[R] SAS to R - if you don't have a SAS license

From: Gyula Gulyas <gygulyas_at_yahoo.ca>
Date: Thu, 27 Dec 2007 15:33:27 -0800 (PST)


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:
#

http://www.sas.com/apps/demosdownloads/setupcat.jsp?cat=SAS+System+Viewer (requires registration)
#

http://www.umass.edu/statdata/software/downloads/SASViewer/index.html
# 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
file
# 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 later

# Select the SAS data file...

sas.data<-read.table(file.choose(),header=T, sep=",", na.strings=".")

# Select SAS variable definition file...
sas.def<-read.csv(file.choose())

# str(sas.def)
# sas.def$SASFORMAT[sas.def$Type=="Char"]<-"character"
# sas.def$SASFORMAT[sas.def$Type=="Num"]<-"numeric"

sas.def$SASFORMAT[substr(sas.def$Format,1,4)=="DATE"]<-"date"

sas.def<-sas.def[,length(names(sas.def))] # pick last column

tmp<-which(sas.def=="date")

sas.data[,tmp] <-
as.data.frame(strptime(sas.data[,tmp],
"%d%b%Y:%H:%M:%S"))

str(sas.data)
print(head(sas.data))

setwd(wrkdir) # reset working directory

rm(wrkdir,tmp,sas.def)

# the end



Be a better friend, newshound, and

R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu 27 Dec 2007 - 23:40:24 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 28 Dec 2007 - 00:30:20 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.