How can I export data from SAS to Excel, and what are some examples of this process? 2

How can I export data from SAS to Excel, and what are some examples of this process?

Exporting data from SAS to Excel is a simple and efficient way to transfer data between the two programs. This process involves converting the data from SAS format into a format that can be read by Excel. This can be done using the PROC EXPORT statement in SAS, which allows users to specify the data set to be exported, the destination file in Excel, and any necessary formatting options.

Some examples of this process include exporting SAS data sets containing statistical analysis results, such as tables or graphs, to Excel for further analysis or visualization. Another example is exporting large data sets from SAS to Excel for easier manipulation and sharing with colleagues. Additionally, users can export SAS output such as reports or summaries to Excel for presentation purposes. This process is beneficial for users who prefer to work with data in Excel or need to collaborate with others who primarily use Excel. Overall, exporting data from SAS to Excel provides a convenient and versatile way to transfer and utilize data between the two programs.

Export Data from SAS to Excel (With Examples)


You can use proc export to quickly export data from SAS to an Excel file.

This procedure uses the following basic syntax:

/*export data to file called my_data.xlsx*/
proc exportdata=my_data
    outfile="/home/u13181/my_data.xlsx"
    dbms=xlsx
    replace;
    sheet="First Data";
run;

Here’s what each line does:

  • data: Name of dataset to export
  • outfile: Location to export Excel file
  • dmbs: File format to use for export
  • replace: Replace the file if it already exists
  • sheet: Name to display on sheet in Excel workbook

The following examples show how to use this function in practice.

Example 1: Export One Dataset to One Excel Sheet

Suppose we have the following dataset in SAS:

/*create dataset*/
data my_data;
    input A B C;
    datalines;
1 4 76
2 3 49
2 3 85
4 5 88
2 2 90
4 6 78
5 9 80
;
run;

/*view dataset*/
proc printdata=my_data;

We can use the following code to export this dataset to an Excel file called my_data.xlsx:

/*export dataset*/
proc exportdata=my_data
    outfile="/home/u13181/my_data.xlsx"
    dbms=xlsx
    replace;
    sheet="First Data";
run;

I can then navigate to the location on my computer where I exported the file and view it in Excel:

The data in Excel matches the dataset from SAS and the sheet in the Excel workbook is called “First Data” just like I specified in the proc export statement.

Example 2: Export Multiple Datasets to Multiple Excel Sheets

Suppose we have two datasets in SAS:

/*create first dataset*/
data my_data;
    input A B C;
    datalines;
1 4 76
2 3 49
2 3 85
4 5 88
2 2 90
4 6 78
5 9 80
;
run;

/*create second dataset*/
data my_data2;
    input D E F;
    datalines;
1 4 90
2 3 49
2 3 85
4 5 88
2 1 90
;
run;

We can use the following code to export both datasets to the same Excel file in different sheets:

/*export first dataset to first sheet in Excel*/
proc exportdata=my_data
    outfile="/home/u13181/my_data.xlsx"
    dbms=xlsx
    replace;
    sheet="First Data";
run;

/*export second dataset to second sheet in Excel*/
proc exportdata=my_data2
    outfile="/home/u13181/my_data.xlsx"
    dbms=xlsx
    replace;
    sheet="Second Data";
run;

I can then navigate to the location on my computer where I exported the file and view it in Excel.

The first sheet titled “First Data” contains the first dataset:

And the second sheet titled “Second Data” contains the second dataset:

Additional Resources

The following tutorials explain how to perform other common tasks in SAS:

Cite this article

stats writer (2024). How can I export data from SAS to Excel, and what are some examples of this process?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-export-data-from-sas-to-excel-and-what-are-some-examples-of-this-process/

stats writer. "How can I export data from SAS to Excel, and what are some examples of this process?." PSYCHOLOGICAL SCALES, 1 Jul. 2024, https://scales.arabpsychology.com/stats/how-can-i-export-data-from-sas-to-excel-and-what-are-some-examples-of-this-process/.

stats writer. "How can I export data from SAS to Excel, and what are some examples of this process?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-export-data-from-sas-to-excel-and-what-are-some-examples-of-this-process/.

stats writer (2024) 'How can I export data from SAS to Excel, and what are some examples of this process?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-export-data-from-sas-to-excel-and-what-are-some-examples-of-this-process/.

[1] stats writer, "How can I export data from SAS to Excel, and what are some examples of this process?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, July, 2024.

stats writer. How can I export data from SAS to Excel, and what are some examples of this process?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.

Download Post (.PDF)
Slide Up
x
PDF
Scroll to Top