Import files (CSV,EXCEL)

Importing Different File types

 SAS GUI can be used to import different file types data such as:

  1.  Excel File
  2.  Comma separated Files (CSV)
Importing Files using PROC IMPORT

 Proc import procedure step can be used to import an external file of different file types


proc import datafile =“ External file path “ out= <dataset name>
dbms= <file type> replace;
delimiter= “special character” ; getnames= <yes/no> ; 
datarow= n ;

  • ‘External file path’ is the path of the external file to import
  • ‘Out=‘ specifies the dataset to be created using the imported file
  • ‘dbms’ specifies the file type to be imported or ‘dlm’ if delimited files are imported
  • ‘replace’ replaces already existing files
  • ‘getnames=yes’ tells SAS to read the variable names from the first line of the data file
  • ‘delimiter=‘ specifies the delimiter in the external file. It is specified only when the ‘dbms=  dlm’ is specified
  • ‘datarow =n’ specifies the row from which the data has to read from the external file.
  • Where, n is a number
Importing a comma separated file (.csv) :
Example 1:

 Comma separated file is a special external file with file extension .csv (comma separated

proc import datafile="comma.csv" out= mydata dbms=csv replace;

  • A comma separated file called ‘comma.csv’ is imported
  • A new dataset called ‘mydata’ is created
  • ‘getnames=no’ indicates that the first row in the file is not variable names
  • ‘replace’ indicated SAS to replace the existing file mydata
Example 2:

 Another way of reading a comma delimited file is to consider a comma as an ordinary delimiter
 Here is a program that shows how to use the dbms=dlm and delimiter=","

proc import datafile="comma1.txt" out=mydata dbms=dlm replace;
Delimiter =",” ;
Getnames =yes ;
Datarow =5 ;
Run ;

  • ‘comma1.txt’ is a comma separated text file whose variable values are separated by commas
  • ‘dbms=dlm’ indicates that comma1.txt is a delimiter file
  • ‘delimiter=“,” ‘ indicates the delimiter as “,”
  • ‘Datarow=5’ tell SAS to read data from the 5th row
Import from Tab- Delimitated files (TXT File):


proc import datafile ="tab.txt" out=mydata dbms=tab replace ;
getnames=no ;
Run ;

  • ‘tab.txt’ is a tab separated text file
  • ‘dbms=tab’ indicates tab.txt as tab separated file