Table of Contents
Data from SAS can be easily exported to a text file through the use of the SAS Export procedure. This procedure allows users to specify the desired data set, variables, and file location for the export. Additionally, the user can also specify the formatting and delimiter options for the text file. This process enables efficient and accurate transfer of data from SAS to a text file, providing users with a versatile and portable method for sharing and analyzing their data.
Export Data from SAS to Text File (With Examples)
You can use the PROC EXPORT statement to quickly export data from SAS to a text file.
This procedure uses the following basic syntax:
/*export data to file called my_data.txt*/ proc exportdata=my_data outfile="/home/u13181/my_data.txt" dbms=tab replace; run;
Here’s what each line does:
- data: Name of dataset to export
- outfile: Location to export text file
- dmbs: File format to use for export (tab is used for text files)
- replace: Replace the file if it already exists
The following examples show how to use this function in practice.
Example 1: Export Dataset to Text File with Default Settings
Suppose we have the following dataset in SAS that contains information about various basketball players:
/*create dataset*/ data my_data; input rating points assists rebounds; datalines; 90 25 5 11 85 20 7 8 82 14 7 10 88 16 8 6 94 27 5 6 90 20 7 9 76 12 6 6 75 15 9 10 87 14 9 10 86 19 5 7 ; run; /*view dataset*/ proc printdata=my_data;

We can use the following code to export this dataset to a text file called my_data.txt:
/*export dataset*/ proc exportdata=my_data outfile="/home/u13181/my_data.txt" dbms=tab replace; run;
I can then navigate to the location on my computer where I exported the file and view it:

The data in the text file matches the dataset from SAS.
Example 2: Export Dataset to Text File with Custom Settings
You can also use the delimiter and putnames arguments to change the delimiter that separates the values and remove the header row from the dataset.
/*export dataset*/ proc exportdata=my_data outfile="/home/u13181/my_data2.txt" dbms=tab replace; delimiter=";"; putnames=NO; run;
I can then navigate to the location on my computer where I exported the file and view it:

Notice that the header row has been removed and the values are separated by semi-colons instead of commas.
Note: You can find the complete documentation for the PROC EXPORT statement .
The following tutorials explain how to perform other common tasks in SAS:
Cite this article
stats writer (2024). How can data be exported from SAS to a text file?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-data-be-exported-from-sas-to-a-text-file/
stats writer. "How can data be exported from SAS to a text file?." PSYCHOLOGICAL SCALES, 23 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-data-be-exported-from-sas-to-a-text-file/.
stats writer. "How can data be exported from SAS to a text file?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-data-be-exported-from-sas-to-a-text-file/.
stats writer (2024) 'How can data be exported from SAS to a text file?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-data-be-exported-from-sas-to-a-text-file/.
[1] stats writer, "How can data be exported from SAS to a text file?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.
stats writer. How can data be exported from SAS to a text file?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
