Write Data-sets in SAS

In the previous topic, we have learned to read data-sets from different file formats in SAS. Now, in this topic, we are going to learn how to write data-sets in the SAS programming language.

As we have studied that SAS can read the data-set from different file formats, similar to this SAS can also write data-sets in different file formats. It is able to write data from the SAS file to text file, CSV file, excel file, etc., and these files can be read easily by any operating system.

Write Data-sets in SAS

How to export data sets?

PROC export is an inbuilt procedure of SAS that is used to export the SAS data sets. Exported data sets are used to write data into files of different formats.

Syntax:

Where,

SAS data-set: This is the name of the data set that is being exported. By creating SAS files, it can share data sets with other applications which can be read by various operating systems.

SAS data-set-options: It is used to specify a subset of exported columns.

Filename: It is the name of the file, in which the data values of the data sets are written.

Identifier: It is used to refer delimitation such as a comma, space, and pipeline, written in the file.

LABEL: It is used to mention the name of all the variables written in the file.

Various file formats in which we can write SAS data sets:

Text File

We can write SAS data set in a text file by exporting it from the SAS library.Here we are using Buy data set which is already available in the SASHELP library. We are exporting Buy data set as a text file which is space delimited.

When you execute the code, you can see a file with .txt extension, and when you right-click on it, you can see its content. Consider the following image:

Write Data-sets in SAS

CSV (Comma Separated Values) File

To write a comma delimited file, we can use the dbms option with the value "csv." Here we are using the cars data set which is already available in the SASHELP library. The following code writesfile car_data.csv.

On the execution of code we will get the following output:

Write Data-sets in SAS

Tab Delimited File

To write a tab-delimited file, we can use the dbms option with the "tab" value. Here we are using the cars data set which is already available in the SASHELP library. The following code writes the filecar_tab.txt.

Write Data-sets in SAS