SAS - Write Data Sets

Similar to reading datasets, SAS can write datasets in different formats. It can write data from SAS files to normal text file.These files can be read by other software programs. SAS uses PROC EXPORT to write data sets.
It is a SAS inbuilt procedure used to export the SAS data sets for writing the data into files of different formats.
The basic syntax for writing the procedure in SAS is −
PROC EXPORT 
DATA = libref.SAS data-set (SAS data-set-options)
OUTFILE = "filename" 
DBMS = identifier LABEL(REPLACE);

Following is the description of the parameters used −
SAS data-set is the data set name which is being exported.
SAS can share the data sets from its environment with other applications by creating files which can be read by different operating systems. It uses the inbuilt EXPORT function to out the data set files in a variety of formats. In this chapter we will see the writing of SAS data sets using proc export along with the options dlm and dbms.
SAS data-set is the data set name which is being exported.
SAS can share the data sets from its environment with other applications by creating files which can be read by different operating systems. It uses the inbuilt EXPORT function to out the data set files in a variety of formats. In this chapter we will see the writing of SAS data sets using proc export along with the options dlm and dbms.
SAS data-set-options is used to specify a subset of columns to be exported.
SAS data-set-options is used to specify a subset of columns to be exported.
filename is the name of the file to which the data is written into.
filename is the name of the file to which the data is written into.
identifier is used to mention the delimiter that will be written into the file.
identifier is used to mention the delimiter that will be written into the file.
LABEL option is used to mention the name of the variables written to the file.
LABEL option is used to mention the name of the variables written to the file.
We will use the SAS data set named cars available in the SASHELP library. We export it as a space delimited text file with the code as shown in the following program.
proc export data = sashelp.cars
   outfile = '/folders/myfolders/sasuser.v94/TutorialsPoint/car_data.txt'
   dbms = dlm;
   delimiter = ' ';
   run;

On executing the above code we can see the output as a text file and right click on it to see its content as shown below.
In order to write a comma delimited file we can use the dlm option with a value "csv". The following code writes the file car_data.csv.
proc export data = sashelp.cars
   outfile = '/folders/myfolders/sasuser.v94/TutorialsPoint/car_data.csv'
   dbms = csv;
   run;

On executing the above code we get the below output.
In order to write a tab delimited file we can use the dlm option with a value "tab". The following code writes the file car_tab.txt.
proc export data = sashelp.cars
   outfile = '/folders/myfolders/sasuser.v94/TutorialsPoint/car_tab.txt'
   dbms = csv;
   run;

Data can also be written as HTML file which we will see under the output delivery system chapter.

    50 Lectures 
     5.5 hours 

 Code And Create

    124 Lectures 
     30 hours 

 Juan Galvan

    162 Lectures 
     31.5 hours 

 Yossef Ayman Zedan

    35 Lectures 
     2.5 hours 

 Ermin Dedic

    167 Lectures 
     45.5 hours 

 Muslim Helalee
 Print
 Add Notes
 Bookmark this page