*Programming Examples
*1984 data
*1994 data
*1994 Moved HH data
*1994 Migrant data
*2000 data
*2000 Moved HH data
* 2000 Migrant data
 
You are here: Home > Data > Identifiers > Person Identifier > Programming Examples > 2000 Migrant data

Add the Person Identifier (NRPID) to the 2000-01 Migrant Follow-Up data

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;


SAS Log                     go back to SAS Program
375        ***************************************************************************
376 * Attach NRPID to the 2000 Migrant Follow-Up Individual-Level Data File *
377 ***************************************************************************;
378
379 * 1. Select ONLY 2000 Migrants in the PERSONID Data File *
380 -----------------------------------------------------------;
381 data migrant00;
382 set in1.personid(keep=MID00 MIGTYPE MCEP00 MID00B MIGTYPEB MCEP00B NRPID);
383
384 if (MID00 ne ' ');
385
386 *** Rename Variables ***;
387
388 rename
389 MID00=MID00A
390 MIGTYPE=MIGTYPEA
391 MCEP00=MCEP00A
392 ;
393
394 run;

NOTE: There were 57416 observations read from the data set IN1.PERSONID.
NOTE: The data set WORK.MIGRANT00 has 5412 observations and 7 variables.
NOTE: DATA statement used:
real time 0.87 seconds
cpu time 0.83 seconds

395
396 * 2. Restructure MIGRANT00 into "Child" File,
 as 14 Migrants are in Migrant Follow-Up TWICE *
397 -----------------------------------------------------;
398 data migrant00b;
399 set migrant00;
400 length MID00 $ 11 MIGTYPE $ 4 MCEP00 $ 2;
401
402 keep MID00 MIGTYPE MCEP00 NRPID;
403
404 array m3 {2} MID00A MID00B;
405 array m4 {2} MIGTYPEA MIGTYPEB;
406 array m5 {2} MCEP00A MCEP00B;
407
408 do i=1 to 2;
409 MID00=m3{i};
410 MIGTYPE=m4{i};
411 MCEP00=m5{i};
412 if MID00 ne ' ' then output;
413 end;
414
415 run;

NOTE: There were 5412 observations read from the data set WORK.MIGRANT00.
NOTE: The data set WORK.MIGRANT00B has 5426 observations and 4 variables.
NOTE: DATA statement used:
real time 0.13 seconds
cpu time 0.08 seconds

416
417 *** Sort MIGRANT00B by MID00 MIGTYPE MCEP00 ***;
418
419 proc sort data=migrant00b out=smigrant00b nodupkey;
420 by MID00 MIGTYPE MCEP00;
421 run;

NOTE: 0 observations with duplicate key values were deleted.
NOTE: There were 5426 observations read from the data set WORK.MIGRANT00B.
NOTE: The data set WORK.SMIGRANT00B has 5426 observations and 4 variables.
NOTE: PROCEDURE SORT used:
real time 0.12 seconds
cpu time 0.08 seconds

422
423 * 3. Match SMIGRANT00B to the MINDIV00 Data File *
424 ---------------------------------------------------;
425 data mindiv00_nrpid notin_mindiv00 notin_migrant00b;
426 merge smigrant00b(in=a)
427 in8.mindiv00(in=b);
428 by MID00 MIGTYPE MCEP00;
429
430 if a=1 and b=1 then output mindiv00_nrpid;
431 if a=1 and b=0 then output notin_mindiv00;
432 if a=0 and b=1 then output notin_migrant00b;
433
434 run;

NOTE: There were 5426 observations read from the data set WORK.SMIGRANT00B.
NOTE: There were 5426 observations read from the data set IN8.MINDIV00.
NOTE: The data set WORK.MINDIV00_NRPID has 5426 observations and 537 variables.
NOTE: The data set WORK.NOTIN_MINDIV00 has 0 observations and 537 variables.
NOTE: The data set WORK.NOTIN_MIGRANT00B has 0 observations and 537 variables.
NOTE: DATA statement used:
real time 6.39 seconds
cpu time 6.29 seconds


435
436 *** Check for Duplicates on NRPID in MINDIV00_NRPID (SHOULD HAVE 14!) ***;
437
438 proc sort data=mindiv00_nrpid out=smindiv00_nrpid nodupkey;
439 by NRPID;
440 run;

NOTE: 14 observations with duplicate key values were deleted.
NOTE: There were 5426 observations read from the data set WORK.MINDIV00_NRPID.
NOTE: The data set WORK.SMINDIV00_NRPID has 5412 observations and 537 variables.
NOTE: PROCEDURE SORT used:
real time 4.74 seconds
cpu time 3.06 seconds


  Last Modified: 02/16/2005 UNC Carolina Population Center