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;
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.
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;
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;
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;
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;
Share Share Tweet