*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 > 1994 Migrant data

Add the Person Identifier (NRPID) to the 1994-95 Migrant Follow-Up data

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;


SAS Log                     go back to SAS Program
206        ***************************************************************************
207 * Attach NRPID to the 1994 Migrant Follow-Up Individual-Level Data File *
208 ***************************************************************************;
209
210 * 1. Select ONLY 1994 Migrants in the PERSONID Data File *
211 -----------------------------------------------------------;
212 data migrant94;
213 set in1.personid(keep=MID MCEP8 MIDB MCEP8B NRPID);
214
215 if (MID ne .);
216
217 *** Rename Variables ***;
218
219 rename
220 MID=MIDA
221 MCEP8=MCEP8A
222 ;
223
224 run;

NOTE: There were 57416 observations read from the data set IN1.PERSONID.
NOTE: The data set WORK.MIGRANT94 has 3791 observations and 5 variables.
NOTE: DATA statement used:
real time 0.78 seconds
cpu time 0.77 seconds

225
226 * 2. Restructure MIGRANT94 into "Child" File,
 as 3 Migrants are in Migrant Follow-Up TWICE *
227 ----------------------------------------------------;
228 data migrant94b;
229 set migrant94;
230 length MCEP8 $ 3;
231
232 keep MID MCEP8 NRPID;
233
234 array m1 {2} MIDA MIDB;
235 array m2 {2} MCEP8A MCEP8B;
236
237 do i=1 to 2;
238 MID=m1{i};
239 MCEP8=m2{i};
240 if MID ne . then output;
241 end;
242
243 run;

NOTE: There were 3791 observations read from the data set WORK.MIGRANT94.
NOTE: The data set WORK.MIGRANT94B has 3794 observations and 3 variables.
NOTE: DATA statement used:
real time 0.10 seconds
cpu time 0.06 seconds


244
245 *** Sort MIGRANT94B by MID MCEP8 ***;
246
247 proc sort data=migrant94b out=smigrant94b nodupkey;
248 by MID MCEP8;
249 run;

NOTE: 0 observations with duplicate key values were deleted.
NOTE: There were 3794 observations read from the data set WORK.MIGRANT94B.
NOTE: The data set WORK.SMIGRANT94B has 3794 observations and 3 variables.
NOTE: PROCEDURE SORT used:
real time 0.10 seconds
cpu time 0.05 seconds
250
251 * 3. Match SMIGRANT94B to the MINDIV94 Data File *
252 ---------------------------------------------------;
253 data mindiv94_nrpid notin_mindiv94 notin_migrant94b;
254 merge smigrant94b(in=a)
255 in5.mindiv94(in=b);
256 by MID MCEP8;
257
258 if a=1 and b=1 then output mindiv94_nrpid;
259 if a=1 and b=0 then output notin_mindiv94;
260 if a=0 and b=1 then output notin_migrant94b;
261
262 run;

NOTE: There were 3794 observations read from the data set WORK.SMIGRANT94B.
NOTE: There were 3794 observations read from the data set IN5.MINDIV94.
NOTE: The data set WORK.MINDIV94_NRPID has 3794 observations and 316 variables.
NOTE: The data set WORK.NOTIN_MINDIV94 has 0 observations and 316 variables.
NOTE: The data set WORK.NOTIN_MIGRANT94B has 0 observations and 316 variables.
NOTE: DATA statement used:
real time 2.83 seconds
cpu time 2.69 seconds


263
264 *** Check for Duplicates on NRPID in MINDIV94_NRPID (SHOULD HAVE 3!) ***;
265
266 proc sort data=mindiv94_nrpid out=smindiv94_nrpid nodupkey;
267 by NRPID;
268 run;

NOTE: 3 observations with duplicate key values were deleted.
NOTE: There were 3794 observations read from the data set WORK.MINDIV94_NRPID.
NOTE: The data set WORK.SMINDIV94_NRPID has 3791 observations and 316 variables.
NOTE: PROCEDURE SORT used:
real time 2.03 seconds
cpu time 1.24 seconds


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