Table of Contents
To import a specific range of data from an Excel spreadsheet using SAS, you can use the “range” option in the “proc import” statement. This allows you to specify the desired range of rows and columns to be imported into SAS. Additionally, you can also use the “getnames” option to import column names from the Excel spreadsheet, making it easier to identify and manipulate the imported data. This method is helpful when working with large Excel spreadsheets, as it allows you to import only the necessary data and avoid unnecessary processing time.
SAS: Import Specific Range from Excel
You can use the PROC IMPORT statement with the RANGE option to import a specific range of cells from an Excel file into SAS.
You can use the following basic syntax to do so:
/*import data from Excel file called basketball_data.xlsx*/ proc import out=my_data datafile="/home/u13181/basketball_data.xlsx" dbms=xlsx replace; getnames=YES; range="Sheet1$C4:E11"; 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)
- range: The range of cells to import
Note that this particular example will import the cells in the range C4:E11 of Sheet1 from the Excel file called basketball_data.xlsx.
The following examples show how to use this syntax in practice with the following Excel file called basketball_data.xlsx:

Example 1: Import Data from Excel File into SAS Without Specifying Range
We can use the following syntax to import the Excel file into a SAS dataset named my_data without specifying a specific range of cells to import:
/*import data from Excel file called basketball_data.xlsx*/ proc import out=my_data datafile="/home/u13181/basketball_data.xlsx" dbms=xlsx replace; getnames=YES; run; /*view dataset*/proc printdata=my_data;

Since we didn’t use the range statement to specify a range of cells to import, SAS imported all cells until it encountered data in the sheet.
Example 2: Import Data from Excel File into SAS and Specify Range
We can use the following syntax to import the Excel file into a SAS dataset named my_data and use the range option to import only a specific range of cells:
/*import specific cells from Excel file called basketball_data.xlsx*/ proc import out=my_data datafile="/home/u13181/basketball_data.xlsx" dbms=xlsx replace; getnames=YES; range="Sheet1$C4:E11"; run; /*view dataset*/proc printdata=my_data;

Note that you can also pass a named range to the range statement.
For example, if the cell range C4:E11 had a named ranged of my_range then you could use the argument range=”my_range” in the PROC IMPORT statement instead.
Note: You can find the complete documentation for the PROC IMPORT statement in SAS .
The following tutorials explain how to perform other common tasks in SAS:
Cite this article
stats writer (2024). How can I import a specific range of data from an Excel spreadsheet using SAS?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-import-a-specific-range-of-data-from-an-excel-spreadsheet-using-sas/
stats writer. "How can I import a specific range of data from an Excel spreadsheet using SAS?." PSYCHOLOGICAL SCALES, 23 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-i-import-a-specific-range-of-data-from-an-excel-spreadsheet-using-sas/.
stats writer. "How can I import a specific range of data from an Excel spreadsheet using SAS?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-import-a-specific-range-of-data-from-an-excel-spreadsheet-using-sas/.
stats writer (2024) 'How can I import a specific range of data from an Excel spreadsheet using SAS?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-import-a-specific-range-of-data-from-an-excel-spreadsheet-using-sas/.
[1] stats writer, "How can I import a specific range of data from an Excel spreadsheet using SAS?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.
stats writer. How can I import a specific range of data from an Excel spreadsheet using SAS?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
