SAS Program go to SAS Log
****************************************************************************** Attach NRPID to the 2000 Individual-Level Data File 1. Select ONLY 2000 Individuals in the PERSONID Data File 2. Restructure WORK.PERSON00 into "Child" File, as 2511 Code 2 Individuals are in data TWICE 3. Match WORK.SPERSON00B to the INDIV00 Data File
Input data: /nangrong/personid.X01 /nangrong/2000/indiv00.03 *****************************************************************************;
libname in1 xport '/nangrong/personid.X01'; libname in2 xport '/nangrong/2000/indiv00.03';
********************************************************* * Attach NRPID to the 2000 Individual-Level Data File * *********************************************************;
* 1. Select ONLY 2000 Individuals in the PERSONID Data File * --------------------------------------------------------------; data person00; set in1.personid(keep=HHID00 CEP00 OHHID00 OCEP00 NRPID);
if (HHID00 ne ' ');
*** Rename Identifiers ***;
rename HHID00=DHHID00 CEP00=DCEP00 ;
run;
* 2. Restructure PERSON00 into "Child" File, as 2511 Code 2 Individuals are in data TWICE * ----------------------------------------------------; data person00b; set person00; length HHID00 $ 9 CEP00 $ 2;
keep HHID00 CEP00 NRPID;
array i3 {2} DHHID00 OHHID00; array i4 {2} DCEP00 OCEP00;
do i=1 to 2; HHID00=i3{i}; CEP00=i4{i}; if HHID00 ne ' ' then output; end;
run;
*** Sort PERSON00B by HHID00 CEP00 ***;
proc sort data=person00b out=sperson00b nodupkey; by HHID00 CEP00; run;
* 3. Match SPERSON00B to the INDIV00 Data File * -------------------------------------------------; data indiv00_nrpid notin_indiv00 notin_person00a; merge sperson00b(in=a) in6.indiv00(in=b); by HHID00 CEP00;
if a=1 and b=1 then output indiv00_nrpid; if a=1 and b=0 then output notin_indiv00; if a=0 and b=1 then output notin_person00a;
run;
*** Check for Duplicates on NRPID in INDIV00_NRPID (SHOULD HAVE 2511!) ***;
proc sort data=indiv00_nrpid out=sindiv00_nrpid nodupkey; by NRPID; run;
|