Home  /  Stata News  /  Vol 34 No 5  /  Importing data from SPSS and SAS
The Stata News

«Back to main page

In the spotlight: Importing data from SPSS and SAS

In Stata 16, you can now import SPSS (.sav) and SAS (.sas7bdat) files directly into Stata—no need for third-party applications or community-contributed commands. The new commands are import spss and import sas, and their syntax is straightforward. For instance, you can type

. import spss filename.sav
. import sas filename.sas7bdat

to read a dataset into Stata.

These commands are convenient, but there is one very nice feature that I think is easily overlooked. Both commands allow us to load only the variables we need to analyze. We can also import only a subset of the observations; just select a range of observations, or use a conditional expression restriction, or both. So, if we have household-level data in the SAS dataset hsg.sas7bdat, we might type

. import sas ACCESS HISPEED SATELLITE OTHSVCEX using hsg.sas7bdat if NP>1

to load into Stata only the variables related to the household's Internet access and only observations for households having more than one person (NP>1).

Even better, we can select the variables and observations we need by using the dialog box.

Why is this better? Perhaps you don't know the names of the variables in the dataset you are importing. With the dialog box for import sas or import spss, you can search through large files, filter on variable names and variable labels, and determine which ones you need to extract.

Loading just the data you need to analyze saves both time and computer resources. Using a computer's resources wisely is very important on a single workstation and becomes even more important when you are using shared resources on a server or on the Cloud. For more on cloud computing and why it is important to limit the amount of data stored in Stata's memory, see my blog post, Setting up Stata in the Cloud.

— Kevin Crow
Principal Software Developer