Using a FILENAME Statement

Overview

You already know that you can use a FILENAME statement to associate a fileref with a single raw data file. You can also use a FILENAME statement to concatenate raw data files by assigning a single fileref to the raw data files that you want to combine.
General form, FILENAME statement:
FILENAME fileref ('external-file1' 'external-file2' ...'external-filen');
Here is an explanation of the syntax:
fileref
is any SAS name that is eight characters or fewer.
external-file
is the physical name of an external file. The physical name is the name that is recognized by the operating environment.
CAUTION:
All of the file specifications must be enclosed in one set of parentheses.
When the fileref is specified in an INFILE statement, each raw data file that has been referenced can be sequentially read into a data set using an INPUT statement.
Tip
If you are not familiar with the content and structure of your raw data files, you can use PROC FSLIST to view them.

Example

In the following program, the FILENAME statement creates the fileref Qtr1, which references the raw data files Month1.dat, Month2.dat, and Month3.dat. The files are stored in the C:Sasuser directory in the Windows operating environment. In the DATA step, the INFILE statement identifies the fileref, and the INPUT statement describes the data, just as if Qtr1 referenced a single raw data file.
filename qtr1 ('c:sasusermonth1.dat''c:sasusermonth2.dat'
               'c:sasusermonth3.dat'),
data work.firstqtr;
   infile qtr1;
   input Flight $ Origin $ Dest $
         Date : date9. RevCargo : comma15.;
run;
Table 14.1 RAW Data File Month1.dat (first five records)
----+----10---+----20---+----30---+----40 
IA10200 SYD HKG 01JAN2000 $191,187.00 
IA10201 SYD HKG 01JAN2000 $169,653.00 
IA10300 SYD CBR 01JAN2000 $850.00 
IA10301 SYD CBR 01JAN2000 $970.00 
IA10302 SYD CBR 01JAN2000 $1,030.00
Table 14.2 Raw Data File Month2.dat (first five records)
----+----10---+----20---+----30---+----40 
IA10200 SYD HKG 01FEB2000 $177,801.00 
IA10201 SYD HKG 01FEB2000 $174,891.00 
IA10300 SYD CBR 01FEB2000 $1,070.00 
IA10301 SYD CBR 01FEB2000 $1,310.00 
IA10302 SYD CBR 01FEB2000 $850.00
Table 14.3 Raw Data File Month3.dat (first five records)
----+----10---+----20---+----30---+----40 
IA10200 SYD HKG 01MAR2000 $181,293.00 
IA10201 SYD HKG 01MAR2000 $173,727.00 
IA10300 SYD CBR 01MAR2000 $1,150.00 
IA10301 SYD CBR 01MAR2000 $910.00 
IA10302 SYD CBR 01MAR2000 $1,170.00 
The SAS log indicates that the raw data files referenced by Qtr1 are sequentially read into the SAS data set Work.FirstQtr.
Note: The Read count for the three raw data files is 50 records each. The Write count to the output SAS data set is 150 observations.
Table 14.4 SAS Log
9    filename qtr1 ('c:sasusermonth1.dat''c:sasusermonth2.dat'
10                  'c:sasusermonth3.dat'),

11   data work.firstqtr;
12      infile qtr1;
13      input Flight $ Origin $ Dest $
14      Date : date9. RevCargo : comma15.;
15   run;

NOTE: The infile QTR1 is:
      File Name=c:sasusermonth1.dat,
      File List=('c:sasusermonth1.dat' 'c:sasusermonth2.dat' 
                 'c:sasusermonth3.dat'),
      RECFM=V,LRECL=256

NOTE: The infile QTR1 is:
      File Name=c:sasusermonth2.dat,
      File List=('c:sasusermonth1.dat' 'c:sasusermonth2.dat' 
                 'c:sasusermonth3.dat'),
      RECFM=V,LRECL=256

NOTE: The infile QTR1 is:
      File Name=c:sasusermonth3.dat,
      File List=('c:sasusermonth1.dat' 'c:sasusermonth2.dat' 
                 'c:sasusermonth3.dat'),
      RECFM=V,LRECL=256

NOTE: 50 records were read from the infile QTR1.
      The minimum record length was 33.
      The maximum record length was 37.
NOTE: 50 records were read from the infile QTR1.
      The minimum record length was 33.
      The maximum record length was 37.
NOTE: 50 records were read from the infile QTR1.
      The minimum record length was 33.
      The maximum record length was 37.
NOTE: The data set WORK.FIRSTQTR has 150 observations 
      and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           4.02 seconds
      cpu time            0.93 seconds
The following PROC PRINT output shows a portion of the observations in the Work.FirstQtr data set.
proc print 
     data=work.firstqtr (firstobs=45 obs=55);
     format date date9. 
            revcargo dollar11.2;
run;
Work,FirstQtr Data Set
..................Content has been hidden....................

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