Quantcast

Read SAS data into R

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Read SAS data into R

AbouEl-Makarim Aboueissa
Dear ALL:

Could you please let me know how to read SAS data file into R.

Thank you so much for your helps.

Regards;

Abou


==========================
AbouEl-Makarim Aboueissa, Ph.D.
Assistant Professor of Statistics
Department of Mathematics & Statistics
University of Southern Maine
96 Falmouth Street
P.O. Box 9300
Portland, ME 04104-9300

Tel: (207) 228-8389
Email: [hidden email]
          [hidden email]
Office: 301C Payson Smith

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Read SAS data into R

John Kane-2
Have a look at the Hmisc package:sas.get or
sasxport.get.  In either case you need to have a
working SAS installation on the same machine.

Another way, although you lose label is simply to
export the SAS data file as a csv or delim file and
import it.


--- AbouEl-Makarim Aboueissa
<[hidden email]> wrote:

> Dear ALL:
>
> Could you please let me know how to read SAS data
> file into R.
>
> Thank you so much for your helps.
>
> Regards;
>
> Abou
>
>
> ==========================
> AbouEl-Makarim Aboueissa, Ph.D.
> Assistant Professor of Statistics
> Department of Mathematics & Statistics
> University of Southern Maine
> 96 Falmouth Street
> P.O. Box 9300
> Portland, ME 04104-9300
>
> Tel: (207) 228-8389
> Email: [hidden email]
>           [hidden email]
> Office: 301C Payson Smith
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Read SAS data into R

Wensui Liu
In reply to this post by AbouEl-Makarim Aboueissa
see foreign package.
but personally, i think it might be better to transfer through csv or db.

On 5/10/07, AbouEl-Makarim Aboueissa <[hidden email]> wrote:

> Dear ALL:
>
> Could you please let me know how to read SAS data file into R.
>
> Thank you so much for your helps.
>
> Regards;
>
> Abou
>
>
> ==========================
> AbouEl-Makarim Aboueissa, Ph.D.
> Assistant Professor of Statistics
> Department of Mathematics & Statistics
> University of Southern Maine
> 96 Falmouth Street
> P.O. Box 9300
> Portland, ME 04104-9300
>
> Tel: (207) 228-8389
> Email: [hidden email]
>           [hidden email]
> Office: 301C Payson Smith
>
> ______________________________________________
> [hidden email] 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.
>


--
WenSui Liu
A lousy statistician who happens to know a little programming
(http://spaces.msn.com/statcompute/blog)

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Read SAS data into R

Frank Harrell
In reply to this post by John Kane-2
John Kane wrote:
> Have a look at the Hmisc package:sas.get or
> sasxport.get.  In either case you need to have a
> working SAS installation on the same machine.
>
> Another way, although you lose label is simply to
> export the SAS data file as a csv or delim file and
> import it.

I'm also looking into running the SAS Viewer under wine on linux to read
non-transport SAS files in a new Hmisc function.  But so far there is a
problem - SAS in all its wisdom doesn't quote character string output
when creating csv files with the Viewer, so you can't have commas in
your character strings.  There is a tab delimiter option as long as you
don't have tabs in the strings.  Amazing that SAS couldn't do better
than that.

Frank

>
>
> --- AbouEl-Makarim Aboueissa
> <[hidden email]> wrote:
>
>> Dear ALL:
>>
>> Could you please let me know how to read SAS data
>> file into R.
>>
>> Thank you so much for your helps.
>>
>> Regards;
>>
>> Abou
>>
>>
>> ==========================
>> AbouEl-Makarim Aboueissa, Ph.D.
>> Assistant Professor of Statistics
>> Department of Mathematics & Statistics
>> University of Southern Maine
>> 96 Falmouth Street
>> P.O. Box 9300
>> Portland, ME 04104-9300
>>
>> Tel: (207) 228-8389
>> Email: [hidden email]
>>           [hidden email]
>> Office: 301C Payson Smith
>>
>> ______________________________________________
>> [hidden email] 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.
>>
>
> ______________________________________________
> [hidden email] 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.
>


--
Frank E Harrell Jr   Professor and Chair           School of Medicine
                      Department of Biostatistics   Vanderbilt University

______________________________________________
[hidden email] 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.
Frank Harrell
Department of Biostatistics, Vanderbilt University
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Read SAS data into R

kseefeld
In reply to this post by AbouEl-Makarim Aboueissa
Kim’s EZ Recipe for….

SAS TO R, perfectly formatted table with no loss of data

• In SAS: Export SAS DB as access db
• In R go to directory where access db is stored
• Use package RODBC

#R code
#Create connection object (Can set up DSN but I’m too lazy to)
c<-odbcConnectAccess("x.mdb")
#Create table object, store db in object
x<-sqlFetch(c, "test")
#Close connection object
odbcClose(c)

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Initializing lists with n objects

Sam Field-2
Hopefully quick question.   I would like to populate a list with n
objects using a for loop, so within the loop (i to n)  I need to refer
to a list as example.list[[i]] .  This requires that I create a
example.list[[i]] with n objects before the for loop.  How do I do
this?   With matrices it is easy (matrix()).

thanks!

Sam

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Initializing lists with n objects (never mind)

Sam Field-2
sorry every one. I figured it out. I didn't realize that you could add
objects so easily. I just went with

example.list <- list(1)


Sam



Sam Field wrote:

> Hopefully quick question.   I would like to populate a list with n
> objects using a for loop, so within the loop (i to n)  I need to refer
> to a list as example.list[[i]] .  This requires that I create a
> example.list[[i]] with n objects before the for loop.  How do I do
> this?   With matrices it is easy (matrix()).
>
> thanks!
>
> Sam
>
> ______________________________________________
> [hidden email] 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.
>
>
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Initializing lists with n objects

Prof Brian Ripley
In reply to this post by Sam Field-2
On Fri, 11 May 2007, Sam Field wrote:

> Hopefully quick question.   I would like to populate a list with n
> objects using a for loop, so within the loop (i to n)  I need to refer
> to a list as example.list[[i]] .  This requires that I create a
> example.list[[i]] with n objects before the for loop.  How do I do
> this?   With matrices it is easy (matrix()).

And with lists equally easy via vector("list", n), which is mentioned on
the help page for list.

--
Brian D. Ripley,                  [hidden email]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Initializing lists with n objects

John Kane-2
In reply to this post by Sam Field-2
mylist <-  as.list (matrix(1:5))  

might work. Note the elements of the list  are not
empty
--- Sam Field <[hidden email]> wrote:

> Hopefully quick question.   I would like to populate
> a list with n
> objects using a for loop, so within the loop (i to
> n)  I need to refer
> to a list as example.list[[i]] .  This requires that
> I create a
> example.list[[i]] with n objects before the for
> loop.  How do I do
> this?   With matrices it is easy (matrix()).
>
> thanks!
>
> Sam

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Read SAS data into R

Frank Harrell
In reply to this post by kseefeld
kseefeld wrote:

> Kim’s EZ Recipe for….
>
> SAS TO R, perfectly formatted table with no loss of data
>
> • In SAS: Export SAS DB as access db
> • In R go to directory where access db is stored
> • Use package RODBC
>
> #R code
> #Create connection object (Can set up DSN but I’m too lazy to)
> c<-odbcConnectAccess("x.mdb")
> #Create table object, store db in object
> x<-sqlFetch(c, "test")
> #Close connection object
> odbcClose(c)
>
>

That doesn't help people who don't have SAS.

Note that an upcoming release of the Hmisc package has a new Access
import function for users who have access to the mdbtools package on
their operating system (e.g., linux).

--
Frank E Harrell Jr   Professor and Chair           School of Medicine
                      Department of Biostatistics   Vanderbilt University

______________________________________________
[hidden email] 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.
Frank Harrell
Department of Biostatistics, Vanderbilt University
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Read SAS data into R

Marc Schwartz
On Fri, 2007-05-11 at 13:43 -0500, Frank E Harrell Jr wrote:

> kseefeld wrote:
> > Kim’s EZ Recipe for….
> >
> > SAS TO R, perfectly formatted table with no loss of data
> >
> > • In SAS: Export SAS DB as access db
> > • In R go to directory where access db is stored
> > • Use package RODBC
> >
> > #R code
> > #Create connection object (Can set up DSN but I’m too lazy to)
> > c<-odbcConnectAccess("x.mdb")
> > #Create table object, store db in object
> > x<-sqlFetch(c, "test")
> > #Close connection object
> > odbcClose(c)
> >
> >
>
> That doesn't help people who don't have SAS.
>
> Note that an upcoming release of the Hmisc package has a new Access
> import function for users who have access to the mdbtools package on
> their operating system (e.g., linux).

mdbtools is also being used by the OO.org folks:

  http://dba.openoffice.org/drivers/mdb/index.html


Just to follow up on Frank's prior post regarding the SAS System Viewer,
that does work well under Wine on Linux, with the caveat that Frank
notes.

I also use DBMS/Copy under Wine and that works quite well.

One of the advantages of DBMS/Copy versus the System Viewer is wider
support for the proprietary SAS formats from various OSs. We recently
were in receipt of SAS datasets that were generated on a 64 bit Unix
platform. The SAS System Viewer choked on them, but DBMS/Copy had no
problem.

The SAS System Viewer is a free download, whereas DBMS/Copy is not, so
it places an emphasis on either getting SAS datasets from Windows based
installations or ensuring that the entity generating the datasets
outputs SAS Transport format files instead.

HTH,

Marc Schwartz

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Read SAS data into R

Wensui Liu
In reply to this post by Frank Harrell
not necessarily, if R can access SAS data through SAS ODBC driver. I
do so for *.sav data all the time.

On 5/11/07, Frank E Harrell Jr <[hidden email]> wrote:

> kseefeld wrote:
> > Kim's EZ Recipe for….
> >
> > SAS TO R, perfectly formatted table with no loss of data
> >
> > •     In SAS: Export SAS DB as access db
> > •     In R go to directory where access db is stored
> > •     Use package RODBC
> >
> > #R code
> > #Create connection object (Can set up DSN but I'm too lazy to)
> > c<-odbcConnectAccess("x.mdb")
> > #Create table object, store db in object
> > x<-sqlFetch(c, "test")
> > #Close connection object
> > odbcClose(c)
> >
> >
>
> That doesn't help people who don't have SAS.
>
> Note that an upcoming release of the Hmisc package has a new Access
> import function for users who have access to the mdbtools package on
> their operating system (e.g., linux).
>
> --
> Frank E Harrell Jr   Professor and Chair           School of Medicine
>                       Department of Biostatistics   Vanderbilt University
>
> ______________________________________________
> [hidden email] 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.
>


--
WenSui Liu
A lousy statistician who happens to know a little programming
(http://spaces.msn.com/statcompute/blog)

______________________________________________
[hidden email] 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.
Loading...