SAS Program go to SAS Log
****************************************************************************** Attach NRPID to the 1994 Migrant Follow-Up Individual-Level Data File 1. Select ONLY 1994 Migrants in the PERSONID Data File 2. Restructure MIGRANT94 into "Child" File, as 3 Migrants are in Migrant Follow-Up TWICE 3. Match SMIGRANT94B to the MINDIV94 Data File
Input data: /nangrong/personid.X01 /nangrong/1994/mindiv94.03 *****************************************************************************;
libname in1 xport '/nangrong/personid.X01'; libname in2 xport '/nangrong/1994/mindiv94.03';
*************************************************************************** * Attach NRPID to the 1994 Migrant Follow-Up Individual-Level Data File * ***************************************************************************;
* 1. Select ONLY 1994 Migrants in the PERSONID Data File * -----------------------------------------------------------; data migrant94; set in1.personid(keep=MID MCEP8 MIDB MCEP8B NRPID);
if (MID ne .);
*** Rename Variables ***;
rename MID=MIDA MCEP8=MCEP8A ;
run;
* 2. Restructure MIGRANT94 into "Child" File, as 3 Migrants are in Migrant Follow-Up TWICE * ----------------------------------------------------; data migrant94b; set migrant94; length MCEP8 $ 3;
keep MID MCEP8 NRPID;
array m1 {2} MIDA MIDB; array m2 {2} MCEP8A MCEP8B;
do i=1 to 2; MID=m1{i}; MCEP8=m2{i}; if MID ne . then output; end;
run;
*** Sort MIGRANT94B by MID MCEP8 ***;
proc sort data=migrant94b out=smigrant94b nodupkey; by MID MCEP8; run;
* 3. Match SMIGRANT94B to the MINDIV94 Data File * ---------------------------------------------------; data mindiv94_nrpid notin_mindiv94 notin_migrant94b; merge smigrant94b(in=a) in5.mindiv94(in=b); by MID MCEP8;
if a=1 and b=1 then output mindiv94_nrpid; if a=1 and b=0 then output notin_mindiv94; if a=0 and b=1 then output notin_migrant94b;
run;
*** Check for Duplicates on NRPID in MINDIV94_NRPID (SHOULD HAVE 3!) ***;
proc sort data=mindiv94_nrpid out=smindiv94_nrpid nodupkey; by NRPID; run;
|