Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

SaS writes to the dataset


May 27, 2021 SAS


Table of contents


Similar to reading a dataset, SAS can write to a dataset in a different format. I t can write data from an SAS file to a normal text file. T hese files can be read by other software programs. S AS writes to the dataset using PROC EXPORT.

PROC EXPORT

It is an SAS built-in process for exporting SAS datasets to write data to files in different formats.

Grammar

The basic syntax for writing a procedure in SAS is:

PROC EXPORT 
DATA=libref.SAS data-set (SAS data-set-options)
OUTFILE="filename" 
DBMS=identifier LABEL(REPLACE);

Here is a description of the parameters used:

  • The SAS dataset is the name of the dataset to export. S AS can share datasets from its environment with other applications by creating files that can be read by different operating systems. I t uses the built-in EXPORT function to output data set files in various formats. I n this chapter, we'll see using proc export and options dlm and dbms to write SAS datasets.
  • The SAS dataset option specifies a subset of the columns to export.
  • Filename is the name of the file that writes the data.
  • The identifier is used to refer to the separator that will be written to the file.
  • The LABEL option refers to the name of the variable written to the file.

Cases

We will use the SAS dataset called cars provided in theASHELP library. L et's export it as a text file separated by a space, and the code looks like this.

proc export data=sashelp.cars
   outfile=
 '/folders/myfolders/sasuser.v94/TutorialsPoint/car_data.txt'
   dbms=dlm;
   delimiter=' ';
  run;

In the code above we can see the output as a text file and right-click it to see what it is.

Write a CSV file

In order to write comma-separated files, we can use the dlm option with the value "csv". T he following code is written to car_data.csv.

proc export data=sashelp.cars
   outfile=
 '/folders/myfolders/sasuser.v94/TutorialsPoint/car_data.csv'
   dbms=csv;
  run;

To execute the above code, we get the output below.

SaS writes to the dataset

Write tab separators

In order to write a tab separator file, we can use the dlm option with the value "tab". T he following code is written to car_tab.txt.

proc export data=sashelp.cars
   outfile=
 '/folders/myfolders/sasuser.v94/TutorialsPoint/car_tab.txt'
   dbms=csv;
  run;

The data can also be written as HTML files, which we'll see in the Output Delivery System section.