Restructuring a SAS data set: from a mother file to a child file

 

Data set MOTHER (1 obs= mother):

The variable MID identifies a mother. There are up to 3 children for each mother (identified by CID1, CID2, CID3).

         MID    CID1    AGE1    SEX1    CID2    AGE2    SEX2    CID3    AGE3    SEX3

          1       1       2       f       2       5       m       .       .         
          2       1      10       m       2      12       m       3      13        f  
          3       1       7       f       .       .               .       .         
             .
             .
             .

 

Data step to create data set CHILD (1 obs= child):

     data child(keep= mid cid age sex);
          set mother;

          length sex $ 1;

          array c(1:3) cid1-cid3;
          array a(1:3) age1-age3;
          array s(1:3) sex1-sex3;

          do i= 1 to 3;
               cid= c(i);
               age= a(i);
               sex= s(i);
               if not missing(cid) then output;
          end;
     run;

 

The output data set CHILD:

The variables MID CID identify a child.

               MID    CID    AGE    SEX

                1      1      2      f 
                1      2      5      m 
                2      1     10      m 
                2      2     12      m 
                2      3     13      f 
                3      1      7      f 
                   .
                   .
                   .

 


Another topic?

Wink Plone Theme by Quintagroup © 2013.

Personal tools
This is themeComment for Wink theme