Restructuring a SAS data set: from a child file to a mother file
Data set CHILD (1 obs=child):A child is identified by the pair of variables MID CID, where MID identifies the mother.
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
.
.
.
Data step to create data set MOTHER (1 obs=mother):
First solutiondata mother(keep=mid cid1-cid3 age1-age3 sex1-sex3);
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 . . . .
.
.
.
Second solutionHere is a second solution to the above restructuring problem. To produce the mother file, the child file is merged with three copies of itself and with appropriate use of the RENAME= and WHERE= data set options.
Another topic? Questions or comments? If you are affiliated with the Carolina Population Center, send them to Phil Bardsley.
|

