Advertisements

3 ways to Import STATA Files into SAS (3 Unique Examples)

Users often need to import different types of files into SAS software for more analysis. To do so, they can use the Proc Import command. In this section, we discuss “3 ways to import STATA files into SAS”.

Advertisements

In this section:


  1. Which version of STATA is supported by SAS Proc Import Command?
  2. SAS Code Examples to import STATA files into SAS
  3. Save STATA File as Tab Delimited CSV file and import into SAS
  4. Import Excel and Text Files into SAS

Import STATA Files into SAS, Import STATA files into SAS

1. Which version of STATA Files are supported by SAS Proc Import

To import STATA Files into SAS, we need to use Proc Import command. However, the Proc Import command does NOT support the 13 and newer versions of STATA. To import STATA files by using Proc Import, we need to save the STATA files as Version 12/11. To save the STATA files as version 12/11, follow the steps:

Step 1: Click on File–> Save as

Step 2: While saving the file, select the save as type “Stata 12/11 Data (.dta)” [ as shown in the image below]

Now you are ready to import the STATA file into SAS by using the Proc Import command.

NOTE: If you CANNOT save the STATA file as an older verion, you can save the file as Tab or Comma separated CSV and import it into SAS. Section 3 explains how to do this step by step.

2. Import STATA Files into SAS

To import STATA file into SAS, the generic code is:

/* Generic Code to import STATA file into SAS */

proc import file="File Location\filename.dta"
out=work.filename
dbms=DTA
replace;
run;

Example: We have a data set “grade2.dta” located in the folder C:\wikitekkee\Learning SAS. We want to import the file into SAS. To do so, the code we use:

/* To import STATA file into SAS */

proc import file="C:\wikitekkee\Learning SAS\grade2.dta"
out=work.grade2
dbms=DTA
replace;
run;

/* To print the data and check whether the data set has been properly imported into SAS */

proc print data=grade2;
run;

The Example Files: From STATA to SAS File.

Advertisements
Import STATA Files into SAS

3. Save STATA File as Tab Delimited CSV file and import into SAS

Another way to import STATA Files into SAS is to save the STATA file as Tab delimited or comma delimited file, and then import it into SAS.

Save STATA file as Tab delimited:

Step 1: Click on File

Step 2: Click on Export

Step 3: Select Text data (delimited, *.csv,…)

Save STATA File as Tab delimited. How to save STATA File as Tab delimited.

Step 4: After clicking on Text data, the export delimited dialogue box will open.

export STATA files as delimited

Step 5: After clicking on the Save as, you can see the Save As dialogue box. Now, write the File name. In our example, we write “grade3”, and select the Save as type “Comma separated”.

Save STATA File as Tab delimited

Import Tab Delimited File into SAS

To import the newly created Tab Delimited File into SAS, the example code is as follows:

/* save STATA Files as Tab delimited and Import into SAS */

proc import file="C:\wikitekkee\Learning SAS\grade3.csv"
    out=work.grade3
    dbms=tab
	replace;
run;

/* To print and check whether the data set has been properly imported*/

proc print data=grade3;
run;

Example Files: Tab Delimited to SAS.

Import Tab Delimited Files into SAS. How to import Tab Delimited Files into SAS.

Users can also save STATA Files as Comma Delimited and then import the file into SAS. To do so, follow the steps discussed in this section.

Advertisements

More Related Readings

  1. How to import Excel Files into SAS
  2. How to import Text Files into SAS

6 Responses

Leave a Reply

Your email address will not be published. Required fields are marked *

Advertisements