SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Searchback||next

Reading Variable-Length Records
Reading Records with a Varying Number of Fields


Now let's think about how to read the repeating blocks of data in each record. You can see that each block of data is the same length, 14 columns. Add one more column, to include the blank that delimits each block, and the total length of each block is 15 columns.

                               15             15             15
      
|     14     | |     14     | |     14     |
1---+----10---+----V0---+----30---V----40---+----V0
1234 13MAR89 120/80
1443 12FEB89 120/70 03FEB90 125/80 07OCT90 125/99
1681 11JAN90 120/80 05JUN90 110/70
2034 19NOV88 130/70 12MAY89 150/90 23MAR90 130/80


So, you need to execute statements that read each block of 15 columns and output the values as an observation until the end of the record is reached. You can repeatedly execute these statements in an iterative DO loop.

     data perm.health;
        infile bpdata length=reclen;
        input ID 4. @;
        do index=6 to reclen by 15;
The index variable determines how many times the loop will execute. Now you need to think about what kinds of statements need to be executed within the loop.
  • First, you need to read the values for Date and BP.

  • When the first block of values for Date and BP is read, the values in the program data vector must be written to the data set as an observation before the next block of values can be read. This is easily accomplished with an OUTPUT statement.

  • An END statement completes the loop and returns control to the DO statement.

     data perm.health;
        infile bpdata length=reclen;
        input ID 4. @;
        do index=6 to reclen by 15;
           input Date : date. BP $ @;
           output;
        end;
     run;

The RUN statement completes the DATA step.


back||next


Copyright © 2002 SAS Institute Inc., Cary, NC, USA. All rights reserved.

Terms of Use & Legal Information | Privacy Statement