Additional Features

In addition to using the methods for appending raw data files that were discussed earlier in this chapter, you can also append raw data files using a SAS data set or an external file that contains the names of the raw data files to be appended.

Storing Raw Data Filenames in a SAS Data Set

In the following program, five raw data files, Route1.dat, Route2.dat, Route3.dat, Route4.dat, and Route5.dat, are concatenated to create the SAS data set Work.NewRoute. The names of the raw data files are stored in the SAS data set Sasuser.Rawdata, which is referenced using a SET statement. The name of the FILEVAR= variable, Readit, is the name of the variable in Sasuser.Rawdata whose value is the name of the file to be read.
data work.newroute;
  set sasuser.rawdata;
  infile in filevar = readit end = lastfile;
  do while(lastfile = 0);       
    input  @1 RouteID $7. @8 Origin $3. @11 Dest $3. 
           @14 Distance 5. @19 Fare1st 4. 
           @23 FareBusiness 4. @27 FareEcon 4. 
           @31 FareCargo 5.;	         
    output;
  end;
run;
Sasuser.Rawdata Data Set

Storing Raw Data Filenames in an External File

In the following program, Route1.dat, Route2.dat, Route3.dat, Route4.dat, and Route5.dat are also concatenated to create the SAS data set Work.NewRoute. In this example, the names of the raw data files are stored in the external file Rawdatafiles.dat, which is referenced in the first INFILE statement. The name of the FILEVAR= variable, Readit, is the name of the variable read from Rawdatafiles.dat. The value of Readit is the name of the raw data file to be read.
Table 14.15 Raw Data File Rawdatafiles.dat
1---+----10---+----20  
route1.dat  
route2.dat  
route3.dat   
route4.dat   
route5.dat
data work.newroute;
   infile 'rawdatafiles.dat';
   input readit $10.;
   infile in filevar=readit end=lastfile;
   do while(lastfile = 0);       
      input  @1 RouteID $7. @8 Origin $3. @11 Dest $3. 
             @14 Distance 5. @19 Fare1st 4. 
             @23 FareBusiness 4. @27 FareEcon 4. 
             @31 FareCargo 5.;	         
      output;
   end;
run;
..................Content has been hidden....................

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