How to import data in sas ?

Steps to upload and import a file into SAS OnDemand for Academics.

  1. Go to the desired folder where you want to import the file. It is located on the left-hand side of the screen under Server Files and Folders pane.
  2. Right click on the folder and then click on Upload Files.
  3. Click on Choose Files and then locate and select the file you want to import. Then click on Upload button
  4. Once done, the file should be appeared in the folder you selected in step 1.
  5. In the folder where file is imported, locate the imported datafile and then right click on it and select the Import Data option.
  6. Click on the Run button to start importing.
  7. SAS Studio will import the CSV file and create a new dataset. By default, the imported dataset will be available in the WORK library.

The Import Data utility automatically show the file information and generate SAS code for importing.

Import Data using PROC IMPORT instead of Import Data utility

The basic syntax of PROC IMPORT is as follows. The following SAS code creates a SAS dataset named MYDATA in the temporary library called WORK.

PROC IMPORT DATAFILE=’/home/deepanshu88us0/mydata/customers.csv’

      DBMS=CSV

      OUT=WORK.MYDATA;

      GETNAMES=YES;

RUN;

How to Use PROC IMPORT to Import Data into SAS?

PROC IMPORT is a powerful SAS procedure that allows you to import data from various external file formats into SAS datasets. It simplifies the process of importing data in SAS. Since PROC IMPORT is commonly used in real-world work scenarios, it is important for every SAS programmer to be familiar with this SAS procedure.

Syntax : PROC IMPORT

Syntax of PROC IMPORT is defined below –

PROC IMPORT DATAFILE=FileName OUT=SASDatasetName
DBMS=identifier REPLACE;
GETNAMES=Yes;
RUN;

Arguments of PROC IMPORT : Explanation

  1. DATAFILE: Specify the location of the file to be imported.
  2. OUT: Specify the name to assign to the dataset after it is imported into SAS
  3. DBMS: Define the format of the file being imported. Some of the common values are CSV, EXCEL, TAB, DLM, ACCESS.
  4. REPLACE: Determine whether to replace the existing SAS Dataset. Yes/No.

GETNAMES: Specify whether to use the first row as variable names. By default it it YES. If you set the option as NO, it will tell SAS not to use the first row of data as variable names. In this case SAS assigns variable names as VAR1, VAR2, VAR3 if there are 3 variables.

File Formats supported in PROC IMPORT

Following is a list of file extensions supported in PROC IMPORT. Specify the value in DBMS=identifier option.

IdentifierOutput Data SourceExtension
CSVComma separated values.csv
DLMDelimited file.dat or .txt
TABTab delimited values.txt
XLSExcel 97-2003 workbooks.xls
XLSXMicrosoft Excel 2007 and later.xlsx
EXCELSupports all versions of MS Excel.xls, .xlsx, xlsb, .xlsm
ACCESSMicrosoft Access 2000 and later.mdb
SAVSPSS file.sav
DTAStata File.dta
JMPJMP files.jmp

Use PROC IMPORT to Import CSV File

Let’s take a simple example to import CSV (comma-separated values) file into SAS. Here we have data named data.csv which has 3 variables and 5 observations. Column names are ID, Name, Score. Data looks like the image below. You can open CSV file in Notepad.

DBMS=CSV tells SAS that the file being imported is a CSV file.

PROC IMPORT DATAFILE='/home/deepanshu88us0/data.csv'
      DBMS=CSV
      OUT=WORK.READIN;
      GETNAMES=YES;
RUN;

The above SAS Program creates a SAS dataset named READIN in the temporary library (WORK).

NOTE: WORK.READIN data set was successfully created.

NOTE: The data set WORK.READIN has 5 observations and 3 variables.

To see the imported file in RESULTS window, you can use PROC PRINT procedure. See the SAS program below.

PROC PRINT DATA=WORK.READIN;

RUN;