This document was uploaded by user and they confirmed that they have the permission to share
it. If you are author or own the copyright of this book, please report to us by using this DMCA
report form. Report DMCA
Objectives Write observations from a SAS data set to a comma-delimited external file. Use DATA step logic to insert a header record and a footer record into an external file.
Introduction You can use the DATA step to write a custom report data to an external file to be read by other programming languages or software.
Introduction READING FROM AN EXTERNAL FILE
WRITING TO AN EXTERNAL FILE
The DATA statement begins the DATA step.
The DATA statement begins the DATA step.
The INFILE statement identifies an external file to read with an INPUT statement.
The FILE statement identifies an external file to write with a PUT statement.
The INPUT statement describes the arrangement of values in the input data record.
The PUT statement describes the arrangement of values in the output data record.
The DATA Statement Usually, the DATA statement specifies at least one data set name that the SAS System uses to create an output data set. Using the keyword _NULL_ as the data set name causes SAS to execute the DATA step without writing observations to a data set. DATA DATA _NULL_; _NULL_;
The FILE Statement The FILE statement can be used to specify the output destination for subsequent PUT statements. General form of the FILE statement: FILE FILE file-specification file-specification; ;
You can use the FILE statement in conditional processing (IF-THEN/ELSE or SELECT) because it is executable.
The PUT Statement The PUT statement can write lines to the external file that is specified in the most recently executed FILE statement. General form of the PUT statement: PUT PUTvariable-1 variable-1 variable-2 variable-2… … variable-n; variable-n;
With simple list output, you list the names of the variables whose values you want written. The PUT statement writes a variable value, inserts a single blank, and then writes the next value.
Modified List Output Modified list output increases the versatility of the PUT statement because you can specify a SAS format to control how the variable values are written. To use modified list output, use the colon (:) format modifier in the PUT statement between the variable name and the format. PUTvariable-1 variable-1 :: format-1. format-1. .. PUT variable-2 . variable-2:: format-2. format-2.
variable-n variable-n:: format-n.; format-n.;
Writing to an External File The prog2.maysales data set contains information about houses. Read this data set and write the data to an external file. prog2.maysales Description Colonial Townhouse Townhouse Ranch Victorian
Why is the $ omitted after Description in the PUT statement? put Description ListDate : date9.
Writing to an External File Partial SAS Log NOTE: 5 records were written to ‘export.dat'. The minimum record length The maximum record length NOTE: There were 5 observations the data set PROG2.MAYSALES.
the file was 34. was 38. read from
Can you use PROC PRINT to view the raw data file?
The FSLIST Procedure The FSLIST procedure enables you to browse external files that are not SAS data sets within an interactive SAS session. PROC PROCFSLIST FSLISTFILEREF=file-specification FILEREF=file-specification