Fill in the gaps (within ID)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | *(Q) Assume the data looks like this (a CH_ID that ends in 00 is actually the parent, whose information I am trying to impute into the children): PAR_ID CH_ID VAR1 VAR2 X001 X00100 2 1 X001 X00102 . . X001 X00103 . . X002 X00200 1 . X002 X00201 . . X003 X00300 3 2 X003 X00302 . . X003 X00303 . . I would like to know if anyone has a script (or modification of the one above) that fill in all the missings for each X00's child with the- but NOT run into the next person. That is, not fill in the missing under VAR2 for X002, because that is a new person and the "1" under VAR2 for X001 is not applicable to that person. The corrected dataset would look like: PAR_ID CH_ID VAR1 VAR2 X001 X00100 2 1 X001 X00102 2 1 X001 X00103 2 1 X002 X00200 1 . X002 X00201 1 . X003 X00300 3 2 X003 X00302 3 2 X003 X00303 3 2 * (A) Posted to newsgroup by Ray on 2002/02/18. DATA LIST LIST /PAR_ID (A4) CH_ID(A6) VAR1 VAR2 (2F8.0). BEGIN DATA X001 X00100 2 1 X001 X00102 . . X001 X00103 . . X002 X00200 1 . X002 X00201 . . X003 X00300 3 2 X003 X00302 . . X003 X00303 . . END DATA. LIST. SET ERRORS=no. DO IF $CASENUM>1. DO IF par_id = LAG(par_id). DO REPEAT v=ch_id TO var2. * The next 2 lines are a nice trick: * one the 2 line results in a (non consequential) error * but the other gives the correct answer. IF LEN(RTRIM(v))=0 v=LAG(v). IF MISSING(v) v=LAG(v). END REPEAT PRINT. END IF. END IF. SET ERRORS=yes. EXECUTE. LIST. |
Related pages
...