How to use PROC IMPORT in SAS?

Proc IMPORT is a SAS procedure that enables users to import data from files in external formats (such as comma-separated values, spreadsheets, or text files) into SAS datasets. It is a useful tool for quickly loading data into SAS from commonly used formats. It is easy to use and requires only the datapath and filename of the external data source, along with optional input parameters for more specific configuration of the data import.


You can use the PROC IMPORT statement to import external data files into SAS.

This statement uses the following basic syntax:

proc import out=my_data
    datafile="/home/u13181/my_data.csv"
    dbms=csv
    replace;
    getnames=YES;
run;

Here’s what each line does:

  • out: Name to give dataset once imported into SAS
  • datafile: Location of file to import
  • dbms: Format of file being imported
  • replace: Replace the file if it already exists
  • getnames: Use first row as variable names (Set to NO if first row does not contain variable names)

You can use this general syntax to import virtually any type of file into SAS. You will only need to change the value for the dbms argument depending on the type of file you’re importing.

For example:

  • To import a CSV file, specify dbms=csv
  • To import an Excel file, specify dbms=xlsx
  • To import a Text file, specify dbms=dlm

The following examples show how to use PROC IMPORT to import each of these types of files.

Example 1: Use PROC IMPORT to Import CSV File

Suppose we have the following CSV file called my_data.csv:

We can use the following code to import this dataset into SAS and call it new_data:

/*import data from CSV file called my_data.csv*/
proc import out=new_data
    datafile="/home/u13181/my_data.csv"
    dbms=csv
    replace;
    getnames=YES;
run;

/*view dataset*/
proc print data=new_data;

The data shown in the SAS output matches the data shown in the CSV file.

Example 2: Use PROC IMPORT to Import Excel File

We can use the following code to import this dataset into SAS and call it new_data:

/*import data from Excel file called my_data.xlsx*/
proc import out=new_data
    datafile="/home/u13181/my_data.xlsx"
    dbms=xlsx
    replace;
    getnames=YES;
run;

/*view dataset*/
proc print data=new_data;

The data shown in the SAS output matches the data shown in the Excel file.

Example 3: Use PROC IMPORT to Import Text File

Suppose we have the following text file called data.txt:

We can use the following code to import this dataset into SAS and call it new_data:

/*import data from text file called data.txt*/
proc import out=new_data
    datafile="/home/u13181/data.txt"
    dbms=dlm
    replace;
    getnames=YES;
run;

/*view dataset*/
proc print data=new_data;

The data shown in the SAS output matches the data shown in the text file.

Note: Refer to the SAS for a complete list of optional arguments you can use when importing files.

The following tutorials explain how to perform other common tasks in SAS:

x