Creating Free-Format Data

The Basics of Creating Free-Format Data

Creating SAS Data Sets from External Files explained how the PUT statement can be used with column output to write observations from a SAS data set to a raw data file. The PUT statement can also be used with list output to create free-format raw data files.
List output is similar to list input. With list output, you simply list the names of the variables whose values you want to write. The PUT statement writes a value, leaves a blank, and then writes the next value.
Syntax, PUT statement using list output:
PUT variable <: format>;
  • variable specifies the variable whose value you want to write.
  • : precedes a format.
  • format specifies a format to use for writing the data values.
The following program creates the raw data file Findat, using the SAS data set sasuser.Finance. The DATEw. format is used to write the value of Date in the form DDMMYYYY.
data _null_; 
   set sasuser.finance; 
   file 'c:datafindat.txt'; 
   put ssn name salary date : date9.; 
run;
proc print data=sasuser.finance noobs;
run;
Figure 18.34 SAS Data Set Finance
SAS Data Set Finance
Figure 18.35 Raw Data File Findat
Raw data file Findat.

Specifying a Delimiter

You can use the DLM= option with a FILE statement to create a character-delimited raw data file.
data _null_; 
   set sasuser.finance; 
   file 'c:datafindat2' dlm=','; 
   put ssn name salary date : date9.; 
run;
Figure 18.36 SAS Data Set Finance
SAS Data Set Finance
Figure 18.37 Raw Data File Created by the DLM= Option
Raw data file that is created from the Finance data set with the DLM= option with a FILE statement.
Tip
To create a simple raw data file, you can use the EXPORT procedure as an alternative to the DATA step.
Syntax, PROC EXPORT:
PROC EXPORT DATA=SAS-data-set;
OUTFILE=filename <DELIMITER='delimiter'>;
RUN;
  • SAS-data-set names the input SAS data set.
  • filename specifies the complete path and filename of the output.
  • delimiter specifies the delimiter to separate columns of data in the output file.

Using the DSD Option

What happens if you need to create a comma-delimited file that requires the use of a format that writes out values using commas?
If you used the following program, the resulting raw data file would contain five fields rather than four.
data _null_;  
   set sasuser.finance;  
   file 'c:datafindat2' dlm=',';  
   put ssn name salary : comma6. date : date9.;  
run;
Figure 18.38 SAS Data Set Finance
SAS data set Finance
Figure 18.39 Raw Data Created with the DLM Option
Raw data from the SAS data set Finance that is created by the above example. It shows five fields rather than four.
You can use the DSD option in the FILE statement to specify that data values that contain commas should be enclosed in quotation marks. Remember that the DSD option uses a comma as a delimiter, so a DLM= option is not necessary here.
data _null_;  
   set sasuser.finance;  
   file 'c:datafindat2' dsd;  
   put ssn name salary : comma. date : date9.;  
run;
Figure 18.40 Raw Data Created with the DSD Option
Raw data created with the above example. It shows data values that contain commas and are contained in quotation marks.
Last updated: January 10, 2018
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.145.82