SAS PROC EXPORT: Learn with Examples

Deepanshu Bhalla Add Comment

PROC EXPORT is used to export SAS datasets to external files in various different formats.

PROC EXPORT Syntax

Below is the syntax for PROC EXPORT:

proc export data=sas-dataset-name
  outfile='/path/to/output/filename.csv'
  dbms=csv
  replace;
run;
Explanation of PROC EXPORT Syntax
  • data=sas-dataset-name: Name of SAS dataset you want to export.
  • outfile: File location where you want to save file.
  • dbms: File format to use for exported file.
  • replace: Replaces the exported file if it already exists. It is optional argument.

You can use the following DBMS options to export data to different file formats:

  • Specify dbms=XLSX to export data as an Excel file.
  • Specify dbms=CSV to export data as a CSV file.
  • Specify dbms=TAB to export data as a Text file.
  • Specify dbms=SAV to export data as a SPSS file.
  • Specify dbms=DTA to export data as a Stata file.
  • Specify dbms=ACCESSCS to export data as a MS Access file.
Table of Contents

How to export SAS Data to Excel File

The following code shows how to use PROC EXPORT to export the SAS dataset sashelp.class to an Excel file named class.xlsx located at '/home/deepanshu88us0/Files/'. It specifies the file format as XLSX.

proc export data=sashelp.class
  outfile='/home/deepanshu88us0/Files/class.xlsx'
  dbms=xlsx
  replace;
  sheet="Students";
run;
PROC EXPORT: Excel File

In the sheet argument, we specified the name of the sheet within the Excel file as "Students". It is visible in the image above.

How to export SAS Data to CSV File

Here we are exporting the SAS dataset sashelp.class to a CSV file named class.csv.

proc export data=sashelp.class
  outfile='/home/deepanshu88us0/Files/class.csv'
  dbms=csv
  replace;
run;
PROC EXPORT: CSV File

How to export SAS Data to Text File

In the code below, we are exporting the SAS dataset sashelp.class to a Tab Delimited file named class.txt.

proc export data=sashelp.class
  outfile='/home/deepanshu88us0/Files/class.txt'
  dbms=tab
  replace;
run;
PROC EXPORT: TEXT File

To exclude headers in the exported file, we can use the argument PUTNAMES=NO in PROC EXPORT.

proc export data=sashelp.class
  outfile='/home/deepanshu88us0/Files/class.txt'
  dbms=tab
  replace;
  putnames=no;  
run;

How to export SAS Data to SPSS File

To export a SAS dataset to a SPSS file, we need to specify the SAV file format, which is the file format used by SPSS software.

proc export data=sashelp.class
  outfile='/home/deepanshu88us0/Files/class.sav'
  dbms=sav
  replace;
run;
Related Posts
Spread the Word!
Share
About Author:
Deepanshu Bhalla

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has over 10 years of experience in data science. During his tenure, he worked with global clients in various domains like Banking, Insurance, Private Equity, Telecom and HR.

Post Comment 0 Response to "SAS PROC EXPORT: Learn with Examples"
Next → ← Prev