17.6 C
London
Monday, July 21, 2025
HomeSASImport & Export Data in SASHow to Import Excel Files into SAS (With Example)

How to Import Excel Files into SAS (With Example)

Related stories

Learn About Opening an Automobile Repair Shop in India

Starting a car repair shop is quite a good...

Unlocking the Power: Embracing the Benefits of Tax-Free Investing

  Unlocking the Power: Embracing the Benefits of Tax-Free Investing For...

Income Splitting in Canada for 2023

  Income Splitting in Canada for 2023 The federal government’s expanded...

Can I Deduct Home Office Expenses on my Tax Return 2023?

Can I Deduct Home Office Expenses on my Tax...

Canadian Tax – Personal Tax Deadline 2022

  Canadian Tax – Personal Tax Deadline 2022 Resources and Tools...

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
  • dmbs: 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

Subscribe

- Never miss a story with notifications

- Gain full access to our premium content

- Browse free from up to 5 devices at once

Latest stories