Lesson 3: Importing data from external sources
This lesson will explain how to import data from Excel, CSV and Text files.
Below is the excel file that I am going to read into SAS:
PROC IMPORT DATAFILE= "C:\test.xls"
** Optional **;
SHEET = "Sheet 1";
Let’s break down the codes above:
(1) DATAFILE indicates the directory and file name of the external source.
(2) OUT = SASCrunch creates a dataset storing the output. This dataset is named 'SASCrunch'.
(3) DBMS indicates the file type of the imported file. In this example, it is an Excel file.
(4) REPLACE tells SAS to overwrite the file if a file with the exact same name already exists.
(5) GETNAMES tells SAS to read the first row of the Excel spreadsheet as the variable names. Contents of the variables will be read from row 2.
(6) SHEET identifies which Excel spreadsheet should be read in.
You do not need to memorize the codes. Copy them from our website whenever you need to import the data from Excel.
DONE! You have learned to import data from Excel.
What you can do if you don’t have the license is to save the excel file into a csv file and then import the csv file into SAS. This will be explained in the next section.