20.5 - Mixing Input Styles

Of course, the first thing we always do when trying to read data from a raw data file into a SAS data set is to review the data to determine whether we need to use column, formatted, or list input to read in the data values. There are some situations, however, in which just one input method doesn't do the trick. In those cases, we'll want to consider mixing input styles, that is, using more than one input method simultaneously. Let's take a look at an example!

Example 20.17 Section

The following program illustrates using column input, list input, and formatted input simultaneously to read in data concerning five U.S. national parks:

DATA nationalparks;
    	input ParkName $ 1-22 State $ Year @40 Acreage comma9.;
    	DATALINES;
    Yellowstone           ID/MT/WY 1872    4,065,493
    Everglades            FL 1934          1,398,800
    Yosemite              CA 1864            760,917
    Great Smoky Mountains NC/TN 1926         520,269
    Wolf Trap Farm        VA 1966                130;
RUN;
PROC PRINT data = nationalparks;
    format acreage comma9.;
RUN;

The SAS System
ObsParkNameStateYearAcreage
1YellowstoneID/MT/WY18724,065,493
2EvergladesFL19341,398,800
3YosemiteCA1864760,917
4Great Smoky MountainsNC/TN1926520,269
5Wolf Trap FarmVA1966130

Reviewing the data, you can see that:

  • Column input is an appropriate method for the first field (ParkName) because the values can be read as standard character values and are arranged in a neatly defined column.
  • The next two fields are candidates for list input, as they are separated by a single blank while the first (State) contains standard character values and the second (Year) contains standard numeric values.
  • The values in the last field (Acreage) are arranged in a neatly defined column, but the values require an informat. Therefore, formatted input is an appropriate method.

As you can see by the INPUT statement, mixing the input styles is easily achieved by simply using the different methods within the same INPUT statement. Launch and run  the SAS program, and review the output to convince yourself that SAS read in the data properly.