Steps to upload and import a file into SAS OnDemand for Academics.
- 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. - Right click on the folder and then click on
Upload Files
. - Click on
Choose Files
and then locate and select the file you want to import. Then click onUpload
button - Once done, the file should be appeared in the folder you selected in step 1.
- In the folder where file is imported, locate the imported datafile and then right click on it and select the
Import Data
option. - Click on the
Run
button to start importing. - 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
- DATAFILE: Specify the location of the file to be imported.
- OUT: Specify the name to assign to the dataset after it is imported into SAS
- DBMS: Define the format of the file being imported. Some of the common values are CSV, EXCEL, TAB, DLM, ACCESS.
- 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.
Identifier | Output Data Source | Extension |
CSV | Comma separated values | .csv |
DLM | Delimited file | .dat or .txt |
TAB | Tab delimited values | .txt |
XLS | Excel 97-2003 workbooks | .xls |
XLSX | Microsoft Excel 2007 and later | .xlsx |
EXCEL | Supports all versions of MS Excel | .xls, .xlsx, xlsb, .xlsm |
ACCESS | Microsoft Access 2000 and later | .mdb |
SAV | SPSS file | .sav |
DTA | Stata File | .dta |
JMP | JMP 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;