Export a SAS Data Set into an Excel spreadsheet
You will often need to export a data set into an Excel spreadsheet.
This can be done easily by using a procedure called PROC EXPORT.
Example
Proc Export Data=Income
OutFile='/home/your_user_name/Income.xlsx'
Replace
Dbms=xlsx;
Run;
[Note: you must change the directory path when running the code above.]
Proc Export is a procedure that allows you to export a SAS data set into an external file such as an Excel spreadsheet or a text file.
You should include these three options when using Proc Export:
1. OUTFILE option
The OUTFILE option lets you specify the file to be exported. In our example, the data is exported into Income.xlsx.
2. REPLACE option
The REPLACE option allows you to overwrite the file if it already exists in the stated directory path. It is recommended to always include this option when using PROC EXPORT.
3. DBMS option
The DBMS option specifies the file format (file type) to be exported. In our example, we use the DBMS option to tell SAS to export the data set into an Excel spreadsheet (.xlsx).
----
Now, run the code in the example above with your own directory path.
The Income data set (created in one of our previous exercises) will then be exported into an Excel spreadsheet:
Exercise
Locate the Electric data set in the SASHelp library.
Export Electric into an Excel spreadsheet.
Ensure the Excel spreadsheet contains the same rows and columns as the SAS data set.
Need some help?
HINT:
Remember to use the Library Reference when referring to a data set in a permanent library.
SOLUTION:
Proc Export Data=SASHelp.Electric
OutFile=’/home/your_user_name/Electric.xlsx’
Replace
Dbms=xlsm;
Run;
Cookie | Duration | Description |
---|---|---|
cookielawinfo-checkbox-analytics | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics". |
cookielawinfo-checkbox-functional | 11 months | The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional". |
cookielawinfo-checkbox-necessary | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary". |
cookielawinfo-checkbox-others | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other. |
cookielawinfo-checkbox-performance | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance". |
viewed_cookie_policy | 11 months | The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data. |