Chapter Contents |
Previous |
Next |
SAS Companion for the OS/2 Environment |
Altering the Record Format |
Usually, the SAS System reads a line of data until a
carriage return and linefeed character combination (the hexadecimal value
is
'0D0A'x
) are encountered or until just a linefeed character (the hexadecimal
value is
'0A0'x
) is encountered. However, sometimes data do not contain these
carriage control characters but do have fixed-length records. In this case,
you can specify RECFM=F to read your data.
To read such a file, you need to use the LRECL= option to specify the record length and the RECFM= option to tell the SAS System that the records have fixed-length record format. Here are the required statements:
data test; infile "test.dat" lrecl=60 recfm=f; input x y z; run;
In this example, the SAS System expects fixed-length records that are 60 bytes long, and it reads in the three numeric variables: X, Y, and Z.
You can also specify RECFM=F when your data do contain carriage returns and linefeeds, but you want to read these values as part of your data instead of treating them as carriage control characters. When you specify RECFM=F, the SAS System ignores any carriage controls and linefeeds and simply reads the record length that you specify.
Appending Data to an External File |
filename myfile "c:\sas\data"; data _null_; infile myfile(newdata); input sales expenses; file myfile(jandata) mod; put sales expenses; run;
This example reads the variables SALES and EXPENSES from the external data file C:\SAS\DATA\NEWDATA.DAT and appends records to the existing data file C:\SAS\DATA\JANDATA.DAT.
If you are going to append data to several files in a single directory, you can use the MOD option in the FILENAME statement instead of in the FILE statement. You can also use the FAPPEND function or the PRINTTO procedure to append data to a file. For more information, see the SAS functions section in SAS Language Reference: Dictionary and the section on the PRINTTO procedure in SAS Procedures Guide.
Determining Your Hard Drive Mapping |
filename myfile drivemap; data mymap; infile myfile; input drive $; put drive; run;
The information that is written to the SAS log looks similar to that shown in Drive Mapping Information.
50 filename myfile drivemap; 51 52 data mymap; 53 infile myfile; 54 input drive $; 55 put drive; 56 run; NOTE: The infile MYFILE is: FILENAME=DRIVEMAP, RECFM=V,LRECL=256 A: C: H: J: K: L: M: N: R: S: T: U: NOTE: 12 records were read from the infile MYFILE. The minimum record length was 2. The maximum record length was 2. NOTE: The data set WORK.MYMAP has 12 observations and 1 variables. NOTE: The DATA statement used 2.04 seconds. |
You can use this technique in SAS/AF applications, where you can build selection lists to let a user choose a hard drive. You can also use the DRIVEMAP keyword to enable you to assign macro variables to the various available hard drives.
If you try to use the fileref that is associated with the DRIVEMAP device-type keyword in a WRITE or UPDATE situation, you receive an error message that tells you that you do not have sufficient authority to write to the file.
Reading External Files with National Characters |
Characters such as the  are considered national characters. OS/2 represents each character with a hexadecimal number. If your external file was created with an OS/2 editor or in the SAS System under OS/2, you do not need to do anything. Simply read the file by using the FILENAME or FILE statements, as you would normally do.
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.