Chapter Contents |
Previous |
Next |
SAS Companion for the CMS Environment |
You can use the FILE statement or the FILE command to write to an external file.
Using the FILE Statement |
The specified output file must be an external file, not a SAS data library. It cannot be a CMS MACLIB or an OS/390 data set. If no FILE statement is specified, then any PUT statements in your SAS program write to the SAS log. The FILE statement is executable; therefore, you can use it in conditional processing (in an IF/THEN statement, for example).
When multiple FILE statements are present, the PUT statement builds and writes output lines to the file that was specified in the most recent FILE statement.
For complete information about the FILE statement, see FILE.
The syntax of the FILE statement is
FILE file-specification <options>; |
FILE
Form | Example | |
---|---|---|
fileref | report |
|
filename filetype | 'report listing' |
|
filename filetype filemode (or SFS directory) | 'report listing b' |
|
fileref(filename) | mydir(report) |
|
fileref (filename filetype) | mydir(report listing) |
|
CMS pipeline | > report listing b |
|
reserved filerefs | LOG or
PRINT |
See Identifying an External File for details.
You can use options to do the following:
data _null_; length x $20; x='old file a'; file cc filevar=x ; put 'line one'; x='new file b'; file cc filevar=x ; put 'line two'; run;
These statements place 'line one' in OLD FILE A while NEW FILE B contains 'line two'.
Using the FILE Command |
The form of the FILE command is
FILE <file-specification> <options> |
The file-specification argument is in one of the forms that is given in Identifying an External File . The file specification cannot be applied to a CMS MACLIB or OS/390 data set. For information about the available options, see the help for base SAS or see SAS Language Reference: Dictionary.
For example, suppose you specify this FILENAME statement:
filename sasfile 'myfile saspgm b';
The following command-line command will copy the text from the Program Editor window to the disk file MYFILE SASPGM B:
file sasfile
If you do not give a value for file-specification, the file from the previous FILE or INCLUDE command is used. If you have not issued previous FILE or INCLUDE commands, then an error message tells you that no default file exists.
The FILE command does not create a PRINT file, even if A you specify the RECFM= option. In order to create a PRINT file from any window, use the PRINT command instead.
Aggregate external files can also be used in a FILE statement. Suppose that a FILENAME statement assigns a fileref to an SFS directory as an aggregate external file. To illustrate a further point, suppose that the FILENAME statement consists of an SFS directory specification only, as follows:
filename mydir 'fpool:myuser.dir';When the filemode is not specified, the FILE statement assumes a filetype of SAS. In the following FILE statement, the contents of the Program Editor window are copied to PGM1 SAS FPOOL:MYUSER.DIR:
file mydir(pgm1);
Note that aggregate syntax can be applied only to SFS directories and CMS minidisks.
Writing to Print Files |
A print file contains carriage-control information (also called ASA control characters) in column 1 of each line. These characters (blank, 0, - , +, and 1) control the operation of a printer: skipping lines, beginning a new page, and so on. They do not normally appear on a printout. If you do not expect to print the external file, you do not need to write to a print file.
When you write to a print file in a DATA step, SAS shifts
all column specifications in the PUT statement one column to the right to
accommodate the carriage-control characters in column 1.
filename out1 'myfile1 file a'; data _null_; file out1 print; put 'line to myfile1'; run;
filename out2 'myfile2 file a' recfm=va; data _null_; file out2; put 'line to myfile2'; run;
Note: You can use either of these techniques
to read from or write to a file with carriage-control characters. If a print
file is being read, the first byte is stripped off and is not returned as
part of the data. If you wish to include the carriage-control bytes as part
of the data, do not declare the file as a print file.
Writing to Nonprint Files |
filename out3 'myfile3 file a' recfm=va; data _null_; file out3 noprint; put 'line to myfile3'; run;
Whether you create a print file or a nonprint file, SAS provides default values for most characteristics of the file. FILENAME lists the default file characteristics for print and nonprint files.
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.