[R] SAS to R - if you don't have a SAS license
Frank E Harrell Jr
f.harrell at vanderbilt.edu
Fri Dec 28 18:21:55 CET 2007
Wensui Liu wrote:
> while I move data between SAS and R all the time, personally I don't
> think your recommendation is very practical. Instead, I feel SAS
> transport file is much better than csv.
> Plus, the sas dataset created on unix can't be opened by sas viewer on
> windows. It is even undoable if the dataset is large.
That's surprising. I hoped that a "SAS Viewer" would read all formats
of SAS binary files.
There is another definite limitation to SAS Viewer: SAS invested so
little of their billions of $ into it that it only has 2 delimiters (tab
and comma) and doesn't even check if character strings contain the
delimiter so as to escape those occurrences. So the Viewer often
produces invalid csv files.
> Just my $0.02.
> On Dec 27, 2007 6:33 PM, Gyula Gulyas <gygulyas at yahoo.ca> wrote:
>> Hi all,
>> if you do not have a SAS license but want to convert
>> native SAS data files, the solution below will work.
>> # read SAS data without SAS
>> # 1. Download free SAS System Viewer from either of
>> the sites below:
>> (requires registration)
>> # 2. Open SAS data in the SAS System Viewer
>> # 3. View-Formatted sets the data in formatted view
>> # 4. Save As File...csv file - this is your SAS data
>> # 5. View-Variables (now showing the variable names
>> and formats)
>> # 6. Save As File...csv file - this is your SAS
>> variable definition file
>> # run code below
>> wrkdir<-getwd() # save working directory to reset
>> # Select the SAS data file...
>> sas.data<-read.table(file.choose(),header=T, sep=",",
>> # Select SAS variable definition file...
>> # str(sas.def)
>> # sas.def$SASFORMAT[sas.def$Type=="Char"]<-"character"
>> # sas.def$SASFORMAT[sas.def$Type=="Num"]<-"numeric"
>> sas.def<-sas.def[,length(names(sas.def))] # pick last
>> sas.data[,tmp] <-
>> setwd(wrkdir) # reset working directory
>> # the end
More information about the R-help