You can use proc import to quickly import data from an Excel file into SAS.
This procedure uses the following basic syntax:
/*import data from Excel file called my_data.xlsx*/ proc import out=my_data datafile="/home/u13181/my_data.xlsx" dbms=xlsx replace; getnames=YES; run;
Here’s what each line does:
- out: Name to give dataset once imported into SAS
- datafile: Location of Excel 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)
The following example shows how to use this function in practice.
Example: Import Data from Excel File into SAS
Suppose we have the following dataset in Excel:
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.
Note: We used getnames=YES when importing the file since the first row of the Excel file contained variable names.
Additional Resources
The following tutorials explain how to perform other common tasks in SAS:
How to Export Data from SAS to Excel File
How to Export Data from SAS to CSV File