|
|
|
||||
|
|
|||||
Below we create hsb2.xpt and (and it also creates a file with formats called formats.xpf). See the help for fdasave for information about how to use the .xpf file.use http://www.ats.ucla.edu/stat/stata/notes/hsb2, clear (highschool and beyond (200 cases))
Instead, we could write a file with SAS code for making the value labels like this. This time we save the file as hsb2a.fdasave hsb2
and instead Stata creates hsb2.xpt and hsb2.sas (which has the code for creating the SAS formats associated with the value labels).fdasave hsb2a, vallabfile(sascode)
In the example above, we use the libname statement to point to the file c:\data\hsb2.xpt and then use proc contents to have a look at the file assuming all looks good, then we can run the next couple of steps to make a copy of the file as a regular SAS data file.OPTIONS NOFMTERR; libname in XPORT "c:\data\hsb2.xpt"; proc contents data=in.hsb2; run;
In the example above we use the data step to make a regular SAS data file called c:\data\hsb2.sas7bdat and then use proc contents, proc means, and proc print to inspect that copy of the file. It is advisable to compare these results to a decribe, summarize and list in 1/10 from the original Stata file.data "c:\data\hsb2" set in.hsb2; run; proc contents data="c:\data\hsb2"; run; proc means data="c:\data\hsb2"; run; proc print data="c:\data\hsb2"(obs=10); run;
In the example above, we use the %include statement to read in the file with the SAS formats (Stata value labels) and then use the libname statement to point to the file c:\data\hsb2a.xpt and then use proc contents to have a look at the file. Assuming all looks good, then we can run the next couple of steps to make a copy of the file as a regular SAS data file.%include "c:\data\hsb2a.sas"; libname in XPORT "c:\data\hsb2a.xpt"; proc contents data=in.hsb2a; run;
In the example above we use the data step to make a regulare SAS data file called c:\data\hsb2a.sas7bdat and then use proc contents, proc means, and proc print to inspect that copy of the file. It is advisable to compare these results to a decribe, summarize and list in 1/10 from the original Stata file.To use c:\data\hsb2a.sas7bdat in the future, say to get a proc means for the data, you would type.data "c:\data\hsb2"; set in.hsb2; run; proc contents data="c:\data\hsb2"; run; proc means data="c:\data\hsb2"; run; proc print data="c:\data\hsb2a"(obs=10); run;
%include "c:\data\hsb2a.sas"; proc means data="c:\data\hsb2"; run;
Reading the .xpt file in SPSS is very easy. You simply select File then Open and then for Files of Type select SAS Transport file (*.xpt) and then point to, for example, c:\data\hsb2.xpt and it will read that file. However, you will not get the value labels.
UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services