Skip to main content
National Longitudinal Survey of Youth 1979 Child and Young Adult (NLSCYA)

Appendix F: Sample SAS Program for Merging NLSY79 Child/YA & Mother Files

/*******************************************************************

* The sample SAS program reads a child-based file extracted from the NLSY79 Child
& Young Adult Data.
   It then reads a main Youth file extracted from the NLSY79 main Youth data set.  
The two files are sorted by case ID and merged to create a child-based file with
additional mother characteristics attached to each child case ID.
* NOTE: Users who start with data in a system file format can skip the steps that 
read the ASCII files.
*******************************************************************/
options nocenter;
 
filename chdfile 'Child file specification';
filename momfile 'Mother file specification'; 
data one(drop=C0000200);
infile chdfile;   
input   @1 C0000100  7.
           C0000200  5.
           C1526000  2.
           C1531500  2.
           C1531600  2. ;
 
kidflag=1;      /* Use flag to restrict final child-based file after merge. */
momid=C0000200; /* Use same var name for mom ID in both files to be merged. */
 
label momid       = "ID Code Of Mother Of Child";
label C0000100 = "ID Code Of Child";
label C1526000 = "Child Conditn Reqires Attention fr Dr  96";
label C1531500 = "Child Health Covered By Insurance     96";
label C1531600 = "Child Health Covered By Medicaid      96";
label kidflag       = "Observation From Child Dataset"; run;
 
proc sort;  by C0000100; run;   /* Sort by child ID; mother ID is embedded in child ID */
proc format;
  value yesnof 1 = 'Yes' 0 = 'No';  run;
 
proc contents;
  title1 'NLSY79 Child: Sample Merge program-Mother vars from main Youth file';
  title2 'Extract child-based child health insurance variables';  run;
 
 proc means;  run;
 proc freq;
   tables C1526000 C1531500 C1531600;
   format C1526000 C1531500 C1531600 yesnof.;  run;
*****************************************************************************;
data two(drop=R0000100);
infile momfile;      
input @1 R0000100  5. 
         R0214800  2. 
         R5625500  2. 
         R5625600  2. 
         R5625601  2. 
         R5625602  2. 
         R5625603  2. 
         R5625604  2. 
         R5625605  2. 
         R5625606  2.;
 
momid=R0000100;   /* Assign same ID name in both child & mother-based files */  
 
label momid    = "NLSY79 Identification Code (1-12686)  79";
label R0214800 = "Sex Of R                              79";
label R5625500 = "Children Have any Health/Hospitl Plan 96";
label R5625600 = "Hlth Plan-Current Employer Policy        96";
label R5625601 = "Hlth Plan-Previous Employer Policy      96";
label R5625602 = "Hlth Plan-Spouse/Partnr Curr Employer 96";
label R5625603 = "Hlth Plan-Spouse/Partnr Prev Employer 96";
label R5625604 = "Hlth Plan-Direct Purchase frm Med Co. 96";
label R5625605 = "Hlth Plan-Medicaid/Pub Assist/Welfare  96";
label R5625606 = "Hlth Plan - Other Source                        96";
 
if  R0214800=2;   /* Restrict main Youth file to females */ run;
 
proc sort; by momid; run;
 
proc contents;
 title 'NLSY79 Females: Extract child health insurance vars';  run;
 
proc means;  run;
****************************************************************************;
data three;
 merge one(in=kids) two(in=females); by momid;
if kids=1; /* Merge child-based and mother-based files: output as child-based file. */
run;
 
 proc means;
  title 'Check final merge of NLSY79 Child & Mother files';
 run;
 
 proc freq;
  tables C1526000 C1531500 C1531600
         R5625500 R5625600 R5625601 R5625602 R5625603 R5625604 R5625605 R5625606
         C1531500*(C1526000 R5625500);
         format R5625500 C1526000 C1531500 yesnof.;
  run;
 
  proc print data=three(obs=20);