|
|||
|
Here is a sas macro I wrote to import *.sav file. But you need to install R
first on your PC. %macro foreign(file =3D , data =3D ); /************************************************ * THIS MACRO IS MOTIVATED BY FOREIGN PACKAGE IN * * R LANGUAGE AND DESIGNED TO READ SPSS *.sav OR * * STATA *.dta DATA FILE. * ************************************************* * REQUIREMENTS TO RUN THIS MACRO: * * 1. INSTALL R LANGUAGE (www.r-project.org) * * 2. INSTALL FOREIGN PACKAGE * ************************************************* * MACRO INPUTS: * * 1. file: full path of data file. * * (example: data =3D c:\temp\test.sav) * * 2. data: name of output SAS table * ************************************************* * AUTHOR: WENSUI LIU (wensui.liu@cchmc.org) * * DATE : 23MAR, 2006 * ************************************************/ options mlogic mprint symbolgen; /* PATH THAT R IS INSTALLED ON PC */ %let rpath =3D C:\Program Files\R\bin\; data _null_; /* CHANGE PATH OF DATA FILE THAT R CAN RECOGNIZE */ in =3D tranwrd("&file", "\", "\\"); call symput('in', trim(in)); /* ASSIGN THE DIRECTORY OF DATA FILE TO MACRO VARIABLE */ path =3D substr("&file", 1, index("&file", scan("&file", -1, "\")) - 1); call symput('path', trim(path)); /* ASSIGN NAME OF R FILE TO MACRO VARIABLE */ r =3D trim(path)||"foreign.r"; call symput('r', trim(r)); /* ASSIGN PATH OF OUTPUT *.csv FILE TO MACRO VARIABLE */ csv =3D tranwrd(trim(path)||"&data"||".csv", '\', '\\'); call symput('csv', trim(csv)); run; data _null_; /* GET THE EXTENSION OF DATA FILE, .sav OR .dta */ ext =3D upcase(scan("&file", -1, ".")); /* OUTPUT A FILE WITH R CODE */ file "&r"; /* WRITE R CODE TO OUTPUT R FILE */ put 'cat("\n", "***** Log of R execution *****", "\n\n");'; put "library(foreign);"; if ext =3D 'SAV' then do; imp =3D "&data"||'<-read.spss(file =3D "'||"&in"||'", '|| "use.value.labels =3D FALSE, to.data.frame =3D TRUE);"; end; if ext =3D 'DTA' then do; imp =3D "&data"||'<-read.dta(file =3D "'||"&in"||'", '|| "convert.underscore =3D FALSE);"; end; put imp; exp =3D 'write.table('||"&data"||', file =3D "'||"&csv"||'", '|| 'sep =3D",", row.names =3D FALSE, na =3D " ");'; put exp; put 'quit("no");'; /* ASSIGN SHELL SCRIPT TO RUN R LANGUAGE TO MACRO VARIABLE */ cmd =3D "'"||'"'||"&rpath.Rcmd.exe"||'" BATCH -- "'|| "&r"||'"'||"'"; call symput('cmd', trim(cmd)); run; /* RUN R CODE IN BATCH MODE */ options XSYNC NOXWAIT XMIN; x &cmd; /* IMPORT *.csv FILE OUTPUT BY R INTO SAS */ proc import datafile =3D "&path.&data..csv" out =3D &data replace; getnames =3D YES; run; data _null_; /* INFILE R OUTPUT */ infile "&r..Rout"; input; /* SHOW R OUTPUT IN SAS LOG WINDOW */ if _n_ > 20 then put _infile_; /* ASSIGN NAMES OF INTERMEDIATE FILES TO MACRO VARIABLES */ del1 =3D "'del "||'"'||"&r"||'"'||"'"; call symput('del1', trim(del1)); del2 =3D "'del "||'"'||"&path.&data..csv"||'"'||"'"; call symput('del2', trim(del2)); del3 =3D "'del "||'"'||"&r..Rout"||'"'||"'"; call symput('del3', trim(del3)); run; /* DELETE INTERMEDIATE FILES */ systask command &del1; systask command &del2; systask command &del3; /************************************************ * END OF MACRO * ************************************************/ %mend foreign; %foreign(file =3D c:\temp\depression_pp.sav, data =3D ppsav); On 4/6/06, Pardee, Roy <pardee.r@ghc.org> wrote: > > Ah, thanks Paul. > > Unfortunately, this is not testing well for me. The files I need to > view are incredibly wide--too wide for excel even (!), much less dbf. I > tried turning a .sav into html and rtf, and found that the files are > incredibly huge (2mb .sav became an 11mb .html file and a 32mb .rtf) and > wouldn't load up in the time I spent waiting. > > Back to the drawing board I guess... > > -----Original Message----- > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of > Choate, Paul@DDS > Sent: Thursday, April 06, 2006 2:32 PM > To: SAS-L@LISTSERV.UGA.EDU > Subject: Re: Does SPSS have a dataset viewer like SAS does? > > Roy - recently I posted this little gem: > > =3D=3D=3D=3D=3D=3D > SAS only can import POR SPSS files, they're the equivalent of a SAS > Xport or CPORT file. > > If you can't get a POR file then you'll need a converter. A simple one > for Windows that's free is DataLoad by D. Baird in New Zealand. > > http://www.american.edu/academic.dep...tilitys/datalo > ad.htm > > It will read a SAV file and create any of the following .XLS - Excel 5 > Spreadsheet file or Logbook file. > .WQ1 - Quattro Spreadsheet file. > .DBF - dBase 3 database file. > .TPT - SAS transport file. > .TXT - ASCII Text file (space delimited). > .CSV - ASCII CSV comma delimited text file. > .TAB - ASCII tab delimited text file. > .RTF - a rich text format file (Word). > .HTM - a hypertext markup format file (Internet viewable). > .HTML - a hypertext markup format file (Internet viewable). > > As well as some other statistical application files. I can't make the > SAS "TPT" files work, but XLS, TXT, CSV, & TAB all work fine. > > Here is a example commands for a BAT file or the command processor. You > could even fire them off from SAS with an X Command, and import the > result with proc import. > > DataLoad sample.SAV sample.xls > =3D=3D=3D=3D=3D=3D > > hth > > Paul Choate > DDS Data Extraction > (916) 654-2160 > > > -----Original Message----- > > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of > > Pardee, Roy > > Sent: Thursday, April 06, 2006 2:24 PM > > To: SAS-L@LISTSERV.UGA.EDU > > Subject: Does SPSS have a dataset viewer like SAS does? > > > > Hey All, > > > > Does anybody know if SPSS has a viewer program like the sas viewer for > > > pulling open their datasets? I've googled & searched spss.com & > didn't > > find anything like it... I need to be able to pull up .sav files > speedy > > quick, and without an SPSS install. > > > > BTW--I'm bummed that sas' SPSS libname engine can only work with .por > > files! Look at the barf I got when I tried to use it w/a .sav file: > > > > 15 libname t > > "\\groups\data\CTRHS\CHCR\Programming\Data\Analyti c" ; > > NOTE: Libref T was successfully assigned as follows: > > Engine: V9 > > Physical Name: > \\groups\data\CTRHS\CHCR\Programming\Data\Analytic > > 16 libname ts spss > > "\\groups\data\CTRHS\CHCR\Programming\Data\Analyti c\pq_age.sav" ; > > NOTE: Libref TS was successfully assigned as follows: > > Engine: SPSS > > Physical Name: > > \\groups\data\CTRHS\CHCR\Programming\Data\Analytic \pq_age.sav > > 17 > > 18 data t.pq_age ; > > 19 set ts.pq_age ; > > 20 run ; > > > > ERROR: Read Access Violation In Task [ DATASTEP ) Exception occurred > > at (662B49BF) Task Traceback > > Address Frame (DBGHELP API Version 4.0 rev 5) > > 662B49BF 03F4FD38 sasspss:mcn_main+0x39BF > > 662B3726 03F4FDA4 sasspss:mcn_main+0x2726 662B200A 03F4FDD4 > > sasspss:mcn_main+0x100A > > 671A3A98 03F4FE90 sasyoio:mcn_main+0x2A98 67238EB0 03F4FECC > > sasdsx:mcn_main+0x7EB0 > > 67EC3DD5 03F4FF04 sashost:Main+0xAD355 > > 2 The SAS System > > 14:10 Thursday, April 6, 2006 > > > > 6723158A 03F4FF44 sasdsx:mcn_main+0x58A 673115BC 03F4FF88 > > sasds:mcn_main+0x5BC > > 67E228F2 03F4FFA0 sashost:Main+0xBE72 67E26A00 03F4FFB4 > > sashost:Main+0xFF80 7C80B50B 03F4FFEC > > kernel32:GetModuleFileNameA+0x1B4 > > > > > > Thanks! > > > > -Roy > -- WenSui Liu (http://statcompute.blogspot.com) Senior Decision Support Analyst Health Policy and Clinical Effectiveness Cincinnati Children Hospital Medical Center |
|
|
||||
|
||||
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Re: Does SPSS have a dataset viewer like SAS does? | David Neal | Newsgroup comp.soft-sys.sas | 1 | 04-07-2006 08:09 PM |
| Re: Does SPSS have a dataset viewer like SAS does? | Jim Groeneveld | Newsgroup comp.soft-sys.sas | 0 | 04-07-2006 06:12 AM |
| Re: Does SPSS have a dataset viewer like SAS does? | Pardee, Roy | Newsgroup comp.soft-sys.sas | 0 | 04-06-2006 09:59 PM |
| Re: Does SPSS have a dataset viewer like SAS does? | Choate, Paul@DDS | Newsgroup comp.soft-sys.sas | 0 | 04-06-2006 09:31 PM |
| Re: SAS Formats - converting SAS dataset into SPSS data | Nordlund, Dan | Newsgroup comp.soft-sys.sas | 0 | 07-19-2005 05:17 PM |