[R] Read SAS data

Mike Reese mreese at jhu.edu
Thu Mar 25 21:44:41 CET 2010


Nicola,

I found its easier if you  convert your SAS data to the XPORT format (a SAS transport format).  Here's instructions for creating the transport file in SAS - use xport not cport.

http://support.sas.com/documentation/cdl/en/movefile/59598/HTML/default/a002575816.htm

I also found the import works better in R if you use the sasxport.get (instead of read.xport) function. I believe this function is part of the Hmisc library).  

BTW I'm looking for help with the write.dta command, specifically, exporting dataframes with variable labels that are readable in  STATA.  Do you know anything about that?

Mike

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Nordlund, Dan (DSHS/RDA)
Sent: Thursday, March 25, 2010 2:32 PM
To: Nicola Sturaro Sommacal; r-help at r-project.org
Subject: Re: [R] Read SAS data

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
> Behalf Of Nicola Sturaro Sommacal
> Sent: Thursday, March 25, 2010 9:16 AM
> To: r-help at r-project.org
> Subject: [R] Read SAS data
> 
> Hi!
> 
> I need to import in R some SAS dataset (sas7bdat). I found two functions to
> do it:
> "read.ssd" from the package "foreign" and "sas.get" from "Hmisc".
> 
> df = read.ssd(libname = path2data, sectionnames = "sasSmallDataset",
> tmpXport = path2data, tmpProgLoc = path2data, sascmd = path2sas)
> sas.get(libraryName = path2data, member = "sasSmallDataset", formats =
> FALSE, sasprog = path2sas, keep.log = TRUE)
> 
> where path2data is the directory on which is contained the file sas,
> sasSmallDataset.sas7bdat are the data and path2sas is the path to SAS
> (C:/Programmi/SAS/SAS System/9.0/sas.exe).
> 
> I obtain the following messages:
> 
> from read.ssd:
> SAS failed.  SAS program at Z:/projects/QUANTIDE/import2R/.sas
> The log file will be import2R.log in the current directory
> Warning messages:
> 1: In file.symlink(oldPath, linkPath) :
>   symlinks are not supported on this platform
> 2: In read.ssd(libname = path2data, sectionnames = "sasSmallDataset",  :
>   SAS return code was 2
> 
> from sas.get:
> Error in if (status != 0) { : argument is of length zero
> 
> I have SAS 9.0 and R 2.10.1 running on Windows XP Pro.
> 
> Can you help me to found a solution or can you provide an alternative way to
> import SAS data directly from R?
> 
> Thank you very much.
> 
> --
>  Nicola Sturaro Sommacal
> Quantide srl
> 
> http://www.quantide.com

Here is one work-around for sas.get on MS Windows platforms.

http://finzi.psych.upenn.edu/Rhelp10/2008-December/182573.html

Here is another thread that you might find useful.

http://tolstoy.newcastle.edu.au/R/e9/help/10/02/6248.html

Hope this is helpful,

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA  98504-5204

______________________________________________
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.



More information about the R-help mailing list