rssunt.gif (12308 bytes)


Creation date: 06/11/98
Authored by: Karl Ho

Question:

I have a data set that has multiple lines for each case. How to read in a multiple record data set in SAS?

Answer:

Suppose the data set is in the following format:

0012119412
0015235525
0010010010
00221202
0024444444
0022001000
0031121422
0034544546
0032100

where each case has three lines of data.  SAS can read in the data using the line pointer # such as:

title 'Reading in multiple record data set';
data multi;
 infile 'c:\temp\multdata.dat' n=3 missover;
 input id 1-3 @4 (var1-var7)(7*1.)
  #2  @4 (var8-var14) (7*1.)
  #3  @4 var15 1. @5 (var16-var18) (3*2.);
proc print;
run;

where the n=5 specifies three records per case and the missover option ignore the space.  Note that the column pointer (@) points to the starting location of the variable group varm-varn to apply format to multiple variables in the same group (e.g. @4 (var1-var7)(7*1.)) and line pointer (#) directs to the line to read in a new set of variables (e.g. #2  @4 (var8-var14) (7*1.) ).  The log and output of this job are as follows:

1    title 'Reading in multiple record data set';
2    data multi;
3     infile 'c:\temp\multdata.dat' n=3 missover;
4     input id 1-3 @4 (var1-var7)(7*1.)
5      #2  @4 (var8-var14) (7*1.)
6      #3  @4 var15 1. @5 (var16-var18) (3*2.);

NOTE: The infile 'c:\temp\multdata.dat' is:
      FILENAME=c:\temp\multdata.dat,
      RECFM=V,LRECL=256

NOTE: 9 records were read from the infile 'c:\temp\multdata.dat'.
      The minimum record length was 7.
      The maximum record length was 10.
NOTE: The data set WORK.MULTI has 3 observations and 19 variables.
NOTE: The DATA statement used 1.82 seconds.


7    proc print;
8    run;
                               Reading in multiple record data set                              6
                                                                    17:35 Thursday, June 11, 1998

                                                    V   V   V   V   V   V    V    V    V
                V   V   V   V   V   V   V   V   V   A   A   A   A   A   A    A    A    A
        O       A   A   A   A   A   A   A   A   A   R   R   R   R   R   R    R    R    R
        B   I   R   R   R   R   R   R   R   R   R   1   1   1   1   1   1    1    1    1
        S   D   1   2   3   4   5   6   7   8   9   0   1   2   3   4   5    6    7    8

        1   1   2   1   1   9   4   1   2   5   2   3   5   5   2   5   0    1    0   10
        2   2   2   1   2   0   2   .   .   4   4   4   4   4   4   4   2    0   10    0
        3   3   1   1   2   1   4   2   2   4   5   4   4   5   4   6   2   10    .    .

 


BACK | MAIN

Last updated: 01/18/06 by Karl Ho