SAS Program go to SAS Log
****************************************************************************** Attach NRPID to the 2000 Migrant Follow-Up Individual-Level Data File 1. Select ONLY 2000 Migrants in the PERSONID Data File 2. Restructure MIGRANT00 into "Child" File, as 14 Migrants are in Migrant Follow-Up TWICE 3. Match SMIGRANT00B to the MINDIV00 Data File
Input data: /nangrong/personid.X01 /nangrong/2000/mindiv00.02 *****************************************************************************;
libname in1 xport '/nangrong/personid.X01'; libname in2 xport '/nangrong/2000/mindiv00.02';
*************************************************************************** * Attach NRPID to the 2000 Migrant Follow-Up Individual-Level Data File * ***************************************************************************;
* 1. Select ONLY 2000 Migrants in the PERSONID Data File * -----------------------------------------------------------; data migrant00; set in1.personid(keep=MID00 MIGTYPE MCEP00 MID00B MIGTYPEB MCEP00B NRPID);
if (MID00 ne ' ');
*** Rename Variables ***;
rename MID00=MID00A MIGTYPE=MIGTYPEA MCEP00=MCEP00A ;
run;
* 2. Restructure MIGRANT00 into "Child" File, as 14 Migrants are in Migrant Follow-Up TWICE * -----------------------------------------------------; data migrant00b; set migrant00; length MID00 $ 11 MIGTYPE $ 4 MCEP00 $ 2;
keep MID00 MIGTYPE MCEP00 NRPID;
array m3 {2} MID00A MID00B; array m4 {2} MIGTYPEA MIGTYPEB; array m5 {2} MCEP00A MCEP00B;
do i=1 to 2; MID00=m3{i}; MIGTYPE=m4{i}; MCEP00=m5{i}; if MID00 ne ' ' then output; end;
run;
*** Sort MIGRANT00B by MID00 MIGTYPE MCEP00 ***;
proc sort data=migrant00b out=smigrant00b nodupkey; by MID00 MIGTYPE MCEP00; run;
* 3. Match SMIGRANT00B to the MINDIV00 Data File * --------------------------------------------------------; data mindiv00_nrpid notin_mindiv00 notin_migrant00b; merge smigrant00b(in=a) in8.mindiv00(in=b); by MID00 MIGTYPE MCEP00;
if a=1 and b=1 then output mindiv00_nrpid; if a=1 and b=0 then output notin_mindiv00; if a=0 and b=1 then output notin_migrant00b;
run;
*** Check for Duplicates on NRPID in MINDIV00_NRPID (SHOULD HAVE 14!) ***;
proc sort data=mindiv00_nrpid out=smindiv00_nrpid nodupkey; by NRPID; run;
|