0

Is there a way I can make use of the SAS load file (see sample below) in R?

DATA NEDS_2017_Core; 
INFILE "&path\NEDS_2017_Core.csv" dsd dlm=',' LRECL = 395;

/* Define data element attributes */
ATTRIB 
  AGE                        LENGTH=3
  LABEL="Age in years at admission"

  AMONTH                     LENGTH=3
  LABEL="Admission month"

  AWEEKEND                   LENGTH=3
  LABEL="Admission day is a weekend"

  DIED_VISIT                 LENGTH=3
  LABEL="Died in the ED (1), Died in the hospital (2), did not die (0)"
  • Are you asking if you can use the generated .sas7bdat file in R? – Stu Sztukowski Feb 07 '20 at 15:55
  • Have you looked at the haven package? – Kent Johnson Feb 07 '20 at 15:56
  • No I am not looking to use a .sas7bdat file. I do not have SAS. What I have is a csv file and SAS syntax file. I want to use the variable naming in the syntax file to name the columns in R – Quantitative72 Feb 07 '20 at 16:19
  • Do you want someone to convert the meaning of the ATTRIB statement in your code into similar code for R that would let you tell R what names and types to use for the variables to create when reading the CSV file? Do you just want to know how to manually do this yourself or are you looking for an R program that could read the SAS code and generate the R code. – Tom Feb 07 '20 at 17:48
  • Do you also need help translating the formats/codelists/factor definitions that you should see earlier in that file? – Tom Feb 07 '20 at 17:53

1 Answers1

1

It is probably going to be easier to use the layout file instead of the SAS code file to learn how to read the data.

NEDS 2017 Core Filespecitifications

Data Set Name: NEDS_2017_CORE                  
Number of Observations: 33506645
Total Number of Data Elements: 58


 Columns    Description
========    ===========
 1 -   4    Database name
 6 -   9    Discharge year of data
11 -  19    File name
21 -  23    Data element number
25 -  43    Data element name
      45    Length of data element
      48    Non-zero number of digits after decimal point for numeric data element
50 -  53    Data element type (Num=numeric; Char=character)
55 - 154    Data element label


NEDS 2017 Core        1 AGE                  3   Num  Age in years at admission
NEDS 2017 Core        2 AMONTH               2   Num  Admission month
NEDS 2017 Core        3 AWEEKEND             2   Num  Admission day is a weekend
NEDS 2017 Core        4 DIED_VISIT           2   Num  Died in the ED (1), Died in the hospital (2), did not die (0)
...
Tom
  • 47,574
  • 2
  • 16
  • 29