SAS Program go to SAS Log
****************************************************************************** Attach NRPID to the 1994 Individual-Level Data File 1. Select ONLY 1994 Individuals in the PERSONID Data File 2. Restructure PERSON94 into "Child" File, as 2516 Code 2 Individuals are in the data TWICE 3. Match SPERSON94B to the INDIV94 Data File.
Input data: /nangrong/personid.X01 /nangrong/1994/indiv94.03 *****************************************************************************;
libname in1 xport '/nangrong/personid.X01'; libname in2 xport '/nangrong/1994/indiv94.03';
********************************************************* * Attach NRPID to the 1994 Individual-Level Data File * *********************************************************;
* 1. Select ONLY 1994 Individuals in the PERSONID Data File * --------------------------------------------------------------; data person94; set in1.personid(keep=HHID94 CEP94 OHHID94 OCEP94 NRPID);
if (HHID94 ne .);
*** Rename Identifiers ***;
rename HHID94=DHHID94 CEP94=DCEP94 ;
run;
* 2. Restructure PERSON94 into "Child" File, as 2516 Code 2 Individuals are in the data TWICE * --------------------------------------------------------; data person94b; set person94; length CEP94 $ 3;
keep HHID94 CEP94 NRPID;
array i1 {2} DHHID94 OHHID94; array i2 {2} DCEP94 OCEP94;
do i=1 to 2; HHID94=i1{i}; CEP94=i2{i}; if HHID94 ne . then output; end;
run;
*** Sort PERSON94B by HHID94 CEP94 ***;
proc sort data=person94b out=sperson94b nodupkey; by HHID94 CEP94; run;
* 3. Match SPERSON94B to the INDIV94 Data File * -------------------------------------------------; data indiv94_nrpid notin_indiv94 notin_person94a; merge sperson94b(in=a) in3.indiv94(in=b); by HHID94 CEP94;
if a=1 and b=1 then output indiv94_nrpid; if a=1 and b=0 then output notin_indiv94; if a=0 and b=1 then output notin_person94a;
run;
*** Check for Duplicates on NRPID in INDIV94_NRPID (SHOULD HAVE 2516!) ***;
proc sort data=indiv94_nrpid out=sindiv94_nrpid nodupkey; by NRPID; run;
|