Converting Data between SAS and other Statistical Packages

Users interested in merging IPUMS versions of NHIS and/or MEPS with NCHS restricted access versions of NHIS data must submit their supplemental data file as a SAS-formatted dataset. Researchers who are submitting their IPUMS extract without modification may simply request their extract as a SAS-formatted data file. However, if researchers choose to make modifications in a different statistical package, they will need to conver their data to a SAS-formatted dataset. This page outlines how to convert data files between SAS and other statistical packages.


To convert a dataset from Stata to SAS:

First, save the Stata file in SAS Transport format. Note that you will need to use a "cd" command to change to the correct directory before executing this command.


export sasxport "USERPATH\mydata, vallabfile(sascode) rename

Note that this will convert your data file to a SAS Transport (or XPORT) file. You will need to read this file into SAS, and then save as a standard SAS-formatted datset (*.sas7bdat file).

Then read your .xpt file created in Stata back into SAS and save as a SAS-formatted dataset. The SAS program deinfes libraries based on where the dataset was saved in Stata. Some users may need to change these before running the file, and should be done before running the "%include" statement.


/*This calls the SAS program created in Stata to convert the .xpt file to a .sas7bdat file and defines variable formats*/

/*Make sure the two paths at the top of are defined correctly */


/*This saves formats in a file that can be loaded by another user*/

PROC FORMAT LIBRARY=work CNTLOUT=datapath.mydata_f ;


To convert from SAS back to Stata:

You can use a proc export command to convert a SAS file to Stata format.


PROC EXPORT DATA=datapath.mydata OUTFILE= "USERPATH\mydata.dta" DBMS=DTA;


Back to Top


To convert a dataset from SPSS to SAS:

You may export the file as a SAS file from your SPSS session.


save translate outfile='C:\ipumsdata.sas7bdat'.

You can also use the SPSS drop-down menus to select "File," "Save as...," then "Save as type" to save the file to a SAS format withing your SPSS session.

To convert a dataset from SAS to SPSS:

You can use the get sas command in SPSS.


get sas data='C:\data\ipumsdata.sas7bdat'.

Back to Top


To convert a dataset from R to SAS:

Use the haven package, which is part of the tidyverse collecton of R packages, to export data from R as a .sas7bdat file.



df <-read.csv("ipumsData.csv")

write_sas(df, "sasipums.sas7bdat")

To convert a dataset from SAS to R:

Use the haven package, which is part of the tidyverse collecton of R packages, to import .sas7bdat files directly into R.