SAS Tip: Use PROC SQL to Create SAS Data sets from Excel files (Daily tip for 2025-Sep-26)


If you are a beginner like me and have to work with Excel files, this should help you.

 

Scenario Suppose you have an Excel file named abc.xlsx that has multiple sheets and let xyz be one of those sheets. Further, suppose that within that sheet you want to extract data from the region B4:H200 and create a SAS data set. This is how you can accomplish this!

 

proc sql;
	connect to Excel (path="c:\somedirectory\abc.xlsx");
	create table SasDataset as select * from connection to Excel (select * from [xyz$B4:H200]);
	disconnect from Excel;
quit;

Note: The code uses column values from the first row to create variable names. See TS-792

 

Thanks to Mysterious Contributor for sharing this tip.

READ this complete tip   Visit a random SAS tip

Start a topic
About these Tips
A "SAS tip" is a basic unit of information exchange between SAS users. The tips on this board come from sasCommunity.org, from SAS user conferences, from SAS blogs, and from freelance contributions from SAS users like you. We hope that you're able to always learn something new here!


» How you can contribute


Tip-o-meter: 65 tips