How do I use a SAS data file in Stata?
1. Using SAS software
SAS’s proc export can be used to convert a SAS data file to Stata format as shown below. By specifying the file extension as .dta, SAS understands that the SAS data file mydata in the work directory will be converted to a Stata file. In the process of conversion, SAS will automatically convert the variable labels and value labels as well.
proc export data=mydata outfile= "C:\data\mydata.dta"; run;
2. Using a SAS XPORT (*.xpt) file
Stata is able to read SAS XPORT data files (*.xpt) made with the XPORT engine using the fdause command such as in the example code below. Here is the link to Stata’s help file on fdause if you need more information.
fdause "C:\datahsb2.xpt"
3. Using -usesas-
The user-written Stata ado-file usesas can be used to read SAS data into Stata. To use this method of bringing a SAS data file into Stata, you must have SAS working on your computer. You should carefully read the help file associated with usesas before using the command for the first time, as some configuration may be required.
First, use the search command to find and download the usesas command (see How can I use the search command to search for programs and get additional help? for more information about using search).
search usesas
Next, read the help file for usesas and make any necessary configurations. Finally, read the SAS data file into Stata.
usesas using "D:\data\hsbdemo.sas7bdat"
4. Using Stat/Transfer
If you have Stat/Transfer, or have access to Stat/Transfer, converting SAS to Stata is fairly straightforward. If you need to convert value labels as well using a SAS format library, click on the Options tab and select SAS Value Labels – Reading in the column on the left. You can then use the drop-down menu that appears on the right to select the type of file that contains the value labels. If the file being transferred has more than 2,047 variables and you are going to use Stata/SE, the data file should be converted to Stata/SE, in which case you will need to select Output File Type: Stata/SE.