/********************************************************************/ /********************************************************************/ /********** *********/ /********** INED *********/ /********** EFL 2011 *********/ /********** PROGRAMME D IMPUTATION DES NON REPONSES *********/ /********** septembre 2013 *********/ /********** *********/ /********************************************************************/ /********************************************************************/ /********************************************************************/ /* DEROULEMENT DU PROGRAMME */ /* */ /* - préparation des données */ /* - creation de variables discriminantes */ /* - imputations des pages 1 2 et 4 */ /* */ /* */ /* NOTE: */ /* le programme complet est très lourd et peut mettre plus */ /* d'une dizaine d'heures à fonctionner (selon la puissance de */ /* l'ordinateur utilisé). De plus, une fois le programme lancé */ /* l'ordinateur peut être fortement ralenti, c'est pourquoi il est */ /* conseillé de faire fonctionner le programme la nuit. */ /* */ /********************************************************************/ /* LES BASES UTILISEES */ /* */ /* efl_individu (359 770 individus) */ /* efl_enfant (609 398 individus) */ /* ear_individu (830 962 individus) */ /* */ /********************************************************************/ /* LES BASES CREEES */ /* */ /* efl_individu_imput (359 770 individus) */ /* elf_enfants_imput (611 276 individus) */ /* */ /********************************************************************/ /* LES LIBNAMES */ /* */ /* SI UTILISATION DU FPR */ /* FPR : dossier où sont situées les bases du FPR */ /* imput : dossier où sont créées les bases imputées */ /* */ /* SI UTILISATION DE DONNEES ANONYMISES */ /* il faut ajouter 'recup' : dossier où sont situées les bases */ /* non anonymisées */ /* */ /********************************************************************/ * copier ici l'adresse des fichiers contenant les bases SAS; libname FPR "/imputations EFL/bases" ; libname imput "/imputations EFL/resultat" ; * copier ici l'adresse du fichier contenant les bases non anonymisées; *libname recup "" ; /********************************************************************/ /* TYPE DE DONNEES UTILISEES */ /* - Si vous utilisez le FPR, écrire non */ /* - Si vous utilisez des données non anonymisées, écrire oui à la */ /* place du non dans la macro variable donnees_ano */ /* */ /* NOTE: L'instruction " %let donnees_ano=non; " doit être */ /* sélectionnée lors du lancement du programme. */ /********************************************************************/ %let donnees_ano=non; /**********************************************************************/ /**********************************************************************/ /* Pour lancer le programme, selectionner tout (Ctrl + A) puis */ /* executer */ /* */ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /* désimputation des imputations non documentées */ /**********************************************************************/ /* A partir des fichiers FPR de juillet 2013, on commence par enlever les imputations de l'insee qui ne sont pas documentées ou qui ne nous conviennent pas. On retransforme donc les modalités imputées en manquantes. Les seuls traitements que l'on garde sont sur le sexe d'ego et du cjt: il n'y a donc pas de nr pour ces deux variables*/ /**************Table individus**********************/ data imputpage1; set fpr.efl_individu; /* q8 mari est en format texte dans efl_individu on le transforme en format caractere*/ q8mari=put(q8mari,1.); /*année de naissance refaire une imputation quand i_q1anai=2*/ if i_q1anai=2 then q1anai=9999; /*couple*/ if i_q3couple=4 and q3couple in ("3","4") then do; q3couple="Z"; q10cause_r="Z"; q10annee_d=9999; q10annee_s=9999; end; /*pacs*/ if i_q7pacs=2 and q7pacs="2" then q7pacs="Z"; /*mari*/ if i_q8mari in ("4") then q8mari="Z"; /*q9tps_logr*/ if i_q9tps_logr=2 then q9tps_logr="Z"; /*q11*/ if i_q11enfan="2" then do; q11enfan="Z"; q11nb_enf=0; q11nb_enf_lgt=0; end; /*q12*/ if i_q12enfan_c="2" then do; q12enfan_c="Z"; q12nb_enf_c=0; q12nb_enf_lgt_c=0; end; /*q19*/ if i_q19viv_m=2 then q19viv_m="Z"; if i_q19adec_m=2 then q19adec_m="ZZZZ"; /*q25*/ if i_q25viv_p=2 then q25viv_p="Z"; if i_q25adec_p=2 then q25adec_p="ZZZZ"; /*q27*/ if i_q27grp=2 then q27grp="Z"; if i_q27nbpenf=2 then q27nbpenf=99; run; /**************************************Table enfants**********************/ data imput.imputenfant; set fpr.efl_enfant; /*on supprime les 2614 enfants qui ont été imputés par l'insee à partir de la variable grand-parent car ce n'est pas une imputation par hotdeck*/ if e13_14anai=. then delete; run; data imput.imputenfant; set imput.imputenfant; if loca="logemen" then tableau=13; else if loca="horslog" then tableau=14; run; /**********************************************************************/ /*** ***/ /*** Préparation pour les imputations ***/ /*** ***/ /**********************************************************************/ /*On veut utiliser les variables du RP donc on fait un appariement avec cabbia */ proc sort data=imputpage1; by cabbia; run; proc sort data=fpr.ear_individu; by cabbia; run; /*on ne garde que les variables utiles pour l'imputation afin de ne pas alourdir la base*/ data earindiv; set fpr.ear_individu; keep cabbia anai couple cs dipl empl inat inai matr mnai situat_r typact; run; data imputpage1; merge imputpage1 earindiv; by cabbia; if cabefla=. then delete; run; proc delete data=earindiv;run; *On supprime les variables dont on n'a pas besoin pour les imputations; data imputpage1; set imputpage1; drop I_CABBI Q10annee_S_X Q13autlgt_131_X Q13sexe_133_X Q14agdep_144_X Q14part_143_X Q20res_M_X Q30tpsm_X I_CABBI_c Q10cause_R_X Q13autlgt_132_X Q13sexe_134_X Q14agdep_145_X Q14part_144_X Q21nsp_P_X Q31lgtsec_X I_Q0sexe Q11enfan_X Q13autlgt_133_X Q13sexe_135_X Q14agdep_146_X Q14part_145_X Q22nat_P_X Q32natautlgt_X I_Q11enfan Q11nb_enf_X Q13autlgt_134_X Q13sexe_136_X Q14agdep_147_X Q14part_146_X Q23njt_P_X Q34tpsautlgt_X I_Q12enfan_C Q11nb_enf_lgt_X Q13autlgt_135_X Q13tpslgt_131_X Q14anai_141_X Q14part_147_X Q24statut_P_X Q35persautlgt_X I_Q1anai Q12enfan_C_X Q13autlgt_136_X Q13tpslgt_132_X Q14anai_142_X Q14sexe_141_X Q25adec_P_X Q36propautlgt_X I_Q3couple Q12nb_enf_C_X Q13cpart_131_X Q13tpslgt_133_X Q14anai_143_X Q14sexe_142_X Q25viv_P_X Q3couple_X I_Q5sexe_c Q12nb_enf_lgt_C_X Q13cpart_132_X Q13tpslgt_134_X Q14anai_144_X Q14sexe_143_X Q26res_P_X Q4anai_C_X I_Q7pacs Q13agad_131_X Q13cpart_133_X Q13tpslgt_135_X Q14anai_145_X Q14sexe_144_X Q27agpenf_X Q4mnai_C_X I_Q8mari Q13agad_132_X Q13cpart_134_X Q13tpslgt_136_X Q14anai_146_X Q14sexe_145_X Q27grp_X Q5sexe_C_X I_Q9tps_logr Q13agad_133_X Q13cpart_135_X Q14agad_141_X Q14anai_147_X Q14sexe_146_X Q27nbpenf_X Q6annee_C_X I_q19adec_m Q13agad_134_X Q13cpart_136_X Q14agad_142_X Q14cpart_141_X Q14sexe_147_X Q28mdg_281_X Q6mois_C_X I_q19viv_m Q13agad_135_X Q13part_131_X Q14agad_143_X Q14cpart_142_X Q15nsp_M_X Q28mdg_282_X Q7annee_pacs_X I_q25adec_p Q13agad_136_X Q13part_132_X Q14agad_144_X Q14cpart_143_X Q16nat_M_X Q28sco_281_X Q7mois_pacs_X I_q25viv_p Q13anai_131_X Q13part_133_X Q14agad_145_X Q14cpart_144_X Q17njt_M_X Q28sco_282_X Q7pacs_X I_q27agpenf Q13anai_132_X Q13part_134_X Q14agad_146_X Q14cpart_145_X Q18statut_M_X Q29tps_X Q8annee_mari_X I_q27grp Q13anai_133_X Q13part_135_X Q14agad_147_X Q14cpart_146_X Q19adec_M_X Q2nbdemif_X Q8mari_X I_q27nbpenf Q13anai_134_X Q13part_136_X Q14agdep_141_X Q14cpart_147_X Q19viv_M_X Q2nbdemis_X Q8mois_mari_X Q0sexe_X Q13anai_135_X Q13sexe_131_X Q14agdep_142_X Q14part_141_X Q1anai_x Q2nbfreres_X Q9tps_logr_X Q10annee_D_X Q13anai_136_X Q13sexe_132_X Q14agdep_143_X Q14part_142_X Q1mnai_X Q2nbsoeurs_X; run; /*Dans la base individus appariée au RP, on crée des variables regroupées que l'on utilisera pour les imputations*/ data imputpage1; set imputpage1; /*lieu de naissance*/ if inai in ("1","2","3") then naiss=1;/*métropole*/ else if inai in ("4","5") then naiss=2;/*dom tom*/ else if inai="6" then naiss=3;/*à l'étranger*/ run; /*Dans la base enfants, on crée des variables indicatrices: nbr d'enfants etc*/ /****** Comptage des enfants **************/ proc sort data=imput.imputenfant; by cabefla loca e13_14anai; run; /*Nbr de lignes enfants*/ data imput.imputenfant; set imput.imputenfant; by cabefla; retain nbenftab; if first.cabefla then nbenftab=1; else nbenftab=nbenftab+1; run; /*on reporte l'info sur toutes les lignes*/ proc sort data=imput.imputenfant; by cabefla descending nbenftab; run; data imput.imputenfant; set imput.imputenfant; by cabefla; retain nbenftab2; if first.cabefla then nbenftab2=nbenftab; else nbenftab2=nbenftab2; drop nbenftab; run; proc sort data=imput.imputenfant; by cabefla tableau e13_14anai; run; /*les enfants pour lesquels on a une date de naissance*/ data imput.imputenfant; set imput.imputenfant; if e13_14anai not in (9999) then dateenf=1; else dateenf=0; run; /*on compte le nombre d'enfants avec une date de naiss*/ proc sort data=imput.imputenfant; by cabefla tableau dateenf; run; /*au total*/ data imput.imputenfant; set imput.imputenfant; by cabefla; retain nbenfdateok; if first.cabefla then nbenfdateok=dateenf; else nbenfdateok=nbenfdateok+dateenf; run; /*on reporte l'info sur toutes les lignes*/ proc sort data=imput.imputenfant; by cabefla descending nbenfdateok; run; data imput.imputenfant; set imput.imputenfant; by cabefla; retain nbenfdateok2; if first.cabefla then nbenfdateok2=nbenfdateok; else nbenfdateok2=nbenfdateok2; drop nbenfdateok; run; /*on crée une variable date moyenne*/ proc sort data=imput.imputenfant;by cabefla;run; data imput.imputenfant; set imput.imputenfant; by cabefla; retain totdate; if first.cabefla and e13_14anai not in (9999) then totdate=e13_14anai; else if e13_14anai not in (9999) then totdate=totdate+e13_14anai; run; /*on reporte l'info sur toutes les lignes*/ proc sort data=imput.imputenfant; by cabefla descending totdate; run; data imput.imputenfant; set imput.imputenfant; by cabefla; retain totdate2; if first.cabefla then totdate2=totdate; else totdate2=totdate2; datemoy=totdate2/nbenftab2; drop totdate totdate2; run; /*******************************************************************************************/ /*les enfants du tableau 13 et les enfants du tableau 14*/ data enftab13; set imput.imputenfant; where tableau=13; run; data enftab14; set imput.imputenfant; where tableau=14; run; /******************************** tableau 13 **************************************/ proc sort data=enftab13; by cabefla; run; /*Nbr de lignes enfants*/ data enftab13; set enftab13; by cabefla; retain nbenftab13; if first.cabefla then nbenftab13=1; else nbenftab13=nbenftab13+1; run; /*on reporte l'info sur toutes les lignes*/ proc sort data=enftab13; by cabefla descending nbenftab13; run; data enftab13; set enftab13; by cabefla; retain nbenftab132; if first.cabefla then nbenftab132=nbenftab13; else nbenftab132=nbenftab132; run; /*Nombre d'enfants du tableau 13 avec une date de naissance*/ data enftab13; set enftab13; by cabefla; retain nbenf13dateok; if first.cabefla then nbenf13dateok=dateenf; else nbenf13dateok=nbenf13dateok+dateenf; run; proc sort data=enftab13; by cabefla descending nbenf13dateok; run; data enftab13; set enftab13; by cabefla; retain nbenf13dateok2; if first.cabefla then nbenf13dateok2=nbenf13dateok; else nbenf13dateok2=nbenf13dateok2; keep cabefla nbenftab132 nbenf13dateok2; run; /*************** tableau 14 *******************************************/ proc sort data=enftab14; by cabefla; run; /*Nbr de lignes enfants*/ data enftab14; set enftab14; by cabefla; retain nbenftab14; if first.cabefla then nbenftab14=1; else nbenftab14=nbenftab14+1; run; /*on reporte l'info sur toutes les lignes*/ proc sort data=enftab14; by cabefla descending nbenftab14; run; data enftab14; set enftab14; by cabefla; retain nbenftab142; if first.cabefla then nbenftab142=nbenftab14; else nbenftab142=nbenftab142; run; /*Nombre d'enfants du tableau 14 avec une date de naissance*/ data enftab14; set enftab14; by cabefla; retain nbenf14dateok; if first.cabefla then nbenf14dateok=dateenf; else nbenf14dateok=nbenf14dateok+dateenf; run; proc sort data=enftab14; by cabefla descending nbenf14dateok; run; data enftab14; set enftab14; by cabefla; retain nbenf14dateok2; if first.cabefla then nbenf14dateok2=nbenf14dateok; else nbenf14dateok2=nbenf14dateok2; keep cabefla nbenftab142 nbenf14dateok2; run; /********** on merge ********************/ proc sort data=imput.imputenfant; by cabefla; run; proc sort data=enftab13; by cabefla; run; proc sort data=enftab14; by cabefla; run; data imput.imputenfant; merge imput.imputenfant enftab13; by cabefla; run; data imput.imputenfant; merge imput.imputenfant enftab14; by cabefla; run; proc delete data= enftab13 enftab14;run; /****** On compare les compteurs ******/ data imput.imputenfant; set imput.imputenfant; /*on regarde dans quels bulletins les deux tableaux sont renseignés*/ if nbenftab132 not in (.) then enftab13=1; else enftab13=0; if nbenftab142 not in (.) then enftab14=1; else enftab14=0; /*Si le nombre d'enfants total est égale au nombre d'enfants avec une date de naiss c'est ok*/ if nbenftab2=nbenfdateok2 then bulltotdate="ok"; else bulltotdate="pas ok"; /*Si le nombre d'enfants du tab13 est égale au nombre d'enfants avec une date de naiss ds le tab13 c'est ok pour le tab13*/ if nbenftab132=. then bull13date="nc"; else if nbenftab132=nbenf13dateok2 then bull13date="ok"; else bull13date="pas ok"; /*Si le nombre d'enfants du tab14 est égale au nombre d'enfants avec une date de naiss ds le tab14 c'est ok pour le tab14*/ if nbenftab142=. then bull14date="nc"; else if nbenftab142=nbenf14dateok2 then bull14date="ok"; else bull14date="pas ok"; run; /*On récupère la variable q3couple de la base imputpage1*/ data recup; set imputpage1; keep cabefla q3couple; run; proc sort data=recup; by cabefla; run; proc sort data=imput.imputenfant; by cabefla; run; data imput.imputenfant; merge imput.imputenfant recup; by cabefla; if identa in (" ") then delete; run; proc delete data=recup;run; /*on "classe" les modalités de la variable partcpart pour la determination des rangs quand il manque des dates de naissance*/ data imput.imputenfant; set imput.imputenfant; length partcpart $2; /*Imputations déterministes: d'après la situation de couple d'ego*/ /*on corrige la variable cpart quand ego n'est pas en couple: cpart doit être à .*/ e13_14cpart_i=e13_14cpart; if e13_14cpart not in (" ") and q3couple in ("3","4") then e13_14cpart_i=" ";/*NC*/ partcpart=cats(e13_14part,e13_14cpart_i); if partcpart in ("12") then partcpartnum=1; else if partcpart in ("21") then partcpartnum=2; else if partcpart in ("11") then partcpartnum=3; else if partcpart in ("1 ") then partcpartnum=4; run; /* proc freq data=imput.imputenfant; table partcpart partcpart*q3couple/norow nocol nopercent; run; */ /*CREER UN RANG POUR LES ENFANTS*/ /*On met un rang aux enfants pour lesquels il n'y a pas de prob de date sur le bulletin*/ proc sort data=imput.imputenfant; by cabefla e13_14anai; run; /*on crée le rang de l'enfant quand bulltotdate="ok"*/ data imput.imputenfant; set imput.imputenfant; by cabefla; retain rangenf; if bulltotdate="ok" then do; if first.cabefla then rangenf=1; else rangenf=rangenf+1; end; run; /******Quand il manque des dates de naissance********/ /*Décisions: les enfants que d'ego ou que du cjt sont nés avant les enfants du couple les enfants vivant hors logement sont nés avant les enfants vivants dans le logement*/ /*S'il n'y a aucune dates, on regarde seulement partcpartnum*/ proc sort data=imput.imputenfant; by cabefla partcpartnum; run; data imput.imputenfant; set imput.imputenfant; by cabefla; retain rangenf3; IF nbenfdateok2=0 then do; if first.cabefla then rangenf3=1; else rangenf3=rangenf3+1; end; run; /*s'il y a au moins une date, on regarde les années renseignées et partcpartnum*/ proc sort data=imput.imputenfant; by cabefla e13_14anai partcpartnum; run; data imput.imputenfant; set imput.imputenfant; by cabefla; retain rangenf2; IF bulltotdate="pa" and nbenfdateok2 not in (0) then do; /*on traite les bulletins dans lesquels il n'y a que des enfants dans le tableau 14*/ /*les bulletins dans lesquels il n'y a que des enfants dans le tableau 13*/ /*les bulletins dans lesquels il y a des enfants dans les tableaux 13 et 14*/ if first.cabefla then rangenf2=1; else rangenf2=rangenf2+1; end; run; data imput.imputenfant; set imput.imputenfant; if bulltotdate="ok" then rangenfant=rangenf; else if nbenfdateok2=0 then rangenfant=rangenf3; else rangenfant=rangenf2; run; /* proc freq data=imput.imputenfant; table rangenfant; run; */ /* *on vérifie qu'il n'y ait pas plusieurs fois le même rang pour un cabefla; proc sort data=imput.imputenfant nodupkey out=essai dupout=doublons; by cabefla rangenfant; run; *ok; */ /*A partir du rang, on regarde la date du premier enfant, et du dernier enfant*/ proc sort data=imput.imputenfant; by cabefla rangenfant; run; data imput.imputenfant; set imput.imputenfant; by cabefla; if first.cabefla then dateprem=e13_14anai; if last.cabefla then dateder=e13_14anai; run; /*premier et dernier enfant de chaque tableau*/ data tab13; set imput.imputenfant; where tableau=13; run; proc sort data=tab13; by cabefla rangenfant; run; data tab13; set tab13; by cabefla ; if first.cabefla then dateprem13=e13_14anai; if last.cabefla then dateder13=e13_14anai; run; data tab14; set imput.imputenfant; where tableau=14; run; proc sort data=tab14; by cabefla rangenfant; run; data tab14; set tab14; by cabefla ; if first.cabefla then dateprem14=e13_14anai; if last.cabefla then dateder14=e13_14anai; run; /***on garde que les dates de premier et dernier enfant non vides************/ data dateprem; set imput.imputenfant; if dateprem not in (.) then output; keep cabefla dateprem; run; data dateder; set imput.imputenfant; if dateder not in (.) then output;keep cabefla dateder; run; data dateprem13; set tab13; if dateprem13 not in (.) then output;keep cabefla dateprem13; run; data dateder13; set tab13; if dateder13 not in (.) then output;keep cabefla dateder13; run; data dateprem14; set tab14; if dateprem14 not in (.) then output;keep cabefla dateprem14; run; data dateder14; set tab14; if dateder14 not in (.) then output;keep cabefla dateder14; run; proc delete data=tab13 tab14;run; /****** on copie les informations sur la base imputpage1 (base individus) ********/ data infoenfparcabefla; set imput.imputenfant; by cabefla; if first.cabefla then output; keep cabefla nbenftab2 nbenfdateok2 nbenftab132 nbenf13dateok2 nbenftab142 nbenf14dateok2 enftab13 enftab14 bulltotdate bull13date bull14date datemoy; run; proc sort data=infoenfparcabefla; by cabefla; run; data imputenfantcabefla; merge infoenfparcabefla dateprem dateder dateprem13 dateder13 dateprem14 dateder14; by cabefla; run; /*on colle cette base à imputpage1 pour pouvoir utiliser les variables créées*/ proc sort data=imputenfantcabefla; by cabefla; run; proc sort data=imputpage1; by cabefla; run; data imputpage1; merge imputpage1 imputenfantcabefla; by cabefla; run; /*on supprime les bases temporaires*/ proc delete data=imputenfantcabefla infoenfparcabefla dateprem dateder dateprem13 dateder13 dateprem14 dateder14;run; /*on tri la nouvelle base par cabefla*/ Proc sort data=imputpage1; By cabefla; Run; /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /*** ***/ /*** imputations 1ère page ***/ /*** ***/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /* Point sur la non réponse de la page 1 pour préparation des imputations; voir doc word "2012_10_30_Table individus"*/ /*proc freq data=imputpage1; table q0sexe q1anai q1mnai q2nbfreres q2nbsoeurs q2nbdemif q2nbdemis q3couple q4anai_c q4mnai_c q5sexe_c q6mois_c q6annee_c q7pacs q7mois_pacs q7annee_pacs q8mari q8mois_mari q8annee_mari q9tps_logr q10cause_r q10annee_s q10annee_d q11enfan q12enfan_c; run;*/ /*Pour chaque imputation, on crée n_ok, n_miss et num pour éviter les effets de bord: éviter que le premier d'un groupe soit manquant et que deux manquants se suivent (voir doc L.T)*/ /*on commence par imputer les 45 années de naissance manquantes pour ego*/ /*les cas ou il y a des enfants avec des dates de naissance*/ Proc sort data=imputpage1; By nbenftab2 q0sexe q3couple dateprem dateder dipl; Run; data imputpage1; set imputpage1; q1anai_i=q1anai; /*on crée une variable qui a les mêmes valeurs que la seconde*/ retain reserve;/*retain est fait sur le vecteur: la reserve*/ if nbenftab2=nbenfdateok2 then do; /*si il y a une reponse à q1anai on remplit la réserve*/ if q1anai not in (9999) and q1anai<=1993 then reserve=q1anai; /*si la réponse à anai est vide, on va piocher dans la réserve*/ if (q1anai in (9999) or q1anai>1993) then q1anai_i=reserve; /*on impute les nr au pacs lorsque les individus ne sont pas mariés*/ drop reserve; end; run; /*les cas ou il y a des enfants mais pas toutes les dates de naissance*/ Proc sort data=imputpage1; By nbenftab2 q0sexe q3couple datemoy dipl; Run; data imputpage1; set imputpage1; retain reserve;/*retain est fait sur le vecteur: la reserve*/ if (nbenftab2>nbenfdateok2) then do; /*si il y a une reponse à q1anai on remplit la réserve*/ if q1anai_i not in (9999) and q1anai<=1993 then reserve=q1anai_i; /*si la réponse à anai est vide, on va piocher dans la réserve*/ if (q1anai in (9999) or q1anai>1993) then q1anai_i=reserve; /*on impute les nr au pacs lorsque les individus ne sont pas mariés*/ drop reserve; end; run; /*les cas ou il y a des enfants mais sans dates de naissance ou quand il n'y a pas d'enfant*/ Proc sort data=imputpage1; By nbenftab2 q0sexe q3couple q4anai_c dipl; Run; data imputpage1; set imputpage1; retain reserve;/*retain est fait sur le vecteur: la reserve*/ if ((nbenf13dateok2=0 and nbenf14dateok2=0) or (nbenf13dateok2=. and nbenf14dateok2=0) or (nbenf13dateok2=0 and nbenf14dateok2=.) or (enftab13=. and enftab14=.)) and q4anai_c not in (9999,.) then do; /*si il y a une reponse à q1anai on remplit la réserve*/ if q1anai_i not in (9999) and q1anai<=1993 then reserve=q1anai_i; /*si la réponse à anai est vide, on va piocher dans la réserve*/ if (q1anai in (9999) or q1anai>1993) then q1anai_i=reserve; /*on impute les nr au pacs lorsque les individus ne sont pas mariés*/ drop reserve; end; run; data imputpage1; set imputpage1; if q4anai_c in (9999,.) and (enftab13=. and enftab14=.) and anai<=1993 then q1anai_i=anai; /*quand il n'y a pas de cjt ni d'enfant on prend l'année imputée du rp*/ run; /* proc freq data=imputpage1; table q1anai_i; where i_q1anai=2; run;*OK; proc print data=imputpage1; where q1anai_i=9999; run;*/ /*on impute ensuite les mois manquants*/ proc sort data=imputpage1; by q0sexe q1anai_i; run; data imputpage1; set imputpage1; By q0sexe q1anai_i; retain n_ok n_miss pb; if first.q1anai_i then do; n_ok=1; n_miss=2; end; if q1mnai not in (.) then do; num=n_ok; n_ok=n_ok+2; end; else if q1mnai in (.) then do; num=n_miss; n_miss=n_miss+2; end; else kk = 1 ; if last.q1anai_i then do; if n_ok+1 < n_miss then pb = 1; end; run; proc sort data=imputpage1; by q0sexe q1anai_i num; run; data imputpage1; set imputpage1; q1mnai_i=q1mnai; /*on crée une variable qui a les mêmes valeurs que la seconde*/ retain reserve;/*retain est fait sur le vecteur: la reserve*/ /*si il y a une reponse à q1mnai on remplit la réserve*/ if q1mnai not in (.) then reserve=q1mnai; /*si la réponse à q1mnai est vide, on va piocher dans la réserve*/ if q1mnai=. then q1mnai_i=reserve; /*on impute les nr à q1mnai*/ drop reserve num n_miss n_ok pb kk; run; /* proc freq data=imputpage1; table q1mnai_i; run;*ok; */ /**********************************************************************/ /*** ***/ /*** création groupes d'imputations (variable discriminantes) ***/ /*** ***/ /**********************************************************************/ /*On impute la variable CS qui comporte des données manquantes car on veut ensuite créer une variable regroupée que l'on utilisara dans tous les tris*/ proc sort data=imputpage1; by q0sexe q1anai_i dipl; run; data imputpage1; set imputpage1; By q0sexe q1anai_i dipl; retain n_ok n_miss pb; if first.dipl then do; n_ok=1; n_miss=2; end; if cs not in ("ZZ") then do; num=n_ok; n_ok=n_ok+2; end; else if cs in ("ZZ") then do; num=n_miss; n_miss=n_miss+2; end; else kk = 1 ; if last.dipl then do; if n_ok+1 < n_miss then pb = 1; end; run; proc sort data=imputpage1; by q0sexe q1anai_i dipl num; run; data imputpage1; set imputpage1; cs_i=cs; /*on crée une variable qui a les mêmes valeurs que la seconde*/ retain reserve;/*retain est fait sur le vecteur: la reserve*/ /*si il y a une reponse à cs on remplit la réserve*/ if cs not in ("ZZ") then reserve=cs; /*si la réponse à cs est vide, on va piocher dans la réserve*/ if cs=("ZZ") then cs_i=reserve; /*on impute les nr à cs*/ drop reserve num n_miss n_ok pb kk; run; /* proc freq data=imputpage1; where cs="ZZ"; table cs_i*cs/norow nocol nopercent; run; */ /*On regroupe ensuite les CS_i en utilisant aussi situat_r. C'est pour créer des groupes de tris*/ data imputpage1; set imputpage1; if situat_r=("3") or cs_i in ("84") then regroupCS=1;/*etudiants*/ else if cs_i in ("11","12","21","22","71","72") then regroupCS=2;/*petits agriculteurs artisans*/ else if cs_i in ("23","13","37","38") then regroupCS=3;/*chef d'entr, gros agr, cadres*/ else if cs_i in ("31","33","34","35","74") then regroupCS=4;/*prof libérales, professeurs*/ else if cs_i in ("42","43","45","75") then regroupCS=5;/*prof inter santé ou fonction publique, instit*/ else if cs_i in ("83","53","44","52","55","56","77","54","62","63") then regroupCS=6;/*policiers, employés, clergé*/ else if cs_i in ("46","47","48") then regroupCS=7;/*techniciens, prof inter entreprise*/ else if cs_i in ("64","65","67","68","69","78") then regroupCS=8;/*chauffeurs, ouvriers*/ else if cs_i in ("81","85","86") then regroupCS=9;/*sans activité*/ run; /* proc freq data=imputpage1; table regroupCS; run; */ data imputpage1; set imputpage1; /*on fait des groupes d'age*/ /*date de naissance d'ego*/ datenaissego=mdy(q1mnai_i,15,q1anai_i); dateenquete=mdy(2,1,2011); ageego=(dateenquete-datenaissego)/365.25; /*groupes d'age quiquennaux*/ if 25>ageego then groupageb="01"; else if 30>ageego>=25 then groupageb="02"; else if 35>ageego>=30 then groupageb="03"; else if 40>ageego>=35 then groupageb="04"; else if 45>ageego>=40 then groupageb="05"; else if 50>ageego>=45 then groupageb="06"; else if 55>ageego>=50 then groupageb="07"; else if 60>ageego>=55 then groupageb="08"; else if 65>ageego>=60 then groupageb="09"; else if 70>ageego>=65 then groupageb="10"; else if 75>ageego>=70 then groupageb="11"; else if 80>ageego>=75 then groupageb="12"; else if 85>ageego>=80 then groupageb="13"; else if 90>ageego>=85 then groupageb="14"; else if 110>ageego>=90 then groupageb="15"; /*groupes d'age*/ if 30>ageego then groupage="01"; else if 40>ageego>=30 then groupage="02"; else if 50>ageego>=40 then groupage="03"; else if 60>ageego>=50 then groupage="04"; else if 70>ageego>=60 then groupage="05"; else if 80>ageego>=70 then groupage="06"; else if 110>ageego>=80 then groupage="07"; run; data imputpage1; set imputpage1; groupesimput=cats(q0sexe,groupage,regroupCS); groupesimput2=cats(q0sexe,groupageb,regroupCS); run; /* proc freq data=imputpage1; table groupesimput; run;*groupesimput comporte 122 sous groupes: à regrouper; */ data imputpage1; set imputpage1; /*on fait des regroupements des groupes trops faibles : moins de 500 personnes*/ /*on privilégie l'age à la cs, on garde donc les groupes d'âge et on met la cs la plus proche*/ groupesimput3=groupesimput; /*on met les étudiants avec les inactifs*/ if groupesimput3="1021" then groupesimput3="1029"; if groupesimput3="1031" then groupesimput3="1039"; if groupesimput3="1041" then groupesimput3="1049"; if groupesimput3="2021" then groupesimput3="2029"; if groupesimput3="2031" then groupesimput3="2039"; if groupesimput3="2041" then groupesimput3="2049"; if groupesimput3="2051" then groupesimput3="2059"; if groupesimput3="2061" then groupesimput3="2069"; /*on met les chef d'entr, gros agr, cadres avec les prof libérales, professeurs (groupcs le plus proche)*/ if groupesimput3="1053" then groupesimput3="1054"; if groupesimput3="1063" then groupesimput3="1064"; if groupesimput3="1073" then groupesimput3="1074"; if groupesimput3="2053" then groupesimput3="2054"; if groupesimput3="2063" then groupesimput3="2064"; if groupesimput3="2073" then groupesimput3="2074"; /*On met les techniciens, prof inter entreprise avec les ouvriers*/ if groupesimput3="1057" then groupesimput3="1058"; if groupesimput3="1067" then groupesimput3="1068"; if groupesimput3="1077" then groupesimput3="1078"; if groupesimput3="2057" then groupesimput3="2058"; if groupesimput3="2067" then groupesimput3="2068"; if groupesimput3="2077" then groupesimput3="2078"; /*On met les prof libérales, professeurs avec les prof inter santé ou fonction publique */ if groupesimput3="2074" then groupesimput3="2075"; /*On met les "sans activité" des groupes d'âge 05,06 et 07 ensemble car ils sont trop peu*/ if groupesimput3 in ("1069","1079") then groupesimput3="1059"; run; /* proc freq data=imputpage1; table groupesimput3; run; */ /*On crée un groupesimput4 avec beaucoup moins de groupes pour les cas ou l'on va utiliser d'autres variables de tris*/ data imputpage1; set imputpage1; /*groupes d'age*/ if 30>ageego then groupagec="01"; else if 40>ageego>=30 then groupagec="02"; else if 60>ageego>=40 then groupagec="03"; else if 110>ageego>=60 then groupagec="04"; if situat_r=("3") or cs_i in ("84") or cs_i in ("81","85","86") then regroupCSb=1;/*etudiants et sans activité*/ else if cs_i in ("11","12","21","22","71","72") then regroupCSb=2;/*petits agriculteurs artisans*/ else if cs_i in ("23","13","37","38") then regroupCSb=3;/*chef d'entr, gros agr, cadres*/ else if cs_i in ("31","33","34","35","74") or cs_i in ("42","43","45","75") or cs_i in ("46","47","48") then regroupCSb=4;/*prof libérales, professeurs et prof inter santé ou fonction publique, instit, techniciens, prof inter entreprise*/ else if cs_i in ("83","53","44","52","55","56","77","54","62","63") or cs_i in ("64","65","67","68","69","78") then regroupCSb=5;/*policiers, employés, clergé et chauffeurs, ouvriers*/ groupesimput4=cats(q0sexe,groupagec,regroupCSb); /*rectifications sur les petits groupes*/ if groupesimput4="1041" then groupesimput4="1042"; if groupesimput4="1043" then groupesimput4="1044"; if groupesimput4="2043" then groupesimput4="2044"; if groupesimput4="1012" then groupesimput4="1015"; if groupesimput4="2012" then groupesimput4="2015"; /*les 1021 ?*/ run; /* proc freq data=imputpage1; table groupesimput4; run; */ proc sort data=imputpage1; by groupesimput4; run; data imputpage1; set imputpage1; by groupesimput4; nbg4=0; if first.groupesimput4 then nbg4=1; run; /* proc freq data=imputpage1; table nbg4; run; *groupesimput4 comporte 35 groupes; */ /*on utilisera donc groupesimput3 ou groupesimput4 selon les variables à imputer. Ca dépend des autres variables que l'on introduit dans le tris*/ /*on regroupe la variable nombre d'enfants pour ne pas avoir 18 groupes */ data imputpage1; set imputpage1; if nbenftab2=. then groupnbenf=0; else if nbenftab2=1 then groupnbenf=1; else if nbenftab2=2 then groupnbenf=2; else if nbenftab2=3 then groupnbenf=3; else if nbenftab2>=4 then groupnbenf=4; run; proc sort data=imputpage1; by cabefla; run; /**********************************************************************/ /*** ***/ /*** imputations page 1, suite ***/ /*** ***/ /**********************************************************************/ /********************************************************************* Q3COUPLE *************************************************************************/ /*Variable q3couple, les modalités à imputer concernent seulement des personnes non en couple: on impute "n'a jamais été en coupl"e ou l'a été "par le passé." On prend donc comme donneurs des célibataires*/ proc sort data=imputpage1; by groupesimput3 groupnbenf; run; data imputpage1; set imputpage1; By groupesimput3 groupnbenf; retain n_ok n_miss pb; if first.groupnbenf then do; n_ok=1; n_miss=2; end; if q3couple not in ("Z") then do; num=n_ok; n_ok=n_ok+2; end; else if q3couple in ("Z") then do; num=n_miss; n_miss=n_miss+2; end; else kk = 1 ; if last.groupnbenf then do; if n_ok+1 < n_miss then pb = 1; end; run;/*ok 0 pb*/ Proc sort data=imputpage1 ; By groupesimput3 groupnbenf num;/*on ajoute num pour éviter les effets de bord*/ Run; data imputpage1; set imputpage1; q3couple_i=q3couple; /*on crée une variable qui a les mêmes valeurs que la seconde*/ q10cause_r_i=q10cause_r; q10annee_d_i=q10annee_d; q10annee_s_i=q10annee_s; retain reserve reserveb reservec reserved;/*retain est fait sur le vecteur: la reserve*/ /*si il y a une reponse à q3couple on remplit la réserve*/ if q3couple not in ("Z") and q3couple in ("3","4") then reserve=q3couple; if q10cause_r not in ("Z"," ") and q3couple in ("3","4") then reserveb=q10cause_r; if q10annee_d not in (9999,.) and q3couple in ("3","4") then reservec=q10annee_d; if q10annee_s not in (9999,.) and q3couple in ("3","4") then reserved=q10annee_s; /*si la réponse à q3couple est vide, on va piocher dans la réserve*/ /*la question 10: si on a imputé q3couple_i=4 alors q10cause_r est nc sinon il faut imputer q10cause_r*/ if q3couple="Z" then do; q3couple_i=reserve; /*on impute les nr à q3couple*/ end; if q3couple="Z" and q3couple_i="4" then do; q10cause_r_i=" "; q10annee_d_i=.; q10annee_s_i=.; end; if q3couple="Z" and q3couple_i="3" then do; q10cause_r_i=reserveb; q10annee_d_i=reservec; q10annee_s_i=reserved; end; drop reserve reserveb reservec reserved num n_miss n_ok pb kk; run; /* proc freq data=imputpage1; table q3couple_i q3couple; where i_q3couple=4; run;*ok; */ /********************************************************************* PACS, MARIAGE ET MISE EN COUPLE (questions 6,7 et 8) *************************************************************************/ /* creation et codage des variables imputées*/ data imputpage1; set imputpage1; if Q3couple_i in ("1" "2") then do; if q7pacs="" then q7pacs_i="Z";else q7pacs_i=q7pacs; if q8mari="" then q8mari_i="Z";else q8mari_i=q8mari; end; else if Q3couple_i in ("3" "4") then do; q7pacs_i=""; q8mari_i="";end; run; /* proc freq;table q7pacs q7pacs_i q8mari q8mari_i;run; */ /* On crée une variable concaténée "pacsmari" qui permet de repérer simultanément les réponses et nr au pacs et au mariage. Cette variable, synthétisant l'information, nous sert ensuite à imputer selon les différents cas de NR*/ data imputpage1; set imputpage1; pacsmari=cats(q7pacs_i,q8mari_i); run; /* proc freq data=imputpage1; table pacsmari; run; *11,12,1Z,21,22,Z1,Z2,ZZ => il faut imputer les cas 1Z,Z1,Z2,ZZ; */ *************************************************; /*non mariés, réponse PACS manquante, on trie en ordre décroissant sur age car il n'y a pas de donneurs dans le groupe le plus jeune*/ Proc sort data=imputpage1 ; By q3couple_i q5sexe_c descending groupesimput3; Run; data imputpage1; set imputpage1; By q3couple_i q5sexe_c descending groupesimput3; retain n_ok n_miss pb; if first.groupesimput3 then do; n_ok=1; n_miss=2; end; if q7pacs not in ("Z"," ") and q8mari="2" then do; num=n_ok; n_ok=n_ok+2; end; else if q7pacs_i in ("Z" "") and pacsmari in ("Z2") then do; num=n_miss; n_miss=n_miss+2; end; else kk = 1 ; if last.groupesimput3 then do; if n_ok+1 < n_miss then pb = 1; end; run; /* proc freq data=imputpage1; table pb; run; */ Proc sort data=imputpage1 ; By q3couple_i q5sexe_c descending groupesimput3 num; Run; data imputpage1; set imputpage1; retain reserve; if q7pacs not in ("Z"," ") and q8mari="2" then reserve=q7pacs; if q7pacs_i in ("Z" "") and pacsmari in ("Z2") then q7pacs_i=reserve; drop reserve num n_miss n_ok pb kk; run; *************************************************; /*mariés, réponse PACS manquante*/ Proc sort data=imputpage1 ; By q3couple_i q5sexe_c descending groupesimput3; Run; data imputpage1; set imputpage1; By q3couple_i q5sexe_c descending groupesimput3; retain n_ok n_miss pb; if first.groupesimput3 then do; n_ok=1; n_miss=2; end; if q7pacs not in ("Z"," ") and q8mari="1" then do; num=n_ok; n_ok=n_ok+2; end; else if q7pacs_i in ("Z" "") and pacsmari in ("Z1") then do; num=n_miss; n_miss=n_miss+2; end; else kk = 1 ; if last.groupesimput3 then do; if n_ok+1 < n_miss then pb = 1; end; run; /* proc freq data=imputpage1; table pb; run; */ Proc sort data=imputpage1 ; By q3couple_i q5sexe_c descending groupesimput3 num; Run; data imputpage1; set imputpage1; retain reserve; if q7pacs not in ("Z"," ") and q8mari="1" then reserve=q7pacs; if q7pacs_i in ("Z" "") and pacsmari in ("Z1") then q7pacs_i=reserve; drop reserve num n_miss n_ok pb kk; run; *************************************************; /*On décide d'imputer ensuite les mariages sachant que les imputations pacs et mari sont indépendantes On choisit également de trier la base par la situation de couple, le sexe d'ego, puis le sexe du conjoint, la csp d'ego et l'année de naissance d'ego*/ Proc sort data=imputpage1 ; By q3couple_i q5sexe_c groupesimput3; Run; data imputpage1; set imputpage1; By q3couple_i q5sexe_c groupesimput3; retain n_ok n_miss pb; if first.groupesimput3 then do; n_ok=1; n_miss=2; end; if q8mari not in ("Z"," ") then do; num=n_ok; n_ok=n_ok+2; end; else if q8mari_i in ("Z") and pacsmari in ("2Z") then do; num=n_miss; n_miss=n_miss+2; end; else kk=1; if last.groupesimput3 then do; if n_ok+1 < n_miss then pb = 1; end; run; /* proc freq data=imputpage1; table pb; run; */ Proc sort data=imputpage1 ; By q3couple_i q5sexe_c groupesimput3 num; Run; data imputpage1; set imputpage1; retain reserve; if q8mari not in ("Z"," ") then reserve=q8mari; if q8mari_i in ("Z") and pacsmari="2Z" then q8mari_i=reserve; drop reserve num n_miss n_ok pb kk; run; *************************************************; /* Puis on impute pacs ET mariage lorsque les deux sont en nr. On garde le même tri */ Proc sort data=imputpage1 ; By q3couple_i q5sexe_c groupesimput3; Run; data imputpage1; set imputpage1; By q3couple_i q5sexe_c groupesimput3; retain n_ok n_miss pb; if first.groupesimput3 then do; n_ok=1; n_miss=2; end; if q8mari not in ("Z"," ") and q7pacs not in ("Z"," ") then do; num=n_ok; n_ok=n_ok+2; end; else if q8mari_i in ("Z") and q7pacs_i in ("Z") then do; num=n_miss; n_miss=n_miss+2; end; else kk=1; if last.groupesimput3 then do; if n_ok+1 < n_miss then pb = 1; end; run; /* proc freq data=imputpage1; table pb; run; */ Proc sort data=imputpage1 ; By q3couple_i q5sexe_c groupesimput3 num; Run; data imputpage1; set imputpage1; retain reserve; retain reserve2; if q8mari not in ("Z"," ") and q7pacs not in ("Z"," ") then do; reserve=q8mari; reserve2=q7pacs; end; /*si les réponses à année mari et année pacs sont vides on va piocher dans la réserve*/ if pacsmari="ZZ" then do; q8mari_i=reserve; q7pacs_i=reserve2; end; drop reserve reserve2 num n_miss n_ok pb kk; run; data imputpage1; set imputpage1; /*quand l'enquêté a répondu être pacsé mais n'a pas répondu à la question etes vous marié, on considère qu'il n'est pas marié: 2cas (imputation déterministe liée aux choix d'apurement)*/ if pacsmari="1Z" then do; q8mari_i="2"; end; run; /* proc freq data=imputpage1; table q8mari_i;run; */ /***************************** CORRECTION **********************************/ /* un problème de date: CABEFLA: 1000271741 q1anai: 1987 q4anai_c: 1989 q6annee_c:2006 q7pacs:1 q7annee_pacs:9999 q8mari: 1 q8annee_mari:2006 mise en couple et mariage la même année, conjoint a 17 ans, PACS renseigné mais pas de date */ *on corrige en amont; data imputpage1; set imputpage1; if CABEFLA=1000271741 then q7pacs_i="2"; run; /* proc freq data=imputpage1; table q8mari_i*q8mari_i q7pacs*q7pacs_i /norow nocol nopercent missing;run; */ proc print; where q7pacs_i="" and q3couple_i in ("1" "2"); var CABEFLA groupesimput3 q3couple_i pacsmari q7pacs q7pacs_i q8mari q8mari_i q1anai q4anai_c q6annee_c q7annee_pacs q8annee_mari ;run; /******************************************************************* ********************************************************************* PREPARATION IMPUTATIONS ANNEES COUPLE, PACS, MARIAGE ********************************************************************* *********************************************************************/ /*sauvegarde base complete*/ data imput.imputpage1transit; set imputpage1; run; /* creation base réduite*/ data imputpage1; set imputpage1; keep CABEFLA q0sexe ageego q1anai q1anai_i q1mnai q1mnai_i q3couple_i q3couple q4anai_c q4mnai_c q6annee_c q6mois_c q7pacs q7pacs_i q7annee_pacs q7mois_pacs q8mari q8mari_i q8annee_mari q8mois_mari groupage groupageb groupagec groupesimput groupesimput2 groupesimput3 groupesimput4 regroupcsb regroupcs; run; /***************************************************************************** creation indicateurs ******************************************************************************/ /*creation variable age conjoint*/ data imputpage1; set imputpage1; if q4anai_c not in (0 . 9999) and q4mnai_c not in (. 0 99) then do; /*date de naissance du conjoint*/ datenaisscjt=mdy(q4mnai_c,15,q4anai_c); dateenquete=mdy(2,1,2011); agecjt=(dateenquete-datenaisscjt)/365.25; /*regroupement*/ if agecjt <18 then groupagecjt="01"; else if 18== 60 then groupagecjt="05"; end; if q7annee_pacs not in (0 . 9999) and q7mois_pacs not in (. 0 99) then do; datepacs=mdy(q7mois_pacs,15,q7annee_pacs); datenaissego=mdy(q1mnai_i,15,q1anai_i); ageego_pacs=(datepacs-datenaissego)/365.25; if q4anai_c not in (0 . 9999) and q4mnai_c not in (. 0 99) then do; datenaisscjt=mdy(q4mnai_c,15,q4anai_c); agecjt_pacs=(datepacs-datenaisscjt)/365.25; end; end; run; /* proc print data=imputpage1 (obs=50);where agecjt ne .;var q4anai_c agecjt groupagecjt;run; proc freq;table groupagecjt;run; */ /*on effectue des regroupements creation indic_anpacs indic_anmar indic_ancouple*/ data imputpage1; set imputpage1; if q7annee_pacs not in (0 . 9999) then do; a=put(q7annee_pacs,best4.); if substr(a,4,1) in ("0" "1" ) then indic_anpacs=cat(substr(a,1,3),"0"); else if substr(a,4,1) in ("2" "3" ) then indic_anpacs=cat(substr(a,1,3),"2"); else if substr(a,4,1) in ("4" "5" ) then indic_anpacs=cat(substr(a,1,3),"4"); else if substr(a,4,1) in ("6" "7" ) then indic_anpacs=cat(substr(a,1,3),"6"); else if substr(a,4,1) in ("8" "9" ) then indic_anpacs=cat(substr(a,1,3),"8"); end; if q8annee_mari not in (0 . 9999) then do; b=put(q8annee_mari,best4.); if substr(b,4,1) in ("0" "1" ) then indic_anmar=cat(substr(b,1,3),"0"); else if substr(b,4,1) in ("2" "3" ) then indic_anmar=cat(substr(b,1,3),"2"); else if substr(b,4,1) in ("4" "5" ) then indic_anmar=cat(substr(b,1,3),"4"); else if substr(b,4,1) in ("6" "7" ) then indic_anmar=cat(substr(b,1,3),"6"); else if substr(b,4,1) in ("8" "9" ) then indic_anmar=cat(substr(b,1,3),"8"); end; if q6annee_c not in (0 . 9999) then do; c=put(q6annee_c,best4.); if substr(c,4,1) in ("0" "1" ) then indic_ancou=cat(substr(c,1,3),"0"); else if substr(c,4,1) in ("2" "3" ) then indic_ancou=cat(substr(c,1,3),"2"); else if substr(c,4,1) in ("4" "5" ) then indic_ancou=cat(substr(c,1,3),"4"); else if substr(c,4,1) in ("6" "7" ) then indic_ancou=cat(substr(c,1,3),"6"); else if substr(c,4,1) in ("8" "9" ) then indic_ancou=cat(substr(c,1,3),"8"); end; drop a b c; run; /* proc freq; table indic_anpacs q7annee_pacs q8annee_mari indic_anmar indic_ancou ;run; */ /********************************************************************************/ /****************************************************************************** *test des ages au mariage minimum renseigné; data test; set imputpage1; if q8annee_mari not in (. 0 9999) and q1anai not in (. 0 9999) and q4anai_c not in (. 0 9999) then do; agemarego=q8annee_mari-q1anai; agemarconj=q8annee_mari-q4anai_c; end; proc freq;table agemarego agemarconj; run; proc print; where agemarconj ne . and agemarconj <16; var agemarconj q0sexe q1anai q4anai_c q6annee_c q8mari q8annee_mari; proc delete data=test; run; *essentiellement des femmes, valeurs entre 9 et 15; *******************************************************************************/ /* * verification imputations PACS et mariage; proc freq; table q7pacs*q7pacs_i/norow nocol nopercent;run; proc freq; table q8mari*q8mari_i/norow nocol nopercent;run; */ /********************************************************************* ANNEES PACS, MARIAGE ET MISE EN COUPLE *************************************************************************/ /*On impute les années de pacs, de mariage et de mise en couple, puis les mois pour respecter la saisonnalité*/ /*On crée les variables mois et année de pacs et mariage imputées et on les mets en NC quand on a mis non à pacs ou à mariage imputées Les cas où une date était renseignée ont déjà été apurées */ data imputpage1; set imputpage1; q6annee_c_i=.; q6mois_c_i=.; q7annee_pacs_i=.; q7mois_pacs_i=.; q8annee_mari_i=.; q8mois_mari_i=.; if q3couple_i in ("1","2") then do; if q6annee_c=. then q6annee_c_i=9999;else q6annee_c_i=q6annee_c; if q6mois_c=. then q6mois_c_i=99;else q6mois_c_i=q6mois_c; end; else if q3couple_i in ("3","4") then do; q6annee_c_i=.; q6mois_c_i=.; end; if q7pacs_i="1" then do; if q7annee_pacs=. then q7annee_pacs_i=9999; else q7annee_pacs_i=q7annee_pacs; if q7mois_pacs=. then q7mois_pacs_i=99; else q7mois_pacs_i=q7mois_pacs; end; else if q7pacs_i="2" then do;q7annee_pacs_i=.;q7mois_pacs_i=.;end; if q8mari_i="1" then do; if q8annee_mari=. then q8annee_mari_i=9999;else q8annee_mari_i=q8annee_mari; if q8mois_mari=. then q8mois_mari_i=99;else q8mois_mari_i=q8mois_mari; end; else if q8mari_i="2" then do;q8annee_mari_i=.;q8mois_mari_i=.;end; run; /*on crée une variable concaténée qui indique les nr pour les dates de couple (année de mise en couple,année pacs et année mariage) */ data imputpage1; set imputpage1; if q6annee_c in (9999,.) and q3couple_i in ("1","2") then infocouple=9; else if q6annee_c in (9999,.) and q3couple_i in ("3","4") then infocouple=8; else infocouple=1; if q7annee_pacs_i in (9999,.) and q7pacs_i="2" then infopacs=8; else if q7annee_pacs_i in (9999,.) and q7pacs_i="1" then infopacs=9; else if q7annee_pacs_i not in (.,9999) and q7pacs_i="1" then infopacs=1; if q8annee_mari_i=. and q8mari_i="2" then infomari=8; else if q8annee_mari_i in (9999,.) and q8mari_i="1" then infomari=9; else if q8annee_mari_i not in (.,9999) and q8mari_i="1" then infomari=1; infodate=cats(infocouple,infopacs,infomari); run; /* proc freq data=imputpage1; table infodate; run; */ /*on crée une variable de suivi pour vérifier que toutes les non réponses aux dates sont bien créées*/ data imputpage1; set imputpage1; length suivi $3; suivi="0"; run; /******************************************************************/ /*1*/ /******************************************************************/ /* enquêtés non pacsés et mariés, il manque date mariage*/ Proc sort data=imputpage1 ; By groupagecjt q6annee_c groupesimput3; Run; data imputpage1; set imputpage1; By groupagecjt q6annee_c groupesimput3; retain n_ok n_miss pb; if first.groupesimput3 then do; n_ok=1; n_miss=2; end; if q8annee_mari not in (9999) then do; num=n_ok; n_ok=n_ok+2; end; else if q8annee_mari_i in (9999) then do; num=n_miss; n_miss=n_miss+2; end; else kk=1; if last.groupesimput3 then do; if n_ok+1 < n_miss then pb = 1; end; run; /* proc freq data=imputpage1; table pb; run; */ Proc sort data=imputpage1 ; By groupagecjt q6annee_c groupesimput3 num; Run; data imputpage1; set imputpage1; retain reserve; if q8annee_mari not in (9999,.) then reserve=q8annee_mari; if infodate="189" and q8annee_mari_i=9999 then do ;q8annee_mari_i=reserve;suivi="1";end; /*on impute quand l'année de couple est renseignée et l'année pacs nc*/ drop reserve num n_miss n_ok pb kk; run; /******************************************************************/ /*1 bis */ /******************************************************************/ /* vérification imputation et correction */ data imputpage1; set imputpage1; pbdate=0; *enquetes non imputés; if infodate="189" and q8annee_mari_i in (0 . 9999) then pbdate=1; if infodate="189" then do; *ego trop jeune pour se marier; if (q1anai_i +16) > q8annee_mari_i then pbdate=2; end; *conjoint trop jeune pour se marier; if infodate="189" and q4anai_c not in (. 9999) then do; if (q4anai_c +16) > q8annee_mari_i then pbdate=3; end; *mariage avant mise en couple; if infodate="189" and q6annee_c > q8annee_mari_i then pbdate=4; if pbdate ne 0 then q8annee_mari_i=9999; run; /* proc freq;table pbdate;run; proc print; where pbdate ne 0; var pbdate q0sexe q1anai q4anai_c q8annee_mari q8annee_mari_i q6annee_c q8mari ;run; */ Proc sort data=imputpage1 ; By groupage groupagecjt indic_ancou ; data imputpage1;set imputpage1; By groupage groupagecjt indic_ancou ; retain n_ok n_miss pb; if first.indic_ancou then do; n_ok=1; n_miss=2;end; if q8annee_mari not in (9999,.) and pbdate=0 then do; *on prend des donneurs qui ne sont pas mariés trop jeunes; if q4anai_c not in (. 9999) then do; a=q1anai_i +16;b=q4anai_c +16; if q8annee_mari>a and q8annee_mari>b then do;num=n_ok; n_ok=n_ok+2; end; end; else do; a=q1anai_i +16; if q8annee_mari>a then do;num=n_ok; n_ok=n_ok+2; end; end; end; *choix des receveurs; else if q8annee_mari_i in (9999,.) and pbdate ne 0 then do; num=n_miss; n_miss=n_miss+2; end; else num=10000; if last.indic_ancou then do; if n_ok+1 < n_miss then pb = 1; end; drop a b; run; Proc sort data=imputpage1 ; By groupage groupagecjt indic_ancou num; Run; data imputpage1; set imputpage1; retain reserve; if q8annee_mari not in (9999,.) and pbdate=0 then reserve=q8annee_mari; if pbdate ne 0 and q8annee_mari_i=9999 then do ; if q4anai_c not in (. 9999) then do; a=q1anai_i +16;b=q4anai_c +16; if reserve>a and reserve>b and q6annee_c<= reserve then do;q8annee_mari_i=reserve;suivi="1b";end; end; else do; a=q1anai_i +16; if reserve>a and q6annee_c<= reserve then do;q8annee_mari_i=reserve;suivi="1b";end; end; end; drop reserve num n_miss n_ok pb a b pbdate; run; /**********************************************************************************/ /* si encore des problemes , ultime correction*/ data imputpage1; set imputpage1; pbdate=0; *enquetes non imputés; if infodate="189" and q8annee_mari_i in (0 . 9999) then pbdate=1; if infodate="189" then do; *ego trop jeune pour se marier; if (q1anai_i +16) > q8annee_mari_i then pbdate=2; end; *conjoint trop jeune pour se marier; if infodate="189" and q4anai_c not in (. 9999) then do; if (q4anai_c +16) > q8annee_mari_i then pbdate=3; end; *mariage avant mise en couple; if infodate="189" and q6annee_c > q8annee_mari_i then pbdate=4; *if pbdate ne 0 then q8annee_mari_i=9999; run; /* proc freq;table pbdate;run; proc print; where pbdate ne 0; var q0sexe q1anai q4anai_c q8annee_mari q8annee_mari_i q6annee_c q8mari ;run; */ data imputpage1; set imputpage1; if pbdate ne 0 and infodate="189" then do; if q4anai_c=. or q4anai_c<= q1anai_i then do; *ego plus jeune; if q1anai_i+18 < q6annee_c then c=q6annee_c; else if q6annee_c < q1anai_i+18 < 2011 then c=q1anai_i+18; else c=2011 ; *borne inférieure; if c+15< 2011 then d=c+15 ;else d=2011;*borne supérieure; q8annee_mari_i=c + round(ranuni(7)* (d-c)); end; else if q4anai_c > q1anai_i then do;* conjoint plus jeune; if q4anai_c+18 < q6annee_c then c=q6annee_c; else if q6annee_c < q4anai_c+18 < 2011 then c=q4anai_c+18; else c=2011 ; *borne inférieure; if c+15< 2011 then d=c+15 ;else d=2011;*borne supérieure; q8annee_mari_i=c + round(ranuni(7)* (d-c)); end; suivi="1c"; if q8annee_mari_i> 2011 then q8annee_mari_i=9999; end; drop d c pbdate; run; /**********************************************************************************/ /******************************************************************/ /*2*/ /*******************************************************************/ /*individus pacsés et mariés, il manque l'année de mariage*/ Proc sort data=imputpage1 ; By q3couple_i q6annee_c q7annee_pacs groupesimput3; Run; data imputpage1; set imputpage1; By q3couple_i q6annee_c q7annee_pacs groupesimput3; retain n_ok n_miss pb; if first.groupesimput3 then do; n_ok=1; n_miss=2; end; if q8annee_mari not in (9999,.) then do; num=n_ok; n_ok=n_ok+2; end; else if q8annee_mari_i in (9999) and infodate="189" then do; num=n_miss; n_miss=n_miss+2; end; else kk=1; if last.groupesimput3 then do; if n_ok+1 < n_miss then pb = 1; end; run; /* proc freq data=imputpage1; table pb; run; */ Proc sort data=imputpage1 ; By q3couple_i q6annee_c q7annee_pacs groupesimput3 num; Run; data imputpage1; set imputpage1; retain reserve;/*retain est fait sur le vecteur: la reserve*/ /*si il y a une reponse à mari on remplit la réserve*/ if q8annee_mari not in (9999,.) then reserve=q8annee_mari; /*si la réponse à année mari est vide on va piocher dans la réserve*/ if infodate="119" and q8annee_mari_i=9999 then do ;q8annee_mari_i=reserve;suivi="2";end; /*on impute quand l'année couple et l'année pacs sont renseignées*/ drop reserve num n_miss n_ok pb kk; run; /******************************************************************/ /*2 bis */ /******************************************************************/ /* vérification imputation et correction */ data imputpage1; set imputpage1; pbdate=0; *enquetes non imputés; if infodate="119" and q8annee_mari_i in (0 . 9999) then pbdate=1; *mariage avant PACS; if infodate="119" and q8annee_mari_i < q7annee_pacs then pbdate=2; *ego trop jeune pour se marier; if infodate="119" then do; if (q1anai_i +16) > q8annee_mari_i then pbdate=3; end; *conjoint trop jeune pour se marier; if infodate="119" and q4anai_c not in (. 0 9999) then do; if (q4anai_c +16) > q8annee_mari_i then pbdate=4; end; if pbdate ne 0 then q8annee_mari_i=9999; run; /* proc freq;table pbdate;run; proc print; where pbdate ne 0; var infodate q7annee_pacs q1anai q4anai_c q8annee_mari q8annee_mari_i q6annee_c q8mari ;run; */ Proc sort data=imputpage1 ; By groupage groupagecjt indic_anpacs ; data imputpage1;set imputpage1; By groupage groupagecjt indic_anpacs ; retain n_ok n_miss pb; if first.indic_anpacs then do; n_ok=1; n_miss=2;end; if q8annee_mari not in (9999,.) and q7annee_pacs not in (9999 .) and pbdate=0 then do; num=n_ok; n_ok=n_ok+2; end; else if pbdate ne 0 then do; num=n_miss; n_miss=n_miss+2; end; else num=10000; if last.indic_anpacs then do; if n_ok+1 < n_miss then pb = 1; end; run; Proc sort data=imputpage1 ; By groupage groupagecjt indic_anpacs num; Run; data imputpage1; set imputpage1; retain reserve ; if q8annee_mari not in (9999,.) and pbdate=0 then do; reserve=q8annee_mari; end; if pbdate ne 0 then do ; if q6annee_c <= q7annee_pacs <= reserve then do; q8annee_mari_i=reserve;suivi="2b"; end; end; drop reserve num n_miss n_ok pb pbdate ; run; /* proc freq;table suivi;run;*/ /**********************************************************************************/ /* si encore des problemes , ultime correction*/ data imputpage1; set imputpage1; pbdate=0; *enquetes non imputés; if infodate="119" and q8annee_mari_i in (0 . 9999) then pbdate=1; *mariage avant PACS; if infodate="119" and q8annee_mari_i < q7annee_pacs then pbdate=2; *ego trop jeune pour se marier; if infodate="119" then do; if (q1anai_i +16) > q8annee_mari_i then pbdate=3; end; *conjoint trop jeune pour se marier; if infodate="119" and q4anai_c not in (. 0 9999) then do; if (q4anai_c +16) > q8annee_mari_i then pbdate=4; end; if pbdate ne 0 then q8annee_mari_i=9999; run; /* proc freq;table pbdate;run; proc print; where pbdate ne 0; var infodate q7annee_pacs q1anai q4anai_c q8annee_mari q8annee_mari_i q6annee_c q8mari ;run; */ data imputpage1; set imputpage1; if pbdate ne 0 and infodate="119" then do; c=q7annee_pacs;*borne inférieure; d=2011;*borne supérieure; q8annee_mari_i=c + round(ranuni(7)* (d-c)); suivi="2c" ; if q8annee_mari_i> 2011 then q8annee_mari_i=9999; end; drop d c pbdate; run; /**********************************************************************************/ /******************************************************************/ /*3*/ /***************************************************************/ /*individu non mariés, il seulement l'année de pacs*/ Proc sort data=imputpage1 ; By q3couple_i q6annee_c groupesimput3; Run; data imputpage1; set imputpage1; By q3couple_i q6annee_c groupesimput3; retain n_ok n_miss pb; if first.groupesimput3 then do; n_ok=1; n_miss=2; end; if q7annee_pacs not in (9999,.) then do; num=n_ok; n_ok=n_ok+2; end; else if q7annee_pacs_i in (9999) then do; num=n_miss; n_miss=n_miss+2; end; else kk=1; if last.groupesimput3 then do; if n_ok+1 < n_miss then pb = 1; end; run; /* proc freq data=imputpage1; table pb; run; */ Proc sort data=imputpage1 ; By q3couple_i q6annee_c groupesimput3 num; Run; data imputpage1; set imputpage1; retain reserve;/*retain est fait sur le vecteur: la reserve*/ /*si il y a une reponse à pacs on remplit la réserve*/ if q7annee_pacs_i not in (9999,.) then reserve=q7annee_pacs_i; /*si la réponse à année pacs est vide on va piocher dans la réserve*/ if infodate="198" and q7annee_pacs_i in (9999) then do;q7annee_pacs_i=reserve;suivi="3";end; /*on impute*/ drop reserve num n_miss n_ok pb kk; run; /******************************************************************/ /*3 bis */ /******************************************************************/ /* vérification imputation et correction */ data imputpage1; set imputpage1; pbdate=0; *enquetes non imputés; if infodate="198" and q7annee_pacs_i in (0 . 9999) then pbdate=1; *ego trop jeune pour se pacser; if infodate="198" then do; if (q1anai_i+18) > q7annee_pacs_i then pbdate=2; end; *conjoint trop jeune pour se pacser; if infodate="198" and q4anai_c not in (. 0 9999) then do; if (q4anai_c +18) > q7annee_pacs_i then pbdate=3; end; *pacs avant mise en couple; if infodate="198" and q7annee_pacs_ia and q7annee_pacs>b then do;num=n_ok; n_ok=n_ok+2; end; end; else do; a=q1anai_i +18; if q7annee_pacs>a then do;num=n_ok; n_ok=n_ok+2; end; end; num=n_ok; n_ok=n_ok+2; end; else if pbdate ne 0 then do; num=n_miss; n_miss=n_miss+2; end; else num=10000; if last.indic_ancou then do; if n_ok+1 < n_miss then pb = 1; end; run; Proc sort data=imputpage1 ; By groupage groupagecjt indic_ancou num; Run; data imputpage1; set imputpage1; retain reserve ; if q7annee_pacs not in (9999,.) and pbdate=0 then do; reserve=q7annee_pacs; end; if pbdate ne 0 then do ; if q4anai_c not in (. 9999) then do; a=q1anai_i +18;b=q4anai_c +18; if reserve>a and reserve>b then do;q7annee_pacs_i=reserve;suivi="3b";end; end; else do; a=q1anai_i +16; if reserve>a then do;q7annee_pacs_i=reserve;suivi="3b";end; end; end; drop reserve num n_miss n_ok pb pbdate a b; run; /* proc freq;table suivi;run;*/ /**********************************************************************************/ /* si encore des problemes , ultime correction*/ data imputpage1; set imputpage1; pbdate=0; *enquetes non imputés; if infodate="198" and q7annee_pacs_i in (0 . 9999) then pbdate=1; *ego trop jeune pour se pacser; if infodate="198" then do; if (q1anai_i+18) > q7annee_pacs_i then pbdate=2; end; *conjoint trop jeune pour se pacser; if infodate="198" and q4anai_c not in (. 0 9999) then do; if (q4anai_c +18) > q7annee_pacs_i then pbdate=3; end; *pacs avant mise en couple; if infodate="198" and q7annee_pacs_i= 1999 then a=q1anai_i+18; end; else if q6annee_c >= 1999 then do; if q1anai_i+18 < q6annee_c then a=q6annee_c; else if q1anai_i+18 >= q6annee_c then a=q1anai_i+18; end; end; else if q4anai_c > q1anai_i then do;* conjoint plus jeune; if q6annee_c < 1999 then do; if q4anai_c+18 < 1999 then a=1999; else if q4anai_c+18 >= 1999 then a=q4anai_c+18; end; else if q6annee_c >= 1999 then do; if q4anai_c+18 < q6annee_c then a=q6annee_c; else if q4anai_c+18 >= q6annee_c then a=q4anai_c+18; end; end; b=2011;*borne supérieure; q7annee_pacs_i=a + round(ranuni(7)* (b-a)); suivi="3c" ; if q7annee_pacs_i>2011 or q7annee_pacs_i< 1999 then q7annee_pacs_i=9999; end; drop a b pbdate; run; /**********************************************************************************/ /*******************************************************************/ /*4*/ /*******************************************************************/ /*individus mariés et pacsés, il manque le PACS*/ Proc sort data=imputpage1 ; By q3couple_i q6annee_c q8annee_mari groupesimput3;Run; data imputpage1; set imputpage1; By q3couple_i q6annee_c q8annee_mari groupesimput3; retain n_ok n_miss pb; if first.groupesimput3 then do; n_ok=1; n_miss=2; end; if q7annee_pacs not in (9999,.) then do; num=n_ok; n_ok=n_ok+2; end; else if q7annee_pacs in (9999,.) then do; num=n_miss; n_miss=n_miss+2; end; else kk=1; if last.groupesimput3 then do; if n_ok+1 < n_miss then pb = 1; end; run; /* proc freq data=imputpage1; table pb; run; */ Proc sort data=imputpage1 ; By q3couple_i q6annee_c q8annee_mari groupesimput3 num; Run; data imputpage1; set imputpage1; retain reserve;/*retain est fait sur le vecteur: la reserve*/ /*si il y a une reponse à pacs on remplit la réserve*/ if q7annee_pacs_i not in (9999,.) then reserve=q7annee_pacs_i; /*si la réponse à année pacs est vide on va piocher dans la réserve*/ if infodate="191" then do;q7annee_pacs_i=reserve;suivi="4";end; /*on impute*/ drop reserve num n_miss n_ok pb kk; run; /******************************************************************/ /*4 bis */ /******************************************************************/ /* vérification imputation et correction */ data imputpage1; set imputpage1; pbdate=0; *enquetes non imputés; if infodate="191" and q7annee_pacs_i in (0 . 9999) then pbdate=1; *ego trop jeune pour se pacser; if infodate="191" then do; if (q1anai_i+18) > q7annee_pacs_i then pbdate=2; end; *conjoint trop jeune pour se pacser; if infodate="191" and q4anai_c not in (. 0 9999) then do; if (q4anai_c +18) > q7annee_pacs_i then pbdate=3; end; *pacs avant mise en couple; if infodate="191" and q7annee_pacs_i q8annee_mari then pbdate=5; if pbdate ne 0 then q7annee_pacs_i=9999; run; /* proc freq;table pbdate;run; proc print; where pbdate ne 0; var CABEFLA pbdate infodate q7pacs_i q7pacs q7annee_pacs q7annee_pacs_i q1anai q4anai_c q6annee_c q8mari q8annee_mari ;run; */ Proc sort data=imputpage1 ; By groupage groupagecjt indic_ancou indic_anmar ; data imputpage1;set imputpage1; By groupage groupagecjt indic_ancou indic_anmar ; retain n_ok n_miss pb; if first.indic_anmar then do; n_ok=1; n_miss=2;end; if q7annee_pacs not in (9999,.) and pbdate=0 then do; if q4anai_c not in (. 9999) then do; a=q1anai_i +18;b=q4anai_c +18; if q7annee_pacs>a and q7annee_pacs>b then do;num=n_ok; n_ok=n_ok+2; end; end; else do; a=q1anai_i +18; if q7annee_pacs>a then do;num=n_ok; n_ok=n_ok+2; end; end; num=n_ok; n_ok=n_ok+2; end; else if pbdate ne 0 then do; num=n_miss; n_miss=n_miss+2; end; else num=10000; if last.indic_anmar then do; if n_ok+1 < n_miss then pb = 1; end; run; Proc sort data=imputpage1 ; By groupage groupagecjt indic_ancou indic_anmar num; Run; data imputpage1; set imputpage1; retain reserve ; if q7annee_pacs not in (9999,.) and pbdate=0 then do; reserve=q7annee_pacs; end; if pbdate ne 0 then do ; c=q8annee_mari; if q4anai_c not in (. 9999) then do; a=q1anai_i +18;b=q4anai_c +18; if reserve>a and reserve>b and reserve<=c then do;q7annee_pacs_i=reserve;suivi="4b";end; end; else do; a=q1anai_i +16; if reserve>a and reserve<=c then do;q7annee_pacs_i=reserve;suivi="4b";end; end; end; drop reserve num n_miss n_ok pb a b c; run; /* proc freq;table pbdate;run; proc print; where pbdate ne 0; var CABEFLA pbdate infodate q7pacs_i q7pacs q7annee_pacs q7annee_pacs_i q1anai q4anai_c q6annee_c q8mari q8annee_mari ;run; proc freq;table suivi;run;*/ /**********************************************************************************/ /* si encore des problemes , ultime correction*/ data imputpage1; set imputpage1; pbdate=0; *enquetes non imputés; if infodate="191" and q7annee_pacs_i in (0 . 9999) then pbdate=1; *ego trop jeune pour se pacser; if infodate="191" then do; if (q1anai_i+18) > q7annee_pacs_i then pbdate=2; end; *conjoint trop jeune pour se pacser; if infodate="191" and q4anai_c not in (. 0 9999) then do; if (q4anai_c +18) > q7annee_pacs_i then pbdate=3; end; *pacs avant mise en couple; if infodate="191" and q7annee_pacs_i q8annee_mari then pbdate=5; if pbdate ne 0 then q7annee_pacs_i=9999; run; /* proc freq;table pbdate;run; proc print; where pbdate ne 0; var infodate q7annee_pacs q7annee_pacs_i q1anai q4anai_c q6annee_c ;run; */ data imputpage1; set imputpage1; a=0;b=0;pb=0; if pbdate ne 0 and infodate="191" then do; *borne inférieure; if q4anai_c=. or q4anai_c<= q1anai_i then do; *ego plus jeune; if q6annee_c < 1999 then do; if q1anai_i+18 < 1999 then a=1999; else if q1anai_i+18 >= 1999 then a=q1anai_i+18; end; else if q6annee_c >= 1999 then do; if q1anai_i+18 < q6annee_c then a=q6annee_c; else if q1anai_i+18 >= q6annee_c then a=q1anai_i+18; end; end; else if q4anai_c > q1anai_i then do;* conjoint plus jeune; if q6annee_c < 1999 then do; if q4anai_c+18 < 1999 then a=1999; else if q4anai_c+18 >= 1999 then a=q4anai_c+18; end; else if q6annee_c >= 1999 then do; if q4anai_c+18 < q6annee_c then a=q6annee_c; else if q4anai_c+18 >= q6annee_c then a=q4anai_c+18; end; end; else pb=1; *borne supérieure; if q8annee_mari >= 1999 then b=q8annee_mari; else pb=1; *verification; if q6annee_c=q8annee_mari then pb=2; if (b-a) < 0 then pb=3; end; *imputation q7annee_pacs_i; if pbdate ne 0 and pb=0 then do; q7annee_pacs_i=a + round(ranuni(7)* (b-a)); suivi="4c" ; if q7annee_pacs_i>2011 or q7annee_pacs_i< 1999 then q7annee_pacs_i=9999; end; *cas problematiques; else if pbdate ne 0 and pb ne 0 then do; if pb in (1 3) then q7annee_pacs_i=9999; if pb=2 then q7annee_pacs_i=q6annee_c; end; drop a b pb; run; /* proc print; where pbdate ne 0; var CABEFLA infodate q7pacs_i q7pacs q7annee_pacs q7annee_pacs_i q1anai q4anai_c q6annee_c q8mari q8annee_mari ;run; */ /**********************************************************************************/ /**************************************************************************/ /*5*/ /**************************************************************************/ /* cas où il manque l'année de Pacs et l'année de mariage*/ Proc sort data=imputpage1 ; By q3couple_i q6annee_c groupesimput3; Run; data imputpage1; set imputpage1; By q3couple_i q6annee_c groupesimput3; retain n_ok n_miss pb; if first.groupesimput3 then do; n_ok=1; n_miss=2; end; if q7annee_pacs not in (9999,.) and q8annee_mari not in (9999,.) then do; num=n_ok; n_ok=n_ok+2; end; else if q7annee_pacs in (9999,.) and q8annee_mari in (9999,.) then do; num=n_miss; n_miss=n_miss+2; end; else kk=1; if last.groupesimput3 then do; if n_ok+1 < n_miss then pb = 1; end; run; /* proc freq data=imputpage1; table pb; run; */ Proc sort data=imputpage1 ; By q3couple_i q6annee_c groupesimput3 num; Run; data imputpage1; set imputpage1; retain reserve;/*retain est fait sur le vecteur: la reserve*/ retain reserveb;/*retain est fait sur le vecteur: la reserveb*/ /*si il y a une reponse à pacs et mari on remplit la réserve*/ if q7annee_pacs_i not in (9999,.) and q8annee_mari_i not in (9999,.) then do; reserve=q7annee_pacs_i; reserveb=q8annee_mari_i; end; /*si les réponses à année pacs et année mari sont vides on va piocher dans la réserve*/ if infodate="199" and (q7annee_pacs_i in (9999,.) or q8annee_mari_i in (9999,.)) then do; q7annee_pacs_i=reserve; /*on impute*/ q8annee_mari_i=reserveb; /*on impute*/ suivi="5"; end; drop reserve reserveb num n_miss n_ok pb kk; run; /******************************************************************/ /*5 bis */ /******************************************************************/ /* vérification imputation et correction */ data imputpage1; set imputpage1; pbdate=0; *enquetes non imputés; if infodate="199" and q7annee_pacs_i in (0 . 9999) then pbdate=1; *ego trop jeune pour se pacser; if infodate="199" then do; if (q1anai_i+18) > q7annee_pacs_i then pbdate=2; end; *conjoint trop jeune pour se pacser; if infodate="199" and q4anai_c not in (. 0 9999) then do; if (q4anai_c +18) > q7annee_pacs_i then pbdate=3; end; *pacs avant mise en couple; if infodate="199" and q7annee_pacs_iq8annee_mari_i then pbdate=5; if pbdate ne 0 then q7annee_pacs_i=9999; run; /* proc freq;table pbdate;run; proc print; where pbdate ne 0; var pbdate infodate q7pacs_i q7annee_pacs q7annee_pacs_i q1anai q4anai_c q6annee_c q8mari ;run; */ Proc sort data=imputpage1 ; By groupage groupagecjt indic_ancou; Run; data imputpage1; set imputpage1; By groupage groupagecjt indic_ancou; retain n_ok n_miss pb; if first.indic_ancou then do; n_ok=1; n_miss=2; end; if q7annee_pacs not in (9999,.) and q8annee_mari not in (9999,.) then do; num=n_ok; n_ok=n_ok+2; end; else if q7annee_pacs in (9999,.) and q8annee_mari in (9999,.) then do; num=n_miss; n_miss=n_miss+2; end; else kk=1; if last.indic_ancou then do; if n_ok+1 < n_miss then pb = 1; end; run; Proc sort data=imputpage1 ; By groupage groupagecjt indic_ancou; Run; data imputpage1; set imputpage1; retain reserve; retain reserveb; if q7annee_pacs_i not in (9999,.) and q8annee_mari_i not in (9999,.) then do; reserve=q7annee_pacs_i; reserveb=q8annee_mari_i; end; if infodate="199" and (q7annee_pacs_i in (9999,.) or q8annee_mari_i in (9999,.)) then do; a=q1anai_i+18;b=0;*année majorité ego et conjoint; if q4anai_c not in (. 9999) then b=q4anai_c +18;; if q6annee_c<=reserve<=reserveb then do;*condition 1; if (b=0 and a<=reserve) or (b ne 0 and a<=reserve and b<=reserve) then do;*condition 2; q7annee_pacs_i=reserve; q8annee_mari_i=reserveb; suivi="5b"; end; end; end; drop reserve reserveb num n_miss n_ok pb kk; run; /* proc freq;table suivi;run;*/ /**********************************************************************************/ /* si encore des problemes , ultime correction*/ data imputpage1; set imputpage1; pbdate=0; *enquetes non imputés; if infodate="199" and q7annee_pacs_i in (0 . 9999) then pbdate=1; *ego trop jeune pour se pacser; if infodate="199" then do; if (q1anai_i+18) > q7annee_pacs_i then pbdate=2; end; *conjoint trop jeune pour se pacser; if infodate="199" and q4anai_c not in (. 0 9999) then do; if (q4anai_c +18) > q7annee_pacs_i then pbdate=3; end; *pacs avant mise en couple; if infodate="199" and q7annee_pacs_iq8annee_mari_i then pbdate=5; run; /* proc freq;table pbdate;run; proc print; where pbdate ne 0; var infodate q7annee_pacs_i q1anai q4anai_c q6annee_c q8annee_mari_i ;run; */ data imputpage1; set imputpage1; a=0;b=0;pb=0; if pbdate ne 0 and infodate="199" then do; *borne inférieure; if q4anai_c=. or q4anai_c<= q1anai_i then do; *ego plus jeune; if q6annee_c < 1999 then do; if q1anai_i+18 < 1999 then a=1999; else if q1anai_i+18 >= 1999 then a=q1anai_i+18; end; else if q6annee_c >= 1999 then do; if q1anai_i+18 < q6annee_c then a=q6annee_c; else if q1anai_i+18 >= q6annee_c then a=q1anai_i+18; end; end; else if q4anai_c > q1anai_i then do;* conjoint plus jeune; if q6annee_c < 1999 then do; if q4anai_c+18 < 1999 then a=1999; else if q4anai_c+18 >= 1999 then a=q4anai_c+18; end; else if q6annee_c >= 1999 then do; if q4anai_c+18 < q6annee_c then a=q6annee_c; else if q4anai_c+18 >= q6annee_c then a=q4anai_c+18; end; end; else pb=1; *borne supérieure; b=2011; *conditions; if (q4anai_c=. and q1anai_i+18>2011) or (q4anai_c ne . and (q1anai_i+18>2011 or q1anai_i+18>2011))then pb=2; if (b-a)<0 then pb=3; *imputations; if pb=0 then do; c=a + round(ranuni(7)* (b-a));*années PACS; if (b-c)>= 0 then d=c + round(ranuni(7)* (b-c));*année mariage; if c ne 0 and d ne 0 and c<=d then do; q7annee_pacs_i=c; q8annee_mari_i=d; suivi="5c" ; end; end; *controle dates imputées; if q7annee_pacs_i>2011 or q7annee_pacs_i< 1999 or q8annee_mari_i> 2011 or q8annee_mari_i < q7annee_pacs_i then do; q7annee_pacs_i=9999;q8annee_mari_i=9999; end; end; drop a b c d pb pbdate; run; /**********************************************************************************/ /*******************************************************************/ /*6*/ /*******************************************************************/ /*individus pacsés non mariés, il manque seulement l'année de mise en couple*/ Proc sort data=imputpage1 ; By q3couple_i q7annee_pacs_i groupesimput3; Run; data imputpage1; set imputpage1; By q3couple_i q7annee_pacs_i groupesimput3; retain n_ok n_miss pb; if first.groupesimput3 then do; n_ok=1; n_miss=2; end; if q6annee_c not in (9999,.) then do; num=n_ok; n_ok=n_ok+2; end; else if q6annee_c in (9999,.) then do; num=n_miss; n_miss=n_miss+2; end; else kk=1; if last.groupesimput3 then do; if n_ok+1 < n_miss then pb = 1; end; run; /* proc freq data=imputpage1; table pb; run; */ Proc sort data=imputpage1; By q3couple_i q7annee_pacs_i groupesimput3 num; run; data imputpage1; set imputpage1; retain reserve;/*retain est fait sur le vecteur: la reserve*/ /*si il y a une reponse à mise en couple on remplit la réserve*/ if q6annee_c_i not in (9999,.) then reserve=q6annee_c_i; /*si la réponse à année de mise en couple est vide on va piocher dans la réserve*/ if infodate in ("918") and q6annee_c_i in (9999,.) then do ; q6annee_c_i=reserve;suivi="6";end; drop reserve num n_miss n_ok pb kk; run; /******************************************************************/ /*6 bis */ /******************************************************************/ /* vérification imputation et correction */ data imputpage1; set imputpage1; pbdate=0; *enquetes non imputés; if infodate="918" and q6annee_c_i in (0 . 9999) then pbdate=1; *ego trop jeune pour se mettre en couple; if infodate="918" then do; if (q1anai_i+12) > q6annee_c_i then pbdate=2; end; *conjoint trop jeune pour se mettre en couple; if infodate="918" and q4anai_c not in (. 0 9999) then do; if (q4anai_c +12) > q6annee_c_i then pbdate=3; end; *pacs avant mise en couple; if infodate="918" and q7annee_pacs q6annee_c_i then pbdate=2; end; *conjoint trop jeune pour se mettre en couple; if infodate="918" and q4anai_c not in (. 0 9999) then do; if (q4anai_c +12) > q6annee_c_i then pbdate=3; end; *pacs avant mise en couple; if infodate="918" and q7annee_pacs q1anai_i then a=q4anai_c+14; else pb=1; *borne supérieure; b=q7annee_pacs; *conditions; if (q4anai_c=. and q1anai_i+18>2011) or (q4anai_c ne . and (q1anai_i+18>2011 or q1anai_i+18>2011))then pb=2; if (b-a)<0 then pb=3; *imputations; if pb=0 then do; q6annee_c_i=a + round(ranuni(7)* (b-a)); suivi="6c" ; end; else q6annee_c_i=9999; *controle dates imputées; if q6annee_c_i>q7annee_pacs then q6annee_c_i=9999; end; drop a b pb pbdate; run; /**********************************************************************************/ /*******************************************************************/ /*7*/ /*******************************************************************/ /*individus non pacsés et mariés, il manque seulement l'année de mise en couple*/ Proc sort data=imputpage1 ; By q3couple_i q8annee_mari_i groupesimput3; Run; data imputpage1; set imputpage1; By q3couple_i q8annee_mari_i groupesimput3; retain n_ok n_miss pb; if first.groupesimput3 then do; n_ok=1; n_miss=2; end; if q6annee_c not in (9999,.) then do; num=n_ok; n_ok=n_ok+2; end; else if q6annee_c in (9999,.) then do; num=n_miss; n_miss=n_miss+2; end; else kk=1; if last.groupesimput3 then do; if n_ok+1 < n_miss then pb = 1; end; run; /* proc freq data=imputpage1; table pb; run; */ Proc sort data=imputpage1; By q3couple_i q8annee_mari_i groupesimput3 num; run; data imputpage1; set imputpage1; retain reserve;/*retain est fait sur le vecteur: la reserve*/ /*si il y a une reponse à mise en couple on remplit la réserve*/ if q6annee_c_i not in (9999,.) then reserve=q6annee_c_i; /*si la réponse à année de mise en couple est vide on va piocher dans la réserve*/ if infodate in ("981") and q6annee_c_i in (9999,.) then do ; q6annee_c_i=reserve;suivi="7";end; drop reserve num n_miss n_ok pb kk; run; /******************************************************************/ /*7 bis */ /******************************************************************/ /* vérification imputation et correction */ data imputpage1; set imputpage1; pbdate=0; *enquetes non imputés; if infodate="981" and q6annee_c_i in (0 . 9999) then pbdate=1; *ego trop jeune pour se mettre en couple; if infodate="981" then do; if (q1anai_i+12) > q6annee_c_i then pbdate=2; end; *conjoint trop jeune pour se mettre en couple; if infodate="981" and q4anai_c not in (. 0 9999) then do; if (q4anai_c +12) > q6annee_c_i then pbdate=3; end; *mise en couple après mariage; if infodate="981" and q6annee_c_i>q8annee_mari then pbdate=4; if pbdate ne 0 then q6annee_c_i=9999; run; /* proc freq;table pbdate;run; proc print; where pbdate ne 0; var pbdate infodate q1anai q4anai_c q6annee_c q6annee_c_i q8annee_mari ;run; */ Proc sort data=imputpage1 ; By groupage groupagecjt indic_anmar ; Run; data imputpage1; set imputpage1; By groupage groupagecjt indic_anmar; retain n_ok n_miss pb; if first.indic_anmar then do; n_ok=1; n_miss=2; end; if q6annee_c not in (9999,.) then do; num=n_ok; n_ok=n_ok+2; end; else if q6annee_c in (9999,.) then do; num=n_miss; n_miss=n_miss+2; end; else kk=1; if last.indic_anmar then do; if n_ok+1 < n_miss then pb = 1; end; run; Proc sort data=imputpage1; By groupage groupagecjt indic_anmar num; run; data imputpage1; set imputpage1; retain reserve; if q6annee_c_i not in (9999,.) then reserve=q6annee_c_i; if infodate in ("981") and q6annee_c_i in (9999,.) then do ; a=q1anai_i+12;b=0;*année majorité ego et conjoint; if q4anai_c not in (. 9999) then b=q4anai_c +12;; if ((b=0 and a<=reserve) or (b ne 0 and a<=reserve and b<=reserve)) and reserve<=q8annee_mari then do;*condition; q6annee_c_i=reserve;suivi="7b"; end; end; drop reserve num n_miss n_ok pb kk a b; run; /* proc freq;table suivi;run;*/ /**********************************************************************************/ /* si encore des problemes , ultime correction*/ data imputpage1; set imputpage1; pbdate=0; *enquetes non imputés; if infodate="981" and q6annee_c_i in (0 . 9999) then pbdate=1; *ego trop jeune pour se mettre en couple; else if infodate="981" then do; if (q1anai_i+12) > q6annee_c_i then pbdate=2; end; *conjoint trop jeune pour se mettre en couple; else if infodate="981" and q4anai_c not in (. 0 9999) then do; if (q4anai_c +12) > q6annee_c_i then pbdate=3; end; *mise en couple après mariage; else if infodate="981" and q6annee_c_i>q8annee_mari then pbdate=4; *if pbdate ne 0 then q6annee_c_i=9999; run; /* proc freq;table pbdate;run; proc print; where pbdate ne 0; var pbdate infodate q1anai q4anai_c q6annee_c q6annee_c_i q8annee_mari ;run; */ data imputpage1; set imputpage1; a=0;b=0;pb=0; if pbdate ne 0 and infodate="981" then do; *borne inférieure; if q4anai_c=. or q4anai_c<= q1anai_i then a=q1anai_i+14; else if q4anai_c > q1anai_i then a=q4anai_c+14; else pb=1; *borne supérieure; b=q8annee_mari; *condition; if a> q8annee_mari then pb=2; *imputations; if pb=0 then do; q6annee_c_i=a + round(ranuni(7)* (b-a)); suivi="7c" ; end; else if pb=2 then do; q6annee_c_i=q8annee_mari; suivi="7c" ; end; else q6annee_c_i=9999; *controle dates imputées; if q6annee_c_i>q8annee_mari then q6annee_c_i=9999; end; drop a b pb pbdate; run; /**********************************************************************************/ /*******************************************************************/ /*8*/ /*******************************************************************/ /*individus pacsés et mariés, il manque seulement l'année de mise en couple*/ Proc sort data=imputpage1 ; By q3couple_i q7annee_pacs_i q8annee_mari_i groupesimput3; Run; data imputpage1; set imputpage1; By q3couple_i q7annee_pacs_i q8annee_mari_i groupesimput3; retain n_ok n_miss pb; if first.groupesimput3 then do; n_ok=1; n_miss=2; end; if q6annee_c not in (9999,.) then do; num=n_ok; n_ok=n_ok+2; end; else if q6annee_c in (9999,.) then do; num=n_miss; n_miss=n_miss+2; end; else kk=1; if last.groupesimput3 then do; if n_ok+1 < n_miss then pb = 1; end; run; /* proc freq data=imputpage1; table pb; run; */ Proc sort data=imputpage1; By q3couple_i q7annee_pacs_i q8annee_mari_i groupesimput3 num; run; data imputpage1; set imputpage1; retain reserve;/*retain est fait sur le vecteur: la reserve*/ /*si il y a une reponse à mise en couple on remplit la réserve*/ if q6annee_c_i not in (9999,.) then reserve=q6annee_c_i; /*si la réponse à année de mise en couple est vide on va piocher dans la réserve*/ if infodate in ("911") and q6annee_c_i in (9999,.) then do ; q6annee_c_i=reserve;suivi="8";end; drop reserve num n_miss n_ok pb kk; run; /******************************************************************/ /*8 bis */ /******************************************************************/ /* vérification imputation et correction */ data imputpage1; set imputpage1; pbdate=0; *enquetes non imputés; if infodate="911" and q6annee_c_i in (0 . 9999) then pbdate=1; *ego trop jeune pour se mettre en couple; else if infodate="911" then do; if (q1anai_i+12) > q6annee_c_i then pbdate=2; end; *conjoint trop jeune pour se mettre en couple; else if infodate="911" and q4anai_c not in (. 0 9999) then do; if (q4anai_c +12) > q6annee_c_i then pbdate=3; end; *pacs avant mise en couple; else if infodate="911" and q7annee_pacs q6annee_c_i then pbdate=2; end; *conjoint trop jeune pour se mettre en couple; else if infodate="911" and q4anai_c not in (. 0 9999) then do; if (q4anai_c +12) > q6annee_c_i then pbdate=3; end; *pacs avant mise en couple; else if infodate="911" and q7annee_pacs q1anai_i then a=q4anai_c+14; else pb=1; *borne supérieure; b=q7annee_pacs; *condition; if a> q7annee_pacs then pb=2; *imputations; if pb=0 then do; q6annee_c_i=a + round(ranuni(7)* (b-a)); suivi="8c" ; end; else q6annee_c_i=9999; *controle dates imputées; if q6annee_c_i>q7annee_pacs then q6annee_c_i=9999; end; drop a b pb pbdate; run; /**********************************************************************************/ /*******************************************************************/ /*9*/ /*******************************************************************/ /*individus non pacsés et non mariés, il manque seulement l'année de mise en couple*/ Proc sort data=imputpage1 ; By q3couple_i groupagecjt groupesimput3; Run; data imputpage1; set imputpage1; By q3couple_i groupagecjt groupesimput3; retain n_ok n_miss pb; if first.groupesimput3 then do; n_ok=1; n_miss=2; end; if q6annee_c not in (9999,.) then do; num=n_ok; n_ok=n_ok+2; end; else if q6annee_c_i in (9999) then do; num=n_miss; n_miss=n_miss+2; end; else kk=1; if last.groupesimput3 then do; if n_ok+1 < n_miss then pb = 1; end; run; /* proc freq data=imputpage1; table pb; run; */ Proc sort data=imputpage1; By q3couple_i groupagecjt groupesimput3 num; run; data imputpage1; set imputpage1; retain reserve;/*retain est fait sur le vecteur: la reserve*/ /*si il y a une reponse à mise en couple on remplit la réserve*/ if q6annee_c_i not in (9999,.) then reserve=q6annee_c_i; /*si la réponse à année de mise en couple est vide on va piocher dans la réserve*/ if infodate in ("988") and q6annee_c_i in (9999) then do ; q6annee_c_i=reserve;suivi="9";end; drop reserve num n_miss n_ok pb kk; run; /******************************************************************/ /*9 bis */ /******************************************************************/ /* vérification imputation et correction */ data imputpage1; set imputpage1; pbdate=0; *enquetes non imputés; if infodate="988" and q6annee_c_i in (0 . 9999) then pbdate=1; *ego trop jeune pour se mettre en couple; else if infodate="988" and (q1anai_i+12) > q6annee_c_i then pbdate=2; *conjoint trop jeune pour se mettre en couple; else if infodate="988" and q4anai_c not in (. 0 9999) and (q4anai_c +12) > q6annee_c_i then pbdate=3; if pbdate ne 0 then q6annee_c_i=9999; run; /* proc freq;table pbdate;run; proc print; where pbdate ne 0; var pbdate infodate q7annee_pacs q7annee_pacs_i q1anai q4anai_c q6annee_c q6annee_c_i ;run; */ Proc sort data=imputpage1 ; By groupage groupagecjt ; Run; data imputpage1; set imputpage1; By groupage groupagecjt ; retain n_ok n_miss pb; if first.groupagecjt then do; n_ok=1; n_miss=2; end; if q6annee_c not in (9999,.) then do; num=n_ok; n_ok=n_ok+2; end; else if q6annee_c_i in (9999) then do; num=n_miss; n_miss=n_miss+2; end; else kk=1; if last.groupagecjt then do; if n_ok+1 < n_miss then pb = 1; end; run; Proc sort data=imputpage1; By groupage groupagecjt num; run; data imputpage1; set imputpage1; retain reserve; if q6annee_c_i not in (9999,.) then reserve=q6annee_c_i; if infodate in ("988") and q6annee_c_i in (9999) then do ; a=q1anai_i+12;b=0; if q4anai_c not in (. 9999) then b=q4anai_c +12;; if (b=0 and a<=reserve) or (b ne 0 and a<=reserve and b<=reserve) then do;*condition; q6annee_c_i=reserve;suivi="9b"; end; end; drop reserve num n_miss n_ok pb kk a b; run; /* proc freq;table suivi;run;*/ /**********************************************************************************/ /* vérification imputation et correction */ data imputpage1; set imputpage1; pbdate=0; *enquetes non imputés; if infodate="988" and q6annee_c_i in (0 . 9999) then pbdate=1; *ego trop jeune pour se mettre en couple; else if infodate="988" and (q1anai_i+12) > q6annee_c_i then pbdate=2; *conjoint trop jeune pour se mettre en couple; else if infodate="988" and q4anai_c not in (. 0 9999) and (q4anai_c +12) > q6annee_c_i then pbdate=3; *if pbdate ne 0 then q6annee_c_i=9999; run; /* proc freq;table pbdate;run; proc print; where pbdate ne 0; var infodate q7annee_pacs_i q1anai q4anai_c q6annee_c q6annee_c_i ;run; */ data imputpage1; set imputpage1; a=0;b=0;pb=0; if pbdate ne 0 and infodate="988" then do; *borne inférieure; if q4anai_c=. or q4anai_c<= q1anai_i then a=q1anai_i+14; else if q4anai_c > q1anai_i then a=q4anai_c+14; else pb=1; *borne supérieure; b1=a+20; b2=2011; if b1 b then pb=2; *imputations; if pb=0 then do; q6annee_c_i=a + round(ranuni(7)* (b-a)); suivi="9c" ; end; else if pb=2 then q6annee_c_i=2011; end; drop a b pb ;*pbdate; run; /**********************************************************************************/ /**************************************************************************/ /*10*/ /*******************************************************************/ /*individus pacsés et mariés, il manque date de couple et de mariage*/ Proc sort data=imputpage1 ; By q3couple_i q7annee_pacs_i groupesimput3; Run; data imputpage1; set imputpage1; By q3couple_i q7annee_pacs_i groupesimput3; retain n_ok n_miss pb; if first.groupesimput3 then do; n_ok=1; n_miss=2; end; if q6annee_c not in (9999,.) and q8annee_mari not in (9999,.) then do; num=n_ok; n_ok=n_ok+2; end; else if q6annee_c in (9999,.) and q8annee_mari in (9999,.) then do; num=n_miss; n_miss=n_miss+2; end; else kk=1; if last.groupesimput3 then do; if n_ok+1 < n_miss then pb = 1; end; run; /* proc freq data=imputpage1; table pb; run; */ Proc sort data=imputpage1; By q3couple_i q7annee_pacs_i groupesimput3 num; run; data imputpage1; set imputpage1; retain reserve;/*retain est fait sur le vecteur: la reserve*/ retain reserveb;/*retain est fait sur le vecteur: la reserve*/ /*si il y a une reponse à mise en couple on remplit la réserve*/ if q6annee_c_i not in (9999,.) and q8annee_mari_i not in (9999,.) then do; reserve=q6annee_c_i; reserveb=q8annee_mari_i; end; /*si les réponses à année mise en couple et année mari sont vides on va piocher dans la réserve*/ if infodate in ("919") then do; q6annee_c_i=reserve; /*on impute*/ q8annee_mari_i=reserveb; /*on impute*/ suivi="10"; end; drop reserve reserveb num n_miss n_ok pb kk; run; /******************************************************************/ /*10 bis */ /******************************************************************/ /* vérification imputation et correction */ data imputpage1; set imputpage1; pbdate=0; *enquetes non imputés; if infodate="919" and q6annee_c_i in (0 . 9999) then pbdate=1; *ego trop jeune pour se mettre en couple; else if infodate="919" then do; if (q1anai_i+12) > q6annee_c_i then pbdate=2; end; *conjoint trop jeune pour se mettre en couple; else if infodate="919" and q4anai_c not in (. 0 9999) then do; if (q4anai_c +12) > q6annee_c_i then pbdate=3; end; *ego trop jeune pour se marier; else if infodate="919" then do; if (q1anai_i+18) > q8annee_mari_i then pbdate=4; end; *conjoint trop jeune pour se marier; else if infodate="919" and q4anai_c not in (. 0 9999) then do; if (q4anai_c +18) > q8annee_mari_i then pbdate=5; end; *mariage avant mise en couple; else if infodate="919" and q8annee_mari_i q6annee_c_i then pbdate=2; end; *conjoint trop jeune pour se mettre en couple; else if infodate="919" and q4anai_c not in (. 0 9999) then do; if (q4anai_c +12) > q6annee_c_i then pbdate=3; end; *ego trop jeune pour se marier; else if infodate="919" then do; if (q1anai_i+18) > q8annee_mari_i then pbdate=4; end; *conjoint trop jeune pour se marier; else if infodate="919" and q4anai_c not in (. 0 9999) then do; if (q4anai_c +18) > q8annee_mari_i then pbdate=5; end; *mariage avant mise en couple; else if infodate="919" and q8annee_mari_i q1anai_i then a=q4anai_c+14; else pb=1; *borne supérieure couple; b=q7annee_pacs; *condition couple; if a> q7annee_pacs then pb=2; *imputations couple; if pb=0 then do; q6annee_c_i=a + round(ranuni(7)* (b-a)); suivi="10c" ; end; else q6annee_c_i=9999; *borne inférieure mariage; c=q7annee_pacs; *borne supérieure mariage; d=2011; *condition couple; if c> d then pb=3; *imputations mariage; if pb=0 then do; q8annee_mari_i=c + round(ranuni(7)* (d-c)); suivi="10c" ; end; else q8annee_mari_i=9999; *controle dates imputées; if q6annee_c_i>q7annee_pacs or q8annee_mari_i q6annee_c_i then pbdate=2; end; *conjoint trop jeune pour se mettre en couple; if infodate="989" and q4anai_c not in (. 0 9999) then do; if (q4anai_c +12) > q6annee_c_i then pbdate=3; end; *ego trop jeune pour se marier; if infodate="989" then do; if (q1anai_i+18) > q8annee_mari_i then pbdate=4; end; *conjoint trop jeune pour se marier; if infodate="989" and q4anai_c not in (. 0 9999) then do; if (q4anai_c +18) > q8annee_mari_i then pbdate=5; end; *mariage avant mise en couple; if infodate="989" and q8annee_mari_i q6annee_c_i then pbdate=2; end; *conjoint trop jeune pour se mettre en couple; else if infodate="989" and q4anai_c not in (. 0 9999) then do; if (q4anai_c +12) > q6annee_c_i then pbdate=3; end; *ego trop jeune pour se marier; else if infodate="989" then do; if (q1anai_i+18) > q8annee_mari_i then pbdate=4; end; *conjoint trop jeune pour se marier; else if infodate="989" and q4anai_c not in (. 0 9999) then do; if (q4anai_c +18) > q8annee_mari_i then pbdate=5; end; *mariage avant mise en couple; else if infodate="989" and q8annee_mari_i q1anai_i then a=q4anai_c+14; *condition; if a >2011 then pb=1; *borne supérieure couple; if a+30<2011 then b=a+30 ;else b=2011; *imputations couple; if pb=0 then do; q6annee_c_i=a + round(ranuni(7)* (b-a)); suivi="11c" ; end; else if pb=1 then q6annee_c_i=2011; *borne inférieure mariage; if q4anai_c=. or q4anai_c< q1anai_i then c1=q1anai_i+18; else if q4anai_c > q1anai_i then c1=q4anai_c+18; c2=q6annee_c_i; if c2>=c1 then c=c2; else c=c1; *borne supérieure mariage; if c+20<2011 then d=c+20 ;else d=2011; *condition mariage; if c >2011 then pb=2; *imputations mariage; if pb=0 then do; q8annee_mari_i=c + round(ranuni(7)* (d-c)); suivi="11c" ; end; else if pb=2 then q8annee_mari_i=2011; *controle dates imputées; if q6annee_c_i>q8annee_mari_i or q8annee_mari_i>2011 or q6annee_c_i> 2011 then do; q6annee_c_i=9999;q8annee_mari_i=9999; end; end; drop a b c c1 c2 d pb pbdate; run; /*12*/ /*******************************************************************/ /*individus pacsés et mariés, il manque date couple et pacs*/ Proc sort data=imputpage1 ; By q3couple_i q8annee_mari_i groupesimput3; Run; data imputpage1; set imputpage1; By q3couple_i q8annee_mari_i groupesimput3; retain n_ok n_miss pb; if first.groupesimput3 then do; n_ok=1; n_miss=2; end; if q6annee_c not in (9999,.) and q7annee_pacs not in (9999,.) then do; num=n_ok; n_ok=n_ok+2; end; else if q6annee_c in (9999,.) and q7annee_pacs in (9999,.) then do; num=n_miss; n_miss=n_miss+2; end; else kk=1; if last.groupesimput3 then do; if n_ok+1 < n_miss then pb = 1; end; run; /* proc freq data=imputpage1; table pb; run; */ Proc sort data=imputpage1 ; By q3couple_i q8annee_mari_i groupesimput3 num; run; data imputpage1; set imputpage1; retain reserve; retain reserveb;/*retain est fait sur le vecteur: la reserve*/ /*si il y a une reponse à mari et pacs on remplit les réserves*/ if q6annee_c_i not in (9999,.) and q7annee_pacs_i not in (9999,.) then do; reserve=q6annee_c_i; reserveb=q7annee_pacs_i; end; /*si les réponses à année de mise en couple et année de pacs sont vides on va piocher dans la réserve*/ if infodate in ("991") then do q6annee_c_i=reserve; /*on impute*/ q7annee_pacs_i=reserveb; /*on impute*/ suivi="12"; end; drop reserve reserveb num n_miss n_ok pb kk; run; /******************************************************************/ /*12 bis */ /******************************************************************/ /* vérification imputation et correction */ data imputpage1; set imputpage1; pbdate=0; *enquetes non imputés; if infodate="991" and q6annee_c_i in (0 . 9999) then pbdate=1; *ego trop jeune pour se mettre en couple; else if infodate="991" then do; if (q1anai_i+12) > q6annee_c_i then pbdate=2; end; *conjoint trop jeune pour se mettre en couple; else if infodate="991" and q4anai_c not in (. 0 9999) then do; if (q4anai_c +12) > q6annee_c_i then pbdate=3; end; *ego trop jeune pour se pacser; else if infodate="991" then do; if (q1anai_i+18) > q7annee_pacs_i then pbdate=4; end; *conjoint trop jeune pour se pacser; else if infodate="991" and q4anai_c not in (. 0 9999) then do; if (q4anai_c +18) > q7annee_pacs_i then pbdate=5; end; *pacs avant mise en couple; else if infodate="991" and q7annee_pacs_iq8annee_mari then pbdate=7; *mariage après mise en couple; else if infodate="991" and q6annee_c_i>q8annee_mari then pbdate=8; if pbdate ne 0 then do; q6annee_c_i=9999;q7annee_pacs_i=9999; end; run; /* proc freq;table pbdate;run; proc print; where pbdate ne 0; var pbdate infodate q1anai q4anai_c q6annee_c_i q7annee_pacs_i q8annee_mari_i ;run; */ Proc sort data=imputpage1 ; By groupage groupagecjt indic_anmar ; Run; data imputpage1; set imputpage1; By groupage groupagecjt indic_anmar ; retain n_ok n_miss pb; if first.indic_anmar then do; n_ok=1; n_miss=2; end; if q6annee_c not in (9999,.) and q8annee_mari not in (9999,.) then do; num=n_ok; n_ok=n_ok+2; end; else if q6annee_c in (9999,.) and q8annee_mari in (9999,.) then do; num=n_miss; n_miss=n_miss+2; end; else kk=1; if last.indic_anmar then do; if n_ok+1 < n_miss then pb = 1; end; run; Proc sort data=imputpage1; By groupage groupagecjt indic_anmar num; run; data imputpage1; set imputpage1; retain reserve; retain reserveb; if q6annee_c_i not in (9999,.) and q8annee_mari_i not in (9999,.) then do; reserve=q6annee_c_i; reserveb=q7annee_pacs_i; end; if infodate in ("991") and q6annee_c_i in (9999,.) and q8annee_mari_i in (9999,.) then do; a1=q1anai_i+12;a2=q1anai_i+18; b1=0;b2=0; if q4anai_c not in (. 9999) then do; b1=q4anai_c +12; b2=q4anai_c +18; if a1<=reserve and b1<=reserve and a2<=reserveb and b2<=reserveb and reserve<=reserveb then do; q6annee_c_i=reserve; q7annee_pacs_i=reserveb; suivi="12b"; end; end; else do; if a1<=reserve and a2<=reserveb and reserve<=reserveb then do; q6annee_c_i=reserve; q8annee_mari_i=reserveb; suivi="12b"; end; end; end; drop reserve reserveb num n_miss n_ok pb kk a1 a2 b1 b2 pbdate; run; /* proc freq;table suivi;run;*/ /**********************************************************************************/ /* ultime vérification */ data imputpage1; set imputpage1; pbdate=0; *enquetes non imputés; if infodate="991" and q6annee_c_i in (0 . 9999) then pbdate=1; *ego trop jeune pour se mettre en couple; else if infodate="991" then do; if (q1anai_i+12) > q6annee_c_i then pbdate=2; end; *conjoint trop jeune pour se mettre en couple; else if infodate="991" and q4anai_c not in (. 0 9999) then do; if (q4anai_c +12) > q6annee_c_i then pbdate=3; end; *ego trop jeune pour se pacser; else if infodate="991" then do; if (q1anai_i+18) > q7annee_pacs_i then pbdate=4; end; *conjoint trop jeune pour se pacser; else if infodate="991" and q4anai_c not in (. 0 9999) then do; if (q4anai_c +18) > q7annee_pacs_i then pbdate=5; end; *pacs avant mise en couple; else if infodate="991" and q7annee_pacs_iq8annee_mari then pbdate=7; *mariage après mise en couple; else if infodate="991" and q6annee_c_i>q8annee_mari then pbdate=8; if pbdate ne 0 then do; q6annee_c_i=9999;q7annee_pacs_i=9999; end; run; /* proc freq;table pbdate;run; proc print; where pbdate ne 0; var infodate q7annee_pacs_i q1anai q4anai_c q6annee_c_i q8annee_mari_i ;run; */ data imputpage1; set imputpage1; a=0;b=0;pb=0; if pbdate ne 0 and infodate="991" then do; *borne inférieure couple; if q4anai_c=. or q4anai_c <= q1anai_i then a=q1anai_i+14; else if q4anai_c > q1anai_i then a=q4anai_c+14; *condition; if a >q8annee_mari then pb=1; *borne supérieure couple; if a+20 q1anai_i then c1=q4anai_c+18; c2=q6annee_c_i; c3=1999; if c1c3 then c=c2;else c=c3; end; else if c1>=c2 then do;*repere=18ans; if c1>c3 then c=c1; else c=c3; end; *borne supérieure pacs; d=q8annee_mari; *condition pacs; if c > d then pb=3; *imputations pacs; if pb=0 then do; q7annee_pacs_i=c + round(ranuni(7)* (d-c)); suivi="12c" ; end; else if pb=3 then q7annee_pacs_i=q8annee_mari; *controle dates imputées; if q6annee_c_i>q7annee_pacs_i or q7annee_pacs_i>q8annee_mari or q7annee_pacs_i<1999 or q6annee_c_i> 2011 then do; q6annee_c_i=9999;q7annee_pacs_i=9999; end; end; drop a b c c1 c2 c3 d pb pbdate; run; /*13*/ /*******************************************************************/ /*individus non mariés, il manque les dates de couple et de PACS*/ Proc sort data=imputpage1 ; By q3couple_i groupagecjt groupesimput3; Run; data imputpage1; set imputpage1; By q3couple_i groupagecjt groupesimput3; retain n_ok n_miss pb; if first.groupesimput3 then do; n_ok=1; n_miss=2; end; if q6annee_c not in (9999,.) and q7annee_pacs not in (9999,.) then do; num=n_ok; n_ok=n_ok+2; end; else if q6annee_c in (9999,.) and q7annee_pacs in (9999,.) then do; num=n_miss; n_miss=n_miss+2; end; else kk=1; if last.groupesimput3 then do; if n_ok+1 < n_miss then pb = 1; end; run; /* proc freq data=imputpage1; table pb; run; */ Proc sort data=imputpage1 ; By q3couple_i groupagecjt groupesimput3 num; run; data imputpage1; set imputpage1; retain reserve; retain reserveb;/*retain est fait sur le vecteur: la reserve*/ /*si il y a une reponse à mari et pacs on remplit les réserves*/ if q6annee_c_i not in (9999,.) and q7annee_pacs_i not in (9999,.) then do; reserve=q6annee_c_i; reserveb=q7annee_pacs_i; end; /*si les réponses à année de mise en couple et année de pacs sont vides on va piocher dans la réserve*/ if infodate in ("998") then do q6annee_c_i=reserve; /*on impute*/ q7annee_pacs_i=reserveb; /*on impute*/ suivi="13"; end; drop reserve reserveb num n_miss n_ok pb kk; run; /******************************************************************/ /*13 bis */ /******************************************************************/ /* vérification imputation et correction */ data imputpage1; set imputpage1; pbdate=0; *enquetes non imputés; if infodate="998" and q6annee_c_i in (0 . 9999) then pbdate=1; *ego trop jeune pour se mettre en couple; else if infodate="998" then do; if (q1anai_i+12) > q6annee_c_i then pbdate=2; end; *conjoint trop jeune pour se mettre en couple; else if infodate="998" and q4anai_c not in (. 0 9999) then do; if (q4anai_c +12) > q6annee_c_i then pbdate=3; end; *ego trop jeune pour se pacser; else if infodate="998" then do; if (q1anai_i+18) > q7annee_pacs_i then pbdate=4; end; *conjoint trop jeune pour se pacser; else if infodate="998" and q4anai_c not in (. 0 9999) then do; if (q4anai_c +18) > q7annee_pacs_i then pbdate=5; end; *pacs avant mise en couple; else if infodate="998" and q7annee_pacs_i q6annee_c_i then pbdate=2; end; *conjoint trop jeune pour se mettre en couple; else if infodate="998" and q4anai_c not in (. 0 9999) then do; if (q4anai_c +12) > q6annee_c_i then pbdate=3; end; *ego trop jeune pour se pacser; else if infodate="998" then do; if (q1anai_i+18) > q7annee_pacs_i then pbdate=4; end; *conjoint trop jeune pour se pacser; else if infodate="998" and q4anai_c not in (. 0 9999) then do; if (q4anai_c +18) > q7annee_pacs_i then pbdate=5; end; *pacs avant mise en couple; else if infodate="998" and q7annee_pacs_i q1anai_i then a=q4anai_c+14; *condition; if a >2011 then pb=1; *borne supérieure couple; if a+30<2011 then b=a+30 ;else b=2011; *imputations couple; if pb=0 then do; q6annee_c_i=a + round(ranuni(7)* (b-a)); suivi="13c" ; end; else if pb=1 then q6annee_c_i=2011; *borne inférieure pacs; if q4anai_c=. or q4anai_c< q1anai_i then c1=q1anai_i+18; else if q4anai_c > q1anai_i then c1=q4anai_c+18; c2=q6annee_c_i; c3=1999; if c1c3 then c=c2;else c=c3; end; else if c1>=c2 then do;*repere=18ans; if c1>c3 then c=c1; else c=c3; end; *borne supérieure pacs; d=2011; *condition pacs; if c >2011 then pb=2; *imputations pacs; if pb=0 then do; q7annee_pacs_i=c + round(ranuni(7)* (d-c)); suivi="13c" ; end; else if pb=2 then q7annee_pacs_i=2011; *controle dates imputées; if q6annee_c_i>q7annee_pacs_i or q7annee_pacs_i>2011 or q7annee_pacs_i<1999 or q6annee_c_i> 2011 then do; q6annee_c_i=9999;q7annee_pacs_i=9999; end; end; drop a b c c1 c2 c3 d pb pbdate; run; /*******************************************************************/ /*14*/ /*******************************************************************/ /*Puis on impute les cas où il manque l'année de mise en couple, l'année de pacs et l'année de mariage*/ Proc sort data=imputpage1 ; By q3couple_i q7annee_pacs_i q8annee_mari_i groupesimput3; Run; data imputpage1; set imputpage1; By q3couple_i q7annee_pacs_i q8annee_mari_i groupesimput3; retain n_ok n_miss pb; if first.groupesimput3 then do; n_ok=1; n_miss=2; end; if q6annee_c not in (9999,.) and q7annee_pacs not in (9999,.) and q8annee_mari not in (9999,.) then do; num=n_ok; n_ok=n_ok+2; end; else if q6annee_c in (9999,.) and q7annee_pacs in (9999,.) and q8annee_mari in (9999,.) then do; num=n_miss; n_miss=n_miss+2; end; else kk=1; if last.groupesimput3 then do; if n_ok+1 < n_miss then pb = 1; end; run; /* proc freq data=imputpage1; table pb; run; */ Proc sort data=imputpage1 ; By q3couple_i q7annee_pacs_i q8annee_mari_i groupesimput3 num; run; data imputpage1; set imputpage1; retain reserve; retain reserveb; retain reservec;/*retain est fait sur le vecteur: la reserve*/ /*si il y a une reponse à mari et pacs on remplit les réserves*/ if q6annee_c_i not in (9999,.) and q7annee_pacs_i not in (9999,.) and q8annee_mari_i not in (9999,.) then do; reserve=q6annee_c_i; reserveb=q7annee_pacs_i; reservec=q8annee_mari_i; end; /*si les réponses à année couple, année mari et année pacs sont vides, on va piocher dans la réserve*/ if infodate="999" then do q6annee_c_i=reserve; /*on impute*/ q7annee_pacs_i=reserveb;/*on impute*/ q8annee_mari_i=reservec;/*on impute*/ suivi="14"; end; drop reserve reserveb reservec num n_miss n_ok pb kk; run; /******************************************************************/ /*14 bis */ /******************************************************************/ /* vérification imputation et correction */ data imputpage1; set imputpage1; pbdate=0; *enquetes non imputés; if infodate="999" and q6annee_c_i in (0 . 9999) then pbdate=1; *ego trop jeune pour se mettre en couple; else if infodate="999" then do; if (q1anai_i+12) > q6annee_c_i then pbdate=2; end; *conjoint trop jeune pour se mettre en couple; else if infodate="999" and q4anai_c not in (. 0 9999) then do; if (q4anai_c +12) > q6annee_c_i then pbdate=3; end; *ego trop jeune pour se pacser; else if infodate="999" then do; if (q1anai_i+18) > q7annee_pacs_i then pbdate=4; end; *conjoint trop jeune pour se pacser; else if infodate="999" and q4anai_c not in (. 0 9999) then do; if (q4anai_c +18) > q7annee_pacs_i then pbdate=5; end; *ego trop jeune pour se marier; else if infodate="999" then do; if (q1anai_i+18) > q8annee_mari_i then pbdate=6; end; *conjoint trop jeune pour se marier; else if infodate="999" and q4anai_c not in (. 0 9999) then do; if (q4anai_c +18) > q8annee_mari_i then pbdate=7; end; *pacs avant mise en couple; else if infodate="999" and q7annee_pacs_iq8annee_mari_i then pbdate=9; *mariage après mise en couple; else if infodate="999" and q6annee_c_i>q8annee_mari_i then pbdate=10; if pbdate ne 0 then do; q6annee_c_i=9999;q7annee_pacs_i=9999; end; run; /* proc freq;table pbdate;run; proc print; where pbdate ne 0; var pbdate infodate q1anai q4anai_c q6annee_c_i q7annee_pacs_i q8annee_mari_i ;run; */ Proc sort data=imputpage1 ; By groupage groupagecjt ; Run; data imputpage1; set imputpage1; By groupage groupagecjt ; retain n_ok n_miss pb; if first.groupagecjt then do; n_ok=1; n_miss=2; end; if q6annee_c not in (9999,.) and q8annee_mari not in (9999,.) then do; num=n_ok; n_ok=n_ok+2; end; else if q6annee_c in (9999,.) and q8annee_mari in (9999,.) then do; num=n_miss; n_miss=n_miss+2; end; else kk=1; if last.groupagecjt then do; if n_ok+1 < n_miss then pb = 1; end; run; Proc sort data=imputpage1; By groupage groupagecjt num; run; data imputpage1; set imputpage1; retain reserve; retain reserveb; if q6annee_c_i not in (9999,.) and q7annee_pacs_i not in (9999,.) and q8annee_mari_i not in (9999,.) then do; reserve=q6annee_c_i; reserveb=q7annee_pacs_i; reservec=q8annee_mari_i; end; if infodate in ("991") and q6annee_c_i in (9999,.) and q7annee_pacs_i in (9999,.) and q8annee_mari_i in (9999,.) then do; a1=q1anai_i+12;a2=q1anai_i+18; b1=0;b2=0; if q4anai_c not in (. 9999) then do; b1=q4anai_c +12; b2=q4anai_c +18; if a1<=reserve and b1<=reserve and a2<=reserveb and b2<=reserveb and reserve<=reserveb<=reservec then do; q6annee_c_i=reserve; q7annee_pacs_i=reserveb; suivi="14b"; end; end; else do; if a1<=reserve and a2<=reserveb and reserve<=reserveb and reserve<=reserveb<=reservec then do; q6annee_c_i=reserve; q7annee_pacs_i=reserveb; q8annee_mari_i=reservec; suivi="14b"; end; end; end; drop reserve reserveb reservec num n_miss n_ok pb kk a1 a2 b1 b2 pbdate; run; /* proc freq;table suivi;run;*/ /**********************************************************************************/ /* ultime vérification */ data imputpage1; set imputpage1; pbdate=0; *enquetes non imputés; if infodate="999" and q6annee_c_i in (0 . 9999) then pbdate=1; *ego trop jeune pour se mettre en couple; else if infodate="999" then do; if (q1anai_i+12) > q6annee_c_i then pbdate=2; end; *conjoint trop jeune pour se mettre en couple; else if infodate="999" and q4anai_c not in (. 0 9999) then do; if (q4anai_c +12) > q6annee_c_i then pbdate=3; end; *ego trop jeune pour se pacser; else if infodate="999" then do; if (q1anai_i+18) > q7annee_pacs_i then pbdate=4; end; *conjoint trop jeune pour se pacser; else if infodate="999" and q4anai_c not in (. 0 9999) then do; if (q4anai_c +18) > q7annee_pacs_i then pbdate=5; end; *ego trop jeune pour se marier; else if infodate="999" then do; if (q1anai_i+18) > q8annee_mari_i then pbdate=6; end; *conjoint trop jeune pour se marier; else if infodate="999" and q4anai_c not in (. 0 9999) then do; if (q4anai_c +18) > q8annee_mari_i then pbdate=7; end; *pacs avant mise en couple; else if infodate="999" and q7annee_pacs_iq8annee_mari_i then pbdate=9; *mariage après mise en couple; else if infodate="999" and q6annee_c_i>q8annee_mari_i then pbdate=10; if pbdate ne 0 then do; q6annee_c_i=9999;q7annee_pacs_i=9999; end; run; /* proc freq;table pbdate;run; proc print; where pbdate ne 0; var infodate q7annee_pacs_i q1anai q4anai_c q6annee_c_i q8annee_mari_i ;run; */ data imputpage1; set imputpage1; a=0;b=0;pb=0; if pbdate ne 0 and infodate="999" then do; *****on impute d'abord le PACS, puis date couple et date mariage;; *borne inférieure pacs; if q4anai_c=. or q4anai_c< q1anai_i then c1=q1anai_i+18; else if q4anai_c > q1anai_i then c1=q4anai_c+18; c3=1999; if c1>c3 then c=c1; else c=c3; *borne supérieure pacs; d=2011; *condition pacs; if c > d then pb=1; *imputations pacs; if pb=0 then do; q7annee_pacs_i=c + round(ranuni(7)* (d-c)); suivi="14c" ; end; else if pb=1 then q7annee_pacs_i=2011; *****on impute ensuite la date de couple; *borne inférieure couple; if q4anai_c=. or q4anai_c <= q1anai_i then a=q1anai_i+14; else if q4anai_c > q1anai_i then a=q4anai_c+14; *condition; if a >q7annee_pacs_i then pb=2; *borne supérieure couple; if a+20 f then pb=3; *imputations pacs; if pb=0 then do; q8annee_mari_i=e + round(ranuni(7)* (f-e)); suivi="14c" ; end; else if pb=3 then q8annee_mari_i=q7annee_pacs_i; *****controle dates imputées; if q6annee_c_i>q7annee_pacs_i or q7annee_pacs_i>q8annee_mari_i or q7annee_pacs_i<1999 or q6annee_c_i> 2011 then do; q6annee_c_i=9999;q7annee_pacs_i=9999;q8annee_mari_i=9999; end; end; drop a b c c1 c3 d e f pb pbdate; run; /*******************************************************************/ /*on recrée une variable infocouple pour vérifier que les variables sont imputées*/ data imputpage1; set imputpage1; if q6annee_c_i=. then infocouple=8; else if q6annee_c_i=9999 then infocouple=9; else infocouple=1; if q7annee_pacs_i=. then infopacs=8; else if q7annee_pacs_i=9999 then infopacs=9; else if q7annee_pacs_i not in (.,9999) then infopacs=1; if q8annee_mari_i=. then infomari=8; else if q8annee_mari_i=9999 then infomari=9; else if q8annee_mari_i not in (.,9999) then infomari=1; infodateb=cats(infocouple,infopacs,infomari); run; /* proc freq data=imputpage1; table infodateb; run; proc freq data=imputpage1; table q8mari_i q7pacs_i q6annee_c_i q7annee_pacs_i q8annee_mari_i; run; proc print; where infodateb="988"; var CABEFLA infodateb q1anai q4anai_c q6annee_c q6annee_c_i q7annee_pacs q7annee_pacs_i q8annee_mari_i ;run; */ /*verif pas de pacs après mariages*/ /*proc print data=imputpage1; var q6annee_c_i q7annee_pacs_i q8annee_mari_i q6annee_c q7annee_pacs q8annee_mari q8mari q8mari_x q7pacs_x q7pacs; where q7annee_pacs_i not in (9999,.) and q7annee_pacs_i>q8annee_mari_i; run; */ /*********************** vérification ************************************* *variables imputées; proc freq data=imputpage1; table q3couple_i q6annee_c_i q7pacs_i q7annee_pacs_i q8mari_i q8annee_mari_i; run; *ordre et age des événements d'égo; data test; set imputpage1; length erreur $2; erreur="0"; if q7pacs_i="2" and q8mari_i="2" then do; if q6annee_c_i < q1anai_i + 10 then erreur="1"; end; else if q7pacs_i="1" and q8mari_i="2" then do; if q7annee_pacs_i2011 or q7annee_pacs_i<1999 then erreur="2b"; if q7annee_pacs_i2011 then erreur="3b"; if q8annee_mari_iq8annee_mari_i then erreur="4b"; if q6annee_c_i>q8annee_mari_i then erreur="4c"; end; run; proc freq;table erreur;run; * pas d'erreurs d'imputation, valeurs du FPR parfois dans un ordre étrange 0: tout est bon 2a: ordre événements renseignés étrange 3c: mariage a 10,11 et 12 ans 4a: pas d'erreur d'imputation; ****************************************************************************/ /***************************************************************************** MOIS MISE EN COUPLE *****************************************************************************/ /*Imputations des MOIS selon les années pour respecter la saisonalité , on décide de ne pas prendre la cs comme variable de tri, ce qui est important c'est l'année de l'événement*/ /* on tri par ordre decroissant car un des premiers groupes est vide*/ Proc sort data=imputpage1 ; By descending q0sexe groupage q6annee_c_i; Run; data imputpage1; set imputpage1; By descending q0sexe groupage q6annee_c_i ; retain n_ok n_miss pb; if first.q6annee_c_i then do; n_ok=1; n_miss=2; end; if q6mois_c not in (99,.) then do; num=n_ok; n_ok=n_ok+2; end; else if q6mois_c_i in (99) then do; num=n_miss; n_miss=n_miss+2; end; else kk=1; if last.q6annee_c_i then do; if n_ok+1 < n_miss then pb = 1; end; run; /* proc freq data=imputpage1; table pb; run; */ Proc sort data=imputpage1 ; By descending q0sexe groupage q6annee_c_i num; Run; data imputpage1; set imputpage1; retain reserve; /*Je choisis d'exécuter les changements de données que sur les répondants EFL, les personnes étant en couple et qui possèdent une année de mise en couple*/ if q3couple_i in ("1","2") and q6mois_c not in (99,.,88) then do; /*si le mois de couple est correct: on remplit la réserve*/ if 0 prise en compte date couple - lorsqu'il y a eu pacs => prise en compte date couple + pacs - lorsqu'il y a eu que mariage => prise en compte date couple + mariage */ data imputpage1; set imputpage1; if Q3couple in ("1" "2") then do; if q4anai_c=. then q4anai_c_i=9999;else q4anai_c_i=q4anai_c; if q4mnai_c=. then q4mnai_c_i=99;else q4mnai_c_i=q4mnai_c; end; else do;q4anai_c_i=.; q4mnai_c_i=.;end; if q4anai_c_i in (9999) then do; if q7pacs_i="2" and q8mari_i="2" then situation="1"; else if q7pacs_i="1" then situation="2"; else if q8mari_i="1" then situation="3"; end; run; /************************************************************************/ /*situation 1*/ proc sort data=imputpage1; by q0sexe groupage q6annee_c_i regroupcs; run; data imputpage1; set imputpage1; by q0sexe groupage q6annee_c_i regroupcs; retain n_ok n_miss pb; if first.regroupcs then do; n_ok=1; n_miss=2; end; if q4anai_c not in (9999) then do; num=n_ok; n_ok=n_ok+2; end; else if q4anai_c_i in (9999) and situation="1" then do; num=n_miss; n_miss=n_miss+2; end; else kk = 1 ; ** kk sert à vérifier qu'on n'a pas eu de pb (facultatif mais bien utile… ; if last.regroupcs then do; if n_ok+1 < n_miss then pb = 1; end; run; /* proc freq data=imputpage1; table pb; run; */ Proc sort data=imputpage1 ; By q0sexe groupage q6annee_c_i regroupcs num; Run; data imputpage1; set imputpage1; retain reserve; if q4anai_c not in (.,9999) then reserve=q4anai_c; if q4anai_c_i=9999 and situation="1" then q4anai_c_i=reserve; drop reserve num n_miss n_ok pb kk; run; /**********************vérification**********************************/ data imputpage1; set imputpage1; pbdate=0; *enquetes non imputés; if situation="1" and q4anai_c_i in (9999) then pbdate=1; *conjoint trop jeune pour se mettre en couple; else if situation="1" and (q4anai_c_i +12) > q6annee_c_i then pbdate=2; if situation="1" and pbdate ne 0 then q4anai_c_i=9999; run; /* proc freq;table pbdate;run; proc print; where pbdate ne 0; var infodate q1anai q4anai_c q4anai_c_i q6annee_c q6annee_c_i ;run; */ /******************* correction****************************************** */ proc sort data=imputpage1; by groupage groupagecjt indic_ancou ; run; data imputpage1; set imputpage1; by groupage groupagecjt indic_ancou ; retain n_ok n_miss pb; if first.indic_ancou then do; n_ok=1; n_miss=2; end; if q4anai_c not in (.,9999) then do; num=n_ok; n_ok=n_ok+2; end; else if q4anai_c_i in (9999) and pbdate ne 0 then do; num=n_miss; n_miss=n_miss+2; end; else kk = 1 ; if last.indic_ancou then do; if n_ok+1 < n_miss then pb = 1; end; run; Proc sort data=imputpage1 ; by groupage groupagecjt indic_ancou num; Run; data imputpage1; set imputpage1; retain reserve; if q4anai_c not in (.,9999) then reserve=q4anai_c; if pbdate ne 0 and q4anai_c_i=9999 and situation="1" then do; if q6annee_c_i > reserve +12 then q4anai_c_i=reserve; end; drop reserve num n_miss n_ok pb kk; run; /**********************vérification2**********************************/ data imputpage1; set imputpage1; pbdate=0; *enquetes non imputés; if situation="1" and q4anai_c_i in (9999) then pbdate=1; *conjoint trop jeune pour se mettre en couple; else if situation="1" and (q4anai_c_i +12) > q6annee_c_i then pbdate=2; if situation="1" and pbdate ne 0 then q4anai_c_i=9999; run; /* proc freq;table pbdate;run; proc print; where pbdate ne 0; var infodate q1anai q4anai_c q4anai_c_i q6annee_c q6annee_c_i ;run; */ /********************* ultime correction*********************************/ /* data imputpage1; set imputpage1; a=0;b=0;pb=0; if pbdate ne 0 and situation="1" then do; *borne inférieure conjoint; a=q1anai_i-10; *borne supérieure conjoint; b=q6annee_c_i-12; *imputations couple; q4anai_c_i=a + round(ranuni(7)* (b-a)); *controle dates imputées; if q4anai_c_i> 2011 or q4anai_c_i> q6annee_c_i then q4anai_c_i=9999; end; drop a b ;*pbdate; run; */ /************************************************************************/ /*situation 2*/ proc sort data=imputpage1; by q0sexe groupage q6annee_c_i regroupcs; run; data imputpage1; set imputpage1; by q0sexe groupage q6annee_c_i regroupcs; retain n_ok n_miss pb; if first.regroupcs then do; n_ok=1; n_miss=2; end; if q4anai_c not in (.,9999) then do; num=n_ok; n_ok=n_ok+2; end; else if q4anai_c_i in (9999) and situation="2" then do; num=n_miss; n_miss=n_miss+2; end; else kk = 1 ; if last.regroupcs then do; if n_ok+1 < n_miss then pb = 1; end; run; /* proc freq data=imputpage1; table pb; run; */ Proc sort data=imputpage1 ; By q0sexe groupage q6annee_c_i regroupcs num; Run; data imputpage1; set imputpage1; retain reserve; if q4anai_c not in (.,9999) then reserve=q4anai_c; if q4anai_c_i=9999 and situation="2" then q4anai_c_i=reserve; drop reserve num n_miss n_ok pb kk; run; /**********************vérification**********************************/ data imputpage1; set imputpage1; pbdate=0; *enquetes non imputés; if situation="2" and q4anai_c_i in (9999) then pbdate=1; *conjoint trop jeune pour se mettre en couple; else if situation="2" and (q4anai_c_i +12) > q6annee_c_i then pbdate=2; *conjoint trop jeune pour se pacser; else if situation="2" and (q4anai_c_i +18) > q7annee_pacs_i then pbdate=3; if pbdate ne 0 and situation="2" then q4anai_c_i=9999; run; /* proc freq;table pbdate;run; proc print; where pbdate ne 0; var infodate q7annee_pacs_i q1anai q4anai_c q6annee_c_i q8annee_mari_i ;run; */ /******************* correction****************************************** */ proc sort data=imputpage1; by groupage groupagecjt indic_ancou indic_anpacs ; run; data imputpage1; set imputpage1; by groupage groupagecjt indic_ancou indic_anpacs; retain n_ok n_miss pb; if first.indic_anpacs then do; n_ok=1; n_miss=2; end; if q4anai_c not in (.,9999) then do; num=n_ok; n_ok=n_ok+2; end; else if q4anai_c_i in (9999) and situation="2" and pbdate ne 0 then do; num=n_miss; n_miss=n_miss+2; end; else kk = 1 ; if last.indic_anpacs then do; if n_ok+1 < n_miss then pb = 1; end; run; Proc sort data=imputpage1 ; by groupage groupagecjt indic_ancou indic_anpacs num; Run; data imputpage1; set imputpage1; retain reserve; if q4anai_c not in (.,9999) then reserve=q4anai_c; if pbdate ne 0 and q4anai_c_i=9999 and situation="2" and pbdate ne 0 then do; if q6annee_c_i > reserve +12 and q7annee_pacs_i > reserve +18 then q4anai_c_i=reserve; end; drop reserve num n_miss n_ok pb kk; run; /**********************vérification2**********************************/ data imputpage1; set imputpage1; pbdate=0; *enquetes non imputés; if situation="2" and q4anai_c_i in (9999) then pbdate=1; *conjoint trop jeune pour se mettre en couple; else if situation="2" and (q4anai_c_i +12) > q6annee_c_i then pbdate=2; *conjoint trop jeune pour se pacser; else if situation="2" and (q4anai_c_i +18) > q7annee_pacs_i then pbdate=3; *if pbdate ne 0 and situation="2" then q4anai_c_i=9999; run; /* proc freq;table pbdate;run; proc print; where pbdate ne 0; var infodate q7annee_pacs_i q1anai q4anai_c q6annee_c_i q8annee_mari_i ;run; */ /************************ ultime correction******************************/ /* data imputpage1; set imputpage1; a=0;b=0;pb=0; if pbdate ne 0 and situation="1" then do; *borne inférieure conjoint; a=q1anai_i-10; *borne supérieure conjoint; b=q7annee_pacs_i; *imputations couple; q4anai_c_i=a + round(ranuni(7)* (b-a)); *controle dates imputées; if q4anai_c_i> 2011 or q4anai_c_i> q6annee_c_i or q4anai_c_i>q7annee_pacs_i then q4anai_c_i=9999; end; drop a b ;*pbdate; run; */ /************************************************************************/ /*situation 3*/ proc sort data=imputpage1; by q0sexe groupage q6annee_c_i regroupcs; run; data imputpage1; set imputpage1; by q0sexe groupage q6annee_c_i regroupcs; retain n_ok n_miss pb; if first.regroupcs then do; n_ok=1; n_miss=2; end; if q4anai_c not in (.,9999) then do; num=n_ok; n_ok=n_ok+2; end; else if q4anai_c in (.,9999) and situation="3" and pbdate ne 0 then do; num=n_miss; n_miss=n_miss+2; end; else kk = 1 ; if last.regroupcs then do; if n_ok+1 < n_miss then pb = 1; end; run; Proc sort data=imputpage1 ; By q0sexe groupage q6annee_c_i regroupcs num; Run; data imputpage1; set imputpage1; retain reserve; if q4anai_c not in (.,9999) then reserve=q4anai_c; if q4anai_c_i=9999 and situation="3" and pbdate ne 0 then q4anai_c_i=reserve; drop reserve num n_miss n_ok pb kk; run; /**********************vérification**********************************/ data imputpage1; set imputpage1; pbdate=0; *enquetes non imputés; if situation="3" and q4anai_c_i in (0 . 9999) then pbdate=1; *conjoint trop jeune pour se mettre en couple; else if situation="3" and (q4anai_c_i +12) > q6annee_c_i then pbdate=2; *conjoint trop jeune pour se marier; else if situation="3" and (q4anai_c_i +18) > q8annee_mari_i then pbdate=3; if situation="3" and pbdate ne 0 then q4anai_c_i=9999; run; /* proc freq;table pbdate;run; proc print; where pbdate ne 0; var infodate q7annee_pacs_i q1anai q6annee_c q6annee_c_i q8annee_mari q8annee_mari_i ;run; */ /******************* correction****************************************** */ proc sort data=imputpage1; by groupage groupagecjt indic_ancou ; run; data imputpage1; set imputpage1; by groupage groupagecjt indic_ancou ; retain n_ok n_miss pb; if first.indic_ancou then do; n_ok=1; n_miss=2; end; if q4anai_c not in (.,9999) then do; num=n_ok; n_ok=n_ok+2; end; else if q4anai_c_i in (9999) and situation="3" and pbate ne 0 then do; num=n_miss; n_miss=n_miss+2; end; else kk = 1 ; if last.indic_ancou then do; if n_ok+1 < n_miss then pb = 1; end; run; Proc sort data=imputpage1 ; by groupage groupagecjt indic_ancou num; Run; data imputpage1; set imputpage1; retain reserve; if q4anai_c not in (.,9999) then reserve=q4anai_c; if pbdate ne 0 and q4anai_c_i=9999 and situation="3" then do; if q6annee_c_i > reserve +12 and q8annee_mari_i > reserve +18 then q4anai_c_i=reserve; end; drop reserve num n_miss n_ok pb kk; run; /**********************vérification 2**********************************/ data imputpage1; set imputpage1; pbdate=0; *enquetes non imputés; if situation="3" and q4anai_c_i in (0 . 9999) then pbdate=1; *conjoint trop jeune pour se mettre en couple; else if situation="3" and (q4anai_c_i +12) > q6annee_c_i then pbdate=2; *conjoint trop jeune pour se marier; else if situation="3" and (q4anai_c_i +18) > q8annee_mari_i then pbdate=3; *if situation="3" and pbdate ne 0 then q4anai_c_i=9999; run; /* proc freq;table pbdate;run; proc print; where pbdate ne 0; var infodate groupage groupagecjt q7annee_pacs_i q1anai q4anai_c_i q6annee_c q6annee_c_i q8annee_mari q8annee_mari_i ;run; */ /************************ ultime correction******************************/ data imputpage1; set imputpage1; a=0;b=0;pb=0; if pbdate ne 0 and situation="3" then do; *borne supérieure conjoint; a1=q6annee_c_i-12; a2=q8annee_mari-18; if a1 2011 or q4anai_c_i +12 > q6annee_c_i or q4anai_c_i +18 > q8annee_mari then q4anai_c_i=9999; end; drop a1 a2 a b1 b2 b pbdate; run; /****************************************************************************** question 4 date de naissance du cjt ( mois) ******************************************************************************/ /*mois de naissance*/ proc sort data=imputpage1; by q4anai_c_i; run; data imputpage1; set imputpage1; by q4anai_c_i; retain n_ok n_miss pb; if first.q4anai_c_i then do; n_ok=1; n_miss=2; end; if q4mnai_c not in (.,99) then do; num=n_ok; n_ok=n_ok+2; end; else if q4mnai_c in (.,99) then do; num=n_miss; n_miss=n_miss+2; end; else kk = 1 ; ** kk sert à vérifier qu'on n'a pas eu de pb (facultatif mais bien utile… ; if last.q4anai_c_i then do; if n_ok+1 < n_miss then pb = 1; end; run; /* proc freq data=imputpage1; table pb; run; */ Proc sort data=imputpage1 ; By q4anai_c_i num; Run; data imputpage1; set imputpage1; q4mnai_c_i=q4mnai_c; /*on crée une variable qui a les mêmes valeurs que la seconde*/ retain reserve;/*retain est fait sur le vecteur: la reserve*/ /*si il y a une reponse au mois de naissance du cjt on remplit la réserve*/ if q4mnai_c not in (.,99) then reserve=q4mnai_c; /*si la réponse à q4mnai_c est vide, on va piocher dans la réserve*/ if q4mnai_c=99 then q4mnai_c_i=reserve; drop reserve num n_miss n_ok pb kk; run; /* proc freq data=imputpage1; table q3couple_i q4anai_c_i q4mnai_c_i; run; */ /*****************************************************************************************/ /*****************************************************************************************/ /*****************************************************************************************/ /*****************************************************************************************/ /*****************************************************************************************/ /* creation base imputpage1*/ data imputpage1_c; set imputpage1; keep CABEFLA q6annee_c_i q6mois_c_i q7pacs_i q7annee_pacs_i q7mois_pacs_i q8mari_i q8annee_mari_i q8mois_mari_i q4anai_c_i q4mnai_c_i groupagecjt indic_ancou indic_anmar indic_anpacs; proc sort; by CABEFLA; proc delete data=imputpage1; run; data imputpage1transit; set imput.imputpage1transit;drop q7pacs_i q8mari_i; proc sort ;by CABEFLA; data imputpage1; merge imputpage1transit imputpage1_c; by CABEFLA; proc delete data=imput.imputpage1transit imputpage1_c imputpage1transit; run; /*****************************************************************************************/ /*****************************************************************************************/ /*****************************************************************************************/ /******************** verification ********************************* proc freq; table q6annee_c_i q6mois_c_i q7pacs_i q7annee_pacs_i q7mois_pacs_i q8mari_i q8annee_mari_i q8mois_mari_i q4anai_c_i q4mnai_c_i ; run; ******************** verification *********************************/ /***************************************************************************** question 9 tps passé par le conjoint dans le logement ******************************************************************************/ proc sort data=imputpage1; by q0sexe q3couple_i matr q31lgt_sec_fam regroupcs groupage; run; data imputpage1; set imputpage1; by q0sexe q3couple_i matr q31lgt_sec_fam regroupcs groupage; retain n_ok n_miss pb; if first.groupage then do; n_ok=1; n_miss=2; end; if q9tps_logr not in ("Z"," ") then do; num=n_ok; n_ok=n_ok+2; end; else if q9tps_logr in ("Z"," ") then do; num=n_miss; n_miss=n_miss+2; end; else kk = 1 ; ** kk sert à vérifier qu'on n'a pas eu de pb (facultatif mais bien utile… ; if last.groupage then do; if n_ok+1 < n_miss then pb = 1; end; run; /* proc freq data=imputpage1; table pb; run; */ Proc sort data=imputpage1 ; By q0sexe q3couple_i matr q31lgt_sec_fam regroupcs groupage num; Run; data imputpage1; set imputpage1; q9tps_logr_i=q9tps_logr; /*on crée une variable qui a les mêmes valeurs que la seconde*/ retain reserve;/*retain est fait sur le vecteur: la reserve*/ /*si il y a une reponse à q9tps_logr on remplit la réserve*/ if q9tps_logr not in ("Z"," ") then reserve=q9tps_logr; /*si la réponse à q9tps_logr est vide, on va piocher dans la réserve*/ if q9tps_logr in ("Z") then q9tps_logr_i=reserve; drop reserve num n_miss n_ok pb kk; run; /***************************************************************************** question 10 cause de rupture d'union, (on travaille deja sur q10cause_r_i) ******************************************************************************/ proc sort data=imputpage1; by groupesimput3; run; data imputpage1; set imputpage1; by groupesimput3; retain n_ok n_miss pb 0; if first.groupesimput3 then do; n_ok=1; n_miss=2; end; if q10cause_r not in ("Z"," ") then do; num=n_ok; n_ok=n_ok+2; end; else if q10cause_r in ("Z"," ") then do; num=n_miss; n_miss=n_miss+2; end; else kk = 1 ; ** kk sert à vérifier qu'on n'a pas eu de pb (facultatif mais bien utile… ; if last.groupesimput3 then do; if n_ok+1 < n_miss then pb = 1; end; run; /* proc freq data=imputpage1; table pb; run; */ Proc sort data=imputpage1 ; By groupesimput3 num; Run; data imputpage1; set imputpage1; retain reserve;/*retain est fait sur le vecteur: la reserve*/ /*si il y a une reponse à la cause de rupture d'union on remplit la réserve*/ if q10cause_r not in ("Z"," ") then reserve=q10cause_r; /*si la réponse à cause_r est vide, on va piocher dans la réserve*/ if q10cause_r_i in ("Z") then q10cause_r_i=reserve; drop reserve num n_miss n_ok pb kk; run; /* proc freq data=imputpage1; table q10cause_r_i; run; */ /***************************************************************************** Q10 années de séparation ou de décès du conjoint *****************************************************************************/ data imputpage1; set imputpage1; /*on rectifie les nr et nc selon cause_r imputée*/ if q10cause_r_i="1" and q10cause_r="Z" then do; q10annee_s_i=9999; q10annee_d_i=.; end; if q10cause_r_i="2" and q10cause_r="Z" then do; q10annee_s_i=.; q10annee_d_i=9999; end; run; /* on impute q10annee_s_i*/ proc sort data=imputpage1; by groupesimput3; run; data imputpage1; set imputpage1; by groupesimput3; retain n_ok n_miss pb; if first.groupesimput3 then do; n_ok=1; n_miss=2; end; if q10annee_s_i not in (9999,.) then do; num=n_ok; n_ok=n_ok+2; end; else if q10annee_s_i in (9999,.) then do; num=n_miss; n_miss=n_miss+2; end; else kk = 1 ; ** kk sert à vérifier qu'on n'a pas eu de pb (facultatif mais bien utile… ; if last.groupesimput3 then do; if n_ok+1 < n_miss then pb = 1; end; run; /* proc freq data=imputpage1; table pb; run; */ Proc sort data=imputpage1 ; By groupesimput3 num; Run; data imputpage1; set imputpage1; retain reserve;/*retain est fait sur le vecteur: la reserve*/ /*si il y a une reponse à année de séparation on remplit la réserve*/ if q10annee_s_i not in (9999,.) then reserve=q10annee_s_i; /*si la réponse à année de séparation est vide, on va piocher dans la réserve*/ if q10annee_s_i=9999 then q10annee_s_i=reserve; drop reserve num n_miss n_ok pb kk; run; /*on impute q10cause_r_i*/ proc sort data=imputpage1; by descending groupesimput3; run; data imputpage1;set imputpage1; if q10cause_r_i="2" and q10annee_d in (9999 .) then q10annee_d_i=9999; data imputpage1; set imputpage1; by descending groupesimput3; retain n_ok n_miss pb; if first.groupesimput3 then do; n_ok=1; n_miss=2; end; if q10annee_d_i not in (9999,.) then do; num=n_ok; n_ok=n_ok+2; end; else if q10annee_d_i in (9999,.) then do; num=n_miss; n_miss=n_miss+2; end; else kk = 1 ; if last.groupesimput3 then do; if n_ok+1 < n_miss then pb = 1; end; run; Proc sort data=imputpage1 ; By descending groupesimput3 num; Run; data imputpage1; set imputpage1; suivi=0; retain reserve;/*retain est fait sur le vecteur: la reserve*/ /*si il y a une reponse à l'année de décès on remplit la réserve*/ if q10annee_d_i not in (9999,.) then reserve=q10annee_d_i; /*si la réponse à année de décès est vide, on va piocher dans la réserve*/ if q10cause_r_i="2" and q10annee_d_i in (9999) then do ;q10annee_d_i=reserve;suivi=1;end; drop reserve num n_miss n_ok pb kk; run; /* proc freq; table q10cause_r_i q10annee_d_i; run; */ /******************* verification ******************************* proc freq; table q10cause_r_i q10annee_s_i q10annee_d_i q9tps_logr_i; run; ******************* verification *******************************/ /* on copie en dur la base imputpage1*/ data imput.imputpage1; set imputpage1; proc delete data=imputpage1; run; /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /*** ***/ /*** imputations page 2 ***/ /*** ***/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /* on travaille sur la work on supprime les variables temporaires inutiles*/ data imputpage2;set imput.imputpage1;drop suivi nbg4; data imputenfant;set imput.imputenfant; run; /********************************************************************* Q11 : égo a t'il des enfants *************************************************************************/ proc sort data=imputpage2; by cabefla; run; /*on crée les variables _i*/ data imputpage2; set imputpage2; q11enfan_i=q11enfan; q11nb_enf_i=q11nb_enf; q11nb_enf_lgt_i=q11nb_enf_lgt; q12enfan_c_i=q12enfan_c; q12nb_enf_c_i=q12nb_enf_c; q12nb_enf_lgt_c_i=q12nb_enf_lgt_c; /*on crée des variables indicatrices pour savoir comment sont remplies les questions sur les parents puis on impute les questions 11 et 12*/ if q15reg="ZZ" and q16nat_m="Z" and q17cs_m="ZZ" and q18statut_m="ZZ" and q19viv_m="Z" and q20res_lgt_m="Z" and q20res_aut_m="ZZ" and q21reg="ZZ" and q22nat_p="Z" and q23cs_p="ZZ" and q24statut_p="ZZ" and q25viv_p="Z" and q26res_lgt_p="Z" and q26res_aut_p="ZZ" then infoparents=2; else infoparents=1; /*s'il n'y a pas de petits enfants et qu'il y a des réponses sur les parents on met q11enfan=2 et q12enfan=2*/ if infoparents=1 and q27grp in ("Z","2") and q11enfan="Z" then do; q11enfan_i="2"; q11nb_enf_i=0; q11nb_enf_lgt_i=0; end; if infoparents=1 and q27grp in ("Z","2") and q12enfan_c="Z" then do; q12enfan_c_i="2"; q12nb_enf_c_i=0; q12nb_enf_lgt_c_i=0; end; run; /***************************************************************/ /*enfants de ego et du cjt quand il y a des petits enfants*/ Proc sort data=imputpage2 ; By q0sexe q3couple_i naiss groupage regroupcs; Run; data imputpage2; set imputpage2; By q0sexe q3couple_i naiss groupage regroupcs; retain n_ok n_miss pb; if first.regroupcs then do; n_ok=1; n_miss=2; end; if q11enfan not in ("Z") and infoparents=1 and q27grp in ("1") then do; num=n_ok; n_ok=n_ok+2; end; else if q11enfan in ("Z") and infoparents=2 and q27grp not in ("1") then do; num=n_miss; n_miss=n_miss+2; end; else kk = 1 ; if last.regroupcs then do; if n_ok+1 < n_miss then pb = 1; end; run; Proc sort data=imputpage2 ; By q0sexe q3couple_i naiss groupage regroupcs num;/*on ajoute num pour eviter les effets de bord*/ Run; data imputpage2; set imputpage2; retain reserve; /*si il y a une reponse à q11enfan on remplit la réserve*/ if q11enfan not in ("Z") then reserve=q11enfan; /*si la réponse à q11enfan est vide, on va piocher dans la réserve*/ if q11enfan_i in ("Z") and infoparents=1 and q27grp in ("1") then q11enfan_i=reserve; /*on impute les nr quand il y a des petits enfants*/ drop reserve num n_miss n_ok pb kk; run; /***************************************************************/ /*enfant du cjt*/ Proc sort data=imputpage2 ; By q0sexe q3couple_i naiss groupage regroupcs; Run; data imputpage2; set imputpage2; By q0sexe q3couple_i naiss groupage regroupcs; retain n_ok n_miss pb; if first.regroupcs then do; n_ok=1; n_miss=2; end; if q12enfan_c not in (" ","Z") and infoparents=1 and q27grp in ("1") then do; num=n_ok; n_ok=n_ok+2; end; else if q12enfan_c in (" ","Z") and infoparents=2 and q27grp not in ("1") then do; num=n_miss; n_miss=n_miss+2; end; else kk = 1 ; if last.regroupcs then do; if n_ok+1 < n_miss then pb = 1; end; run; Proc sort data=imputpage2 ; By q0sexe q3couple_i naiss groupage regroupcs num;/*on ajoute num pour eviter les effets de bord*/ Run; data imputpage2; set imputpage2; retain reserve;/*retain est fait sur le vecteur: la reserve*/ /*si il y a une reponse à q11enfan on remplit la réserve*/ if q12enfan_c not in (" ","Z") then reserve=q12enfan_c; /*si la réponse à q12enfan_c est vide, on va piocher dans la réserve*/ if q12enfan_c_i in ("Z") and infoparents=1 and q27grp in ("1") then q12enfan_c_i=reserve; /*on impute les nr*/ drop reserve num n_miss n_ok pb kk; run; /***************************************************************/ /*quand il n'y a rien sur les parents et vide à grp*/ /*enfants de ego et du cjt quand il n'y a pas de petits enfants*/ Proc sort data=imputpage2 ; By q0sexe q3couple_i naiss groupage regroupcs; Run; data imputpage2; set imputpage2; By q0sexe q3couple_i naiss groupage regroupcs; retain n_ok n_miss pb; if first.regroupcs then do; n_ok=1; n_miss=2; end; if q11enfan not in ("Z"," ") and infoparents=2 then do; num=n_ok; n_ok=n_ok+2; end; else if q11enfan in ("Z"," ") and infoparents not in (2) then do; num=n_miss; n_miss=n_miss+2; end; else kk = 1 ; if last.regroupcs then do; if n_ok+1 < n_miss then pb = 1; end; run; Proc sort data=imputpage2 ; By q0sexe q3couple_i naiss groupage regroupcs num;/*on ajoute num pour eviter les effets de bord*/ Run; data imputpage2; set imputpage2; retain reserve;/*retain est fait sur le vecteur: la reserve*/ /*si il y a une reponse à q11enfan on remplit la réserve*/ if q11enfan not in ("Z"," ") then reserve=q11enfan; /*si la réponse à q11enfan est vide, on va piocher dans la réserve*/ if q11enfan_i in ("Z") and infoparents=2 then q11enfan_i=reserve; /*on impute les nr quand il y a des petits enfants*/ drop reserve num n_miss n_ok pb kk; run; /***************************************************************/ /*quand la partie sur les parents est renseignée*/ Proc sort data=imputpage2 ; By q0sexe q3couple_i naiss groupage regroupcs; Run; data imputpage2; set imputpage2; By q0sexe q3couple_i naiss groupage regroupcs; retain n_ok n_miss pb; if first.regroupcs then do; n_ok=1; n_miss=2; end; if q11enfan not in ("Z"," ") and infoparents=1 then do; num=n_ok; n_ok=n_ok+2; end; else if q11enfan in ("Z"," ") and infoparents not in (1) then do; num=n_miss; n_miss=n_miss+2; end; else kk = 1 ; if last.regroupcs then do; if n_ok+1 < n_miss then pb = 1; end; run; Proc sort data=imputpage2 ; By q0sexe q3couple_i naiss groupage regroupcs num;/*on ajoute num pour eviter les effets de bord*/ Run; data imputpage2; set imputpage2; retain reserve;/*retain est fait sur le vecteur: la reserve*/ /*si il y a une reponse à q11enfan on remplit la réserve*/ if q11enfan not in ("Z") then reserve=q11enfan; /*si la réponse à q11enfan est vide, on va piocher dans la réserve*/ if q11enfan_i in ("Z") and infoparents=1 then q11enfan_i=reserve; /*on impute les nr quand il y a des petits enfants*/ drop reserve num n_miss n_ok pb kk; run; /* proc freq data=imputpage2; table q11enfan*q11enfan_i; run; */ /*************************************************************** Q12: le conjoint a t'il des enfants ********************************************************************/ /*enfant du cjt*/ Proc sort data=imputpage2 ; By q0sexe q3couple_i naiss groupage regroupcs; Run; data imputpage2; set imputpage2; By q0sexe q3couple_i naiss groupage regroupcs; retain n_ok n_miss pb; if first.regroupcs then do; n_ok=1; n_miss=2; end; if q12enfan_c not in (" ","Z") and infoparents=2 then do; num=n_ok; n_ok=n_ok+2; end; else if q12enfan_c in (" ","Z") and infoparents not in (2) then do; num=n_miss; n_miss=n_miss+2; end; else kk = 1 ; if last.regroupcs then do; if n_ok+1 < n_miss then pb = 1; end; run; Proc sort data=imputpage2 ; By q0sexe q3couple_i naiss groupage regroupcs num;/*on ajoute num pour eviter les effets de bord*/ Run; data imputpage2; set imputpage2; retain reserve;/*retain est fait sur le vecteur: la reserve*/ /*si il y a une reponse à q11enfan on remplit la réserve*/ if q12enfan_c not in (" ","Z") then reserve=q12enfan_c; /*si la réponse à q12enfan_c est vide, on va piocher dans la réserve*/ if q12enfan_c_i in ("Z") and infoparents=2 then q12enfan_c_i=reserve; /*on impute les nr*/ drop reserve num n_miss n_ok pb kk; run; /***************************************************************/ /*enfant du cjt quand la partie sur les parents est renseignée*/ Proc sort data=imputpage2 ; By q0sexe q3couple_i naiss groupage regroupcs; Run; data imputpage2; set imputpage2; By q0sexe q3couple_i naiss groupage regroupcs; retain n_ok n_miss pb; if first.regroupcs then do; n_ok=1; n_miss=2; end; if q12enfan_c not in (" ","Z") and infoparents=1 then do; num=n_ok; n_ok=n_ok+2; end; else if q12enfan_c in (" ","Z") and infoparents not in (1) then do; num=n_miss; n_miss=n_miss+2; end; else kk = 1 ; if last.regroupcs then do; if n_ok+1 < n_miss then pb = 1; end; run; Proc sort data=imputpage2 ; By q0sexe q3couple_i naiss groupage regroupcs num;/*on ajoute num pour eviter les effets de bord*/ Run; data imputpage2; set imputpage2; retain reserve;/*retain est fait sur le vecteur: la reserve*/ /*si il y a une reponse à q11enfan on remplit la réserve*/ if q12enfan_c not in (" ","Z") then reserve=q12enfan_c; /*si la réponse à q12enfan_c est vide, on va piocher dans la réserve*/ if q12enfan_c_i in ("Z") and infoparents=1 then q12enfan_c_i=reserve; /*on impute les nr*/ drop reserve num n_miss n_ok pb kk; run; /* proc freq data=imputpage2; table q11enfan_i q12enfan_c_i; run;*ok; proc freq data=imputpage2; table q12enfan_c_i; where q12enfan_c="Z"; run;*ok; */ /*************************************************************** Q11 et Q12 : nombre d'enfants ****************************************************************/ /*A partir de q11enfan_i et q12enfan_c_i*/ /*On crée les variables nombre d'enfant à partir des q11 et q12 imputées*/ data imputpage2; set imputpage2; if q11enfan_i="1" then do; if q11nb_enf not in (0) then do; q11nb_enf_i=q11nb_enf; q11nb_enf_lgt_i=q11nb_enf_lgt; end; if q11nb_enf in (0) then do; q11nb_enf_i=.; q11nb_enf_lgt_i=.; end; end; if q11enfan_i="2" then do; q11nb_enf_i=0; q11nb_enf_lgt_i=0; end; if q12enfan_c_i=" " then do; q12nb_enf_c_i=.; q12nb_enf_lgt_c_i=.; end; if q12enfan_c_i="1" then do; if q12nb_enf_c not in (0) then do; q12nb_enf_c_i=q12nb_enf_c; q12nb_enf_lgt_c_i=q12nb_enf_lgt_c; end; if q12nb_enf_c in (0) then do; q12nb_enf_c_i=.; q12nb_enf_lgt_c_i=.; end; end; if q12enfan_c_i="2" then do; q12nb_enf_c_i=0; q12nb_enf_lgt_c_i=0; end; run; /*si on a imputé des enfants à partir de la variable grands parents c'est dans le tableau 14, on met donc la variable q11nb_enf_lgt à 0 et q12nb_enf_lgt à 0. on n'impute pas d'enfants dans le logement*/ data imputpage2; set imputpage2; if q27grp in ("1") then do; if q11enfan in ("Z") and q11enfan_i="1" then q11nb_enf_lgt_i=0; if q12enfan_c in ("Z") and q12enfan_c_i="1" then q12nb_enf_lgt_c_i=0; end; run; /****************************************************************/ /*nombre d'enfant de ego*/ Proc sort data=imputpage2 ; By q0sexe q3couple_i naiss groupage regroupcs; Run; data imputpage2; set imputpage2; By q0sexe q3couple_i naiss groupage regroupcs; retain n_ok n_miss pb; if first.regroupcs then do; n_ok=1; n_miss=2; end; if q11nb_enf_i not in (.,0) then do; num=n_ok; n_ok=n_ok+2; end; else if q11nb_enf_i in (.,0) then do; num=n_miss; n_miss=n_miss+2; end; else kk = 1 ; if last.regroupcs then do; if n_ok+1 < n_miss then pb = 1; end; run; Proc sort data=imputpage2 ; By q0sexe q3couple_i naiss groupage regroupcs num;/*on ajoute num pour eviter les effets de bord*/ Run; data imputpage2; set imputpage2; retain reserve reserveb;/*retain est fait sur le vecteur: la reserve*/ /*si il y a une reponse à q11nb_enf on remplit la réserve*/ if q11nb_enf_i not in (.,0) and q11nb_enf_lgt_i not in (.) and q11nb_enf_i<=6 and q11nb_enf_lgt_i<=4 then do; reserve=q11nb_enf_i; reserveb=q11nb_enf_lgt_i; end; /*si la réponse est vide, on va piocher dans la réserve*/ if q11nb_enf_i=. then q11nb_enf_i=reserve; if q11nb_enf_lgt_i=. then q11nb_enf_lgt_i=reserveb; drop reserve reserveb num n_miss n_ok pb kk; run; /****************************************************************/ /*nombre d'enfant du cjt*/ Proc sort data=imputpage2 ; By q0sexe q3couple_i naiss groupage regroupcs; Run; data imputpage2; set imputpage2; By q0sexe q3couple_i naiss groupage regroupcs; retain n_ok n_miss pb; if first.regroupcs then do; n_ok=1; n_miss=2; end; if Q12nb_enf_c_i not in (.,0) then do; num=n_ok; n_ok=n_ok+2; end; else if Q12nb_enf_c_i in (.,0) then do; num=n_miss; n_miss=n_miss+2; end; else kk = 1 ; if last.regroupcs then do; if n_ok+1 < n_miss then pb = 1; end; run; Proc sort data=imputpage2 ; By q0sexe q3couple_i naiss groupage regroupcs num;/*on ajoute num pour eviter les effets de bord*/ Run; data imputpage2; set imputpage2; retain reserve reserveb;/*retain est fait sur le vecteur: la reserve*/ /*si il y a une reponse à Q12nb_enf on remplit la réserve*/ if Q12nb_enf_c_i not in (.,0) and Q12nb_enf_lgt_c_i not in (.) and Q12nb_enf_c_i<=6 and Q12nb_enf_lgt_c_i<=3 then do; reserve=Q12nb_enf_c_i; reserveb=Q12nb_enf_lgt_c_i; end; /*si la réponse est vide, on va piocher dans la réserve*/ if q12enfan_c_i="1" and Q12nb_enf_c_i=. then Q12nb_enf_c_i=reserve; if q12enfan_c_i="1" and Q12nb_enf_lgt_c_i=. then Q12nb_enf_lgt_c_i=reserveb; drop reserve reserveb num n_miss n_ok pb kk; run; /* proc freq data=imputpage2; table q11nb_enf_i q11nb_enf_lgt_i q12nb_enf_c_i q12nb_enf_lgt_c_i; run;*OK; proc freq data=imputpage2; table q12nb_enf_lgt_c*q12nb_enf_lgt_c_i; run;*OK; proc print data=imputpage2 (obs=10); var q12enfan_c q12enfan_c_i q12nb_enf_c q12nb_enf_lgt_c q12nb_enf_c_i i_q12enfan_c; where q12nb_enf_lgt_c not in (0) and q12nb_enf_lgt_c_i=0; run; */ /****************************************************************/ data imputpage2; set imputpage2; /*on modifie les "2" en nc quand ego n'est pas en couple*/ if q12enfan_c_i="2" and q3couple_i in ("3","4") then do; q12enfan_c_i=" "; q12nb_enf_c_i=.; q12nb_enf_lgt_c_i=.; end; if q12enfan_c_i="2" and q12enfan_c="1" and i_q12enfan_c in (0,1) and q12nb_enf_c>=1 and q12nb_enf_lgt_c>=1 then do; q12enfan_c_i="1"; q12nb_enf_c_i=q12nb_enf_c; q12nb_enf_lgt_c_i=q12nb_enf_lgt_c; end; run; /*************************************************************** ajout des enfants imputés dans la base ****************************************************************/ /*il faut ajouter les lignes dans la base enfants à partir des nombres d'enfant dans le logement et hors logement*/ data imputpage2; set imputpage2; if ((q11enfan_i ne q11enfan) and q11enfan_i="1") or ((q12enfan_c_i ne q12enfan_c) and q12enfan_c_i="1") then imputenf=1; else imputenf=2; if (q11enfan="Z" and q11enfan_i="1") and (q11nb_enf_i ne q11nb_enf) and q11nb_enf_i not in (0) then imputenfego=1; else imputenfego=2; if (q12enfan_c="Z" and q12enfan_c_i="1") and (q12nb_enf_c_i ne q12nb_enf_c) and q12nb_enf_c_i not in (0) then imputenfcjt=1; else cjt=2; if (q11enfan="Z" and q11enfan_i="1") and (q11nb_enf_lgt_i ne q11nb_enf_lgt) and q11nb_enf_lgt_i not in (0) then imputenfegolgt=1; else imputenfegolgt=2; if (q12enfan_c="Z" and q12enfan_c_i="1") and (q12nb_enf_lgt_c_i ne q12nb_enf_lgt_c) and q12nb_enf_lgt_c_i not in (0) then imputenfcjtlgt=1; else imputenfcjtlgt=2; run; /* proc freq data=imputpage2; table imputenf imputenfego imputenfcjt imputenfegolgt imputenfcjtlgt; run; */ data ajoutenfapresimput; set imputpage2; if imputenf=2 then delete; keep cabefla q11enfan_i q11nb_enf_i q11nb_enf_lgt_i q12enfan_c_i q12nb_enf_c_i q12nb_enf_lgt_c_i imputenf q11enfan q12enfan_c; run; /* proc freq data=ajoutenfapresimput; table q11nb_enf_i q11nb_enf_lgt_i q12nb_enf_c_i q12nb_enf_lgt_c_i; run; */ /*enfants de ego dans le logement*/ data ajoutenfapresimputlogego1; set ajoutenfapresimput; locaa="logemen"; e13_14part="1"; if q11enfan="Z" and q11nb_enf_lgt_i>=1 then output; run; data ajoutenfapresimputlogego2; set ajoutenfapresimput; locaa="logemen"; e13_14part="1"; if q11enfan="Z" and q11nb_enf_lgt_i>=2 then output; run; data ajoutenfapresimputlogego3; set ajoutenfapresimput; locaa="logemen"; e13_14part="1"; if q11enfan="Z" and q11nb_enf_lgt_i>=3 then output; run; data ajoutenfapresimputlogego4; set ajoutenfapresimput; locaa="logemen"; e13_14part="1"; if q11enfan="Z" and q11nb_enf_lgt_i>=4 then output; run; data ajoutenfapresimputlogego5; set ajoutenfapresimput; locaa="logemen"; e13_14part="1"; if q11enfan="Z" and q11nb_enf_lgt_i>=5 then output; run; data ajoutenfapresimputlogego6; set ajoutenfapresimput; locaa="logemen"; e13_14part="1"; if q11enfan="Z" and q11nb_enf_lgt_i>=6 then output; run; data ajoutenfapresimputlogego7; set ajoutenfapresimput; locaa="logemen"; e13_14part="1"; if q11enfan="Z" and q11nb_enf_lgt_i>=7 then output; run; /*enfants du cjt dans le logement*/ data ajoutenfapresimputlogcjt1; set ajoutenfapresimput; locaa="logemen"; e13_14part="2"; e13_14cpart="1"; if q12enfan_c="Z" and q12nb_enf_lgt_c_i>=1 then output; run; data ajoutenfapresimputlogcjt2; set ajoutenfapresimput; locaa="logemen"; e13_14part="2"; e13_14cpart="1"; if q12enfan_c="Z" and q12nb_enf_lgt_c_i>=2 then output; run; data ajoutenfapresimputlogcjt3; set ajoutenfapresimput; locaa="logemen"; e13_14part="2"; e13_14cpart="1"; if q12enfan_c="Z" and q12nb_enf_lgt_c_i>=3 then output; run; /*enfants de ego hors logement*/ data ajoutenfapresimputhorslog; set ajoutenfapresimput; enfhorlogego=(q11nb_enf_i-q11nb_enf_lgt_i); locaa="horslog"; e13_14part="1"; run; /* proc freq data=ajoutenfapresimputhorslog; table enfhorlogego; run; */ data ajoutenfapresimputhorslog1; set ajoutenfapresimputhorslog; locaa="horslog"; e13_14part="1"; if q11enfan="Z" and enfhorlogego>=1 then output; run; data ajoutenfapresimputhorslog2; set ajoutenfapresimputhorslog; locaa="horslog"; e13_14part="1"; if q11enfan="Z" and enfhorlogego>=2 then output; run; data ajoutenfapresimputhorslog3; set ajoutenfapresimputhorslog; locaa="horslog"; e13_14part="1"; if q11enfan="Z" and enfhorlogego>=3 then output; run; data ajoutenfapresimputhorslog4; set ajoutenfapresimputhorslog; locaa="horslog"; e13_14part="1"; if q11enfan="Z" and enfhorlogego>=4 then output; run; data ajoutenfapresimputhorslog5; set ajoutenfapresimputhorslog; locaa="horslog"; e13_14part="1"; if q11enfan="Z" and enfhorlogego>=5 then output; run; data ajoutenfapresimputhorslog6; set ajoutenfapresimputhorslog; locaa="horslog"; e13_14part="1"; if q11enfan="Z" and enfhorlogego>=6 then output; run; data ajoutenfapresimputhorslog7; set ajoutenfapresimputhorslog; locaa="horslog"; e13_14part="1"; if q11enfan="Z" and enfhorlogego>=7 then output; run; data ajoutenfapresimputhorslog8; set ajoutenfapresimputhorslog; locaa="horslog"; e13_14part="1"; if q11enfan="Z" and enfhorlogego>=8 then output; run; data ajoutenfapresimputhorslog9; set ajoutenfapresimputhorslog; locaa="horslog"; e13_14part="1"; if q11enfan="Z" and enfhorlogego>=9 then output; run; data ajoutenfapresimputhorslog10; set ajoutenfapresimputhorslog; locaa="horslog"; e13_14part="1"; if q11enfan="Z" and enfhorlogego>=10 then output; run; data ajoutenfapresimputhorslog11; set ajoutenfapresimputhorslog; locaa="horslog"; e13_14part="1"; if q11enfan="Z" and enfhorlogego>=11 then output; run; /*puis on colle l'ensemble des bases*/ data ajoutenftot; set ajoutenfapresimputlogego1 ajoutenfapresimputlogego2 ajoutenfapresimputlogego3 ajoutenfapresimputlogego4 ajoutenfapresimputlogego5 ajoutenfapresimputlogego6 ajoutenfapresimputlogego7 ajoutenfapresimputlogcjt1 ajoutenfapresimputlogcjt2 ajoutenfapresimputlogcjt3 ajoutenfapresimputhorslog1 ajoutenfapresimputhorslog2 ajoutenfapresimputhorslog3 ajoutenfapresimputhorslog4 ajoutenfapresimputhorslog5 ajoutenfapresimputhorslog6 ajoutenfapresimputhorslog7 ajoutenfapresimputhorslog8 ajoutenfapresimputhorslog9 ajoutenfapresimputhorslog10 ajoutenfapresimputhorslog11; run; /* proc freq data=ajoutenftot; table locaa ; run; */ proc delete data= ajoutenfapresimput ajoutenfapresimputhorslog ajoutenfapresimputlogego1 ajoutenfapresimputlogego2 ajoutenfapresimputlogego3 ajoutenfapresimputlogego4 ajoutenfapresimputlogego5 ajoutenfapresimputlogego6 ajoutenfapresimputlogego7 ajoutenfapresimputlogcjt1 ajoutenfapresimputlogcjt2 ajoutenfapresimputlogcjt3 ajoutenfapresimputhorslog1 ajoutenfapresimputhorslog2 ajoutenfapresimputhorslog3 ajoutenfapresimputhorslog4 ajoutenfapresimputhorslog5 ajoutenfapresimputhorslog6 ajoutenfapresimputhorslog7 ajoutenfapresimputhorslog8 ajoutenfapresimputhorslog9 ajoutenfapresimputhorslog10 ajoutenfapresimputhorslog11; run; /* si on a imputé des enfants au dessus il faut créer des lignes enfant du tableau 13 et enfant du tableau 14 et les ajouter à la base enfants avant d'imputer un rang et une date de naissance Verifier si l'ajout de la table ajoutenftot fonctionne */ /*Et on ajoute les lignes enfants imputés à la base enfants*/ data imputenfant; set imputenfant ajoutenftot; proc delete data=ajoutenftot; run; /*NOTE: There were 609398 observations read from the data set IMPUTENFANT. NOTE: There were 1878 observations read from the data set WORK.AJOUTENFTOT. NOTE: The data set IMPUTENFANT has 611276 observations and 93 variables.*/ /*on supprime les anciennes variables indicatrices qui ont été utilisées plus haut pour ne pas créer de problèmes*/ data imputenfant; set imputenfant; drop nbenftab2 nbenfdateok2 dateenf tableau nbenftab132 nbenftab142 nbenf13dateok2 nbenf14dateok2 bulltotdate bull13date bull14date; run; /*NOTE: The data set IMPUTENFANT has 611276 observations and 82 variables.*/ /**************************************************************************/ /**************************************************************************/ /*********************************************************************/ /*********************************************************************/ /*********************************************************************/ /*********************************************************************/ /***** La table enfants ******/ /*********************************************************************/ /*********************************************************************/ /*********************************************************************/ /*********************************************************************/ data imputenfant; set imputenfant; if loca="logemen" or locaa="logemen" then tableau=13; else if loca="horslog" or locaa="horslog" then tableau=14; run; /****** Comptage des enfants **************/ proc sort data=imputenfant; by cabefla; run; /*Nbr de lignes enfants*/ data imputenfant; set imputenfant; by cabefla; retain nbenftab; if first.cabefla then nbenftab=1; else nbenftab=nbenftab+1; run; /*on reporte l'info sur toutes les lignes*/ proc sort data=imputenfant; by cabefla descending nbenftab; run; data imputenfant; set imputenfant; by cabefla; retain nbenftab2; if first.cabefla then nbenftab2=nbenftab; else nbenftab2=nbenftab2; run; /* proc freq data=imputenfant; table nbenftab nbenftab2; run;*OK; proc print data=imputenfant; var cabefla q11enfan Q12enfan_c q11enfan_i q12enfan_c_i q11nb_enf_i q11nb_enf_lgt_i q12nb_enf_lgt_c q12nb_enf_lgt_c_i ; where nbenftab2>17; run; */ proc sort data=imputenfant; by cabefla tableau e13_14anai; run; /*les enfants pour lesquels on a une date de naissance*/ data imputenfant; set imputenfant; if e13_14anai not in (9999) then dateenf=1; else dateenf=0; run; /*on compte le nombre d'enfants avec une date de naiss*/ proc sort data=imputenfant; by cabefla tableau dateenf; run; /*au total*/ data imputenfant; set imputenfant; by cabefla; retain nbenfdateok; if first.cabefla then nbenfdateok=dateenf; else nbenfdateok=nbenfdateok+dateenf; run; /*on reporte l'info sur toutes les lignes*/ proc sort data=imputenfant; by cabefla descending nbenfdateok; run; data imputenfant; set imputenfant; by cabefla; retain nbenfdateok2; if first.cabefla then nbenfdateok2=nbenfdateok; else nbenfdateok2=nbenfdateok2; run; /* proc freq data=imputenfant; table nbenftab2*nbenfdateok2; run;*=>les compteurs fonctionnent bien; */ /*******************************************************************************************/ /*les enfants du tableau 13 et les enfants du tableau 14*/ data enftab13; set imputenfant; where tableau=13; run; data enftab14; set imputenfant; where tableau=14; run; /******************************** tableau 13 **************************************/ proc sort data=enftab13; by cabefla; run; /*Nbr de lignes enfants*/ data enftab13; set enftab13; by cabefla; retain nbenftab13; if first.cabefla then nbenftab13=1; else nbenftab13=nbenftab13+1; run; /*on reporte l'info sur toutes les lignes*/ proc sort data=enftab13; by cabefla descending nbenftab13; run; data enftab13; set enftab13; by cabefla; retain nbenftab132; if first.cabefla then nbenftab132=nbenftab13; else nbenftab132=nbenftab132; run; /* proc freq data=enftab13; table nbenftab13 nbenftab132; run;*OK; */ /*Nombre d'enfants du tableau 13 avec une date de naissance*/ data enftab13; set enftab13; by cabefla; retain nbenf13dateok; if first.cabefla then nbenf13dateok=dateenf; else nbenf13dateok=nbenf13dateok+dateenf; run; proc sort data=enftab13; by cabefla descending nbenf13dateok; run; data enftab13; set enftab13; by cabefla; retain nbenf13dateok2; if first.cabefla then nbenf13dateok2=nbenf13dateok; else nbenf13dateok2=nbenf13dateok2; if last.cabefla then output; keep cabefla identa nbenftab132 nbenf13dateok2; run; /************************* tableau 14 *******************************************/ proc sort data=enftab14; by cabefla; run; /*Nbr de lignes enfants*/ data enftab14; set enftab14; by cabefla; retain nbenftab14; if first.cabefla then nbenftab14=1; else nbenftab14=nbenftab14+1; run; /*on reporte l'info sur toutes les lignes*/ proc sort data=enftab14; by cabefla descending nbenftab14; run; data enftab14; set enftab14; by cabefla; retain nbenftab142; if first.cabefla then nbenftab142=nbenftab14; else nbenftab142=nbenftab142; run; /* proc freq data=enftab14; table nbenftab14 nbenftab142; run;*OK; */ /*Nombre d'enfants du tableau 14 avec une date de naissance*/ data enftab14; set enftab14; by cabefla; retain nbenf14dateok; if first.cabefla then nbenf14dateok=dateenf; else nbenf14dateok=nbenf14dateok+dateenf; run; proc sort data=enftab14; by cabefla descending nbenf14dateok; run; data enftab14; set enftab14; by cabefla; retain nbenf14dateok2; if first.cabefla then nbenf14dateok2=nbenf14dateok; else nbenf14dateok2=nbenf14dateok2; if last.cabefla then output; keep cabefla identa nbenftab142 nbenf14dateok2; run; /****************************************************************************************************************/ /*les enfants de ego, du cjt, du couple*/ data enfego; set imputenfant; where partcpart="12"; run; data enfegonrcjt; set imputenfant; where partcpart="1 "; run; data enfcjt; set imputenfant; where partcpart="21"; run; data enfcouple; set imputenfant; where partcpart="11"; run; /******************************** enfants de ego **************************************/ proc sort data=enfego; by cabefla; run; /*Nbr de lignes enfants*/ data enfego; set enfego; by cabefla; retain nbenfego; if first.cabefla then nbenfego=1; else nbenfego=nbenfego+1; if last.cabefla then output; keep cabefla nbenfego; run; /******************************** enfants de ego nr cjt **************************************/ proc sort data=enfegonrcjt; by cabefla; run; /*Nbr de lignes enfants*/ data enfegonrcjt; set enfegonrcjt; by cabefla; retain nbenfegonrcjt; if first.cabefla then nbenfegonrcjt=1; else nbenfegonrcjt=nbenfegonrcjt+1; if last.cabefla then output; keep cabefla nbenfegonrcjt; run; /******************************** enfants du cjt **************************************/ proc sort data=enfcjt; by cabefla; run; /*Nbr de lignes enfants*/ data enfcjt; set enfcjt; by cabefla; retain nbenfcjt; if first.cabefla then nbenfcjt=1; else nbenfcjt=nbenfcjt+1; if last.cabefla then output; keep cabefla nbenfcjt; run; /******************************** enfants du couple **************************************/ proc sort data=enfcouple; by cabefla; run; /*Nbr de lignes enfants*/ data enfcouple; set enfcouple; by cabefla; retain nbenfcouple; if first.cabefla then nbenfcouple=1; else nbenfcouple=nbenfcouple+1; if last.cabefla then output; keep cabefla nbenfcouple; run; /******************************** date du premier enfant pour lequel on a une date **************************************/ proc sort data=imputenfant; by cabefla e13_14anai; run; /*date premier enfant*/ data imputenfant; set imputenfant; by cabefla; retain datepremenf; if first.cabefla then datepremenf=e13_14anai; else datepremenf=datepremenf; run; /******************************** date du premier enfant de ego pour lequel on a une date **************************************/ data imputenfant; set imputenfant; if e13_14part="1" then enfego=1; else enfego=0; if e13_14cpart="1" then enfcjt=1; else enfcjt=0; run; data enfegop; set imputenfant; where enfego=1; run; data enfcjtp; set imputenfant; where enfcjt=1; run; proc sort data=enfegop; by cabefla rangenfant; run; data enfegop; set enfegop; by cabefla; retain datepremenfego; if first.cabefla then datepremenfego=e13_14anai; else datepremenfego=datepremenfego; keep cabefla datepremenfego; run; proc sort data=enfcjtp; by cabefla rangenfant; run; data enfcjtp; set enfcjtp; by cabefla; retain datepremenfcjt; if first.cabefla then datepremenfcjt=e13_14anai; else datepremenfcjt=datepremenfcjt; keep cabefla datepremenfcjt; run; proc sort data=enfego; by cabefla; run; proc sort data=enfcjt; by cabefla; run; proc sort data=imputenfant; by cabefla; run; proc sort data=enfegonrcjt; by cabefla; run; proc sort data=enfcouple; by cabefla; run; proc sort data=enftab13; by cabefla; run; proc sort data=enftab14; by cabefla; run; proc sort data=enfegop; by cabefla; run; proc sort data=enfcjtp; by cabefla; run; data imputenfant; merge imputenfant enfego enfegonrcjt enfcjt enfcouple enftab13 enftab14 enfegop enfcjtp; by cabefla; run;*OK; proc delete data= enfego enfegonrcjt enfcjt enfcouple enftab13 enftab14 enfegop enfcjtp; run; /************************ On compare les compteurs *************************/ data imputenfant; set imputenfant; /*on regarde dans quels bulletins les deux tableaux sont renseignés*/ if nbenftab132 not in (.) then enftab13=1; else enftab13=0; if nbenftab142 not in (.) then enftab14=1; else enftab14=0; /*Si le nombre d'enfants total est égale au nombre d'enfants avec une date de naiss c'est ok*/ if nbenftab2=nbenfdateok2 then bulltotdate="ok"; else bulltotdate="pas ok"; /*Si le nombre d'enfants du tab13 est égale au nombre d'enfants avec une date de naiss ds le tab13 c'est ok pour le tab13*/ if nbenftab132=. then bull13date="nc"; else if nbenftab132=nbenf13dateok2 then bull13date="ok"; else bull13date="pas ok"; /*Si le nombre d'enfants du tab14 est égale au nombre d'enfants avec une date de naiss ds le tab14 c'est ok pour le tab14*/ if nbenftab142=. then bull14date="nc"; else if nbenftab142=nbenf14dateok2 then bull14date="ok"; else bull14date="pas ok"; run; /*puis on ajoute un rang à ces enfants*/ proc sort data=imputenfant; by cabefla loca e13_14part e13_14cpart; run; data imputenfant; set imputenfant; by cabefla; retain rangenfantc; if first.cabefla then rangenfantc=1; else rangenfantc=rangenfantc+1; run; /*quand il y a toutes les dates sur le bulletin on prend l'ordre des dates de naissance de rangenfant*/ data imputenfant; set imputenfant; if bulltotdate in ("OK") then rangenfantc=rangenfant; run; /* proc freq data=imputenfant; table rangenfantc*bulltotdate/missing; run; */ /* *vérification; proc sort data=imputenfant nodupkey out=essai dupout=doublons; by cabefla rangenfantc; proc delete data=doublons essai; run; *The data set WORK.DOUBLONS has 0 observations and 105 variables => OK; *The data set WORK.ESSAI has 611276 observations and 105 variables. => OK; */ data infoenfparcabefla2; set imputenfant; by cabefla; if first.cabefla then output; keep cabefla nbenftab2 nbenfdateok2 dateenf tableau enftab13 enftab14 nbenftab132 nbenftab142 nbenf13dateok2 nbenf14dateok2 bulltotdate bull13date bull14date datepremenf datepremenfego datepremenfcjt; run; /*on ajoute ces variables à la base enquêté (base indiv)*/ proc sort data=infoenfparcabefla2; by cabefla; run; proc sort data=imputpage2; by cabefla; run; data imputpage2; merge imputpage2 infoenfparcabefla2; by cabefla; proc delete data=infoenfparcabefla2; run; /*on récupère q3couple_i et q6annee_c_i*/ data recup; set imputpage2; where q11enfan_i="1" or q12enfan_c_i="1"; keep cabefla q3couple_i q6annee_c_i; run; proc sort data=recup; by cabefla; run; data imputenfant; set imputenfant; tabenf=1; run; proc sort data=imputenfant; by cabefla; run; data imputenfant; merge imputenfant recup; by cabefla; if tabenf not in (1) then delete; run; proc delete data=recup;run; /**************************************************************************************/ /*on crée un indicateur de remplissage de la ligne enfant*/ data imputenfant; set imputenfant; if e13_14sexe not in ("z"," ") then a=1; else a=0; if e13_14anai not in (9999,.) then b=1; else b=0; if e13_14part not in (" ") then c=1; else c=0; if e13_14cpart not in (" ") then d=1; else d=0; if e13_14agad not in (.) then e=1; else e=0; if e13aut_lgt not in ("Z") then f=1; else f=0; if e14agdep not in (99) then h=1; else h=0; if e14reg not in ("99","ZZ") then i=1; else i=0; if loca="logemen" then do; infoenflog=a+b+c+d+e+f; end; if loca="horslog" then do; infoenfhlog=a+b+c+d+e+h+i; end; /*on corrige la variable cpart quand ego n'est pas en couple: cpart doit être à .*/ e13_14cpart_i=e13_14cpart; if e13_14cpart not in (" ") and q3couple_i in ("3","4") then e13_14cpart_i=" ";/*A faire tourner*/ /*Si ego est en couple et cpart n'est pas renseignée*/ /*si on a la date de naissance de l'enfant: on regarde la date de mise en couple imputée*/ if e13_14cpart_i=" " and q3couple_i in ("1","2") and e13_14anai not in (9999,.) then do; if e13_14anai>=q6annee_c_i then e13_14cpart_i="1"; if e13_14anai0 then enfdec=1; else if indexw (prenom,"FAUSSE COUCHE")>0 then enfdec=1; else if indexw (prenom,"PAS DE PRENOM")>0 then enfdec=1; else if indexw (prenom,"SANS PRENOM")>0 then enfdec=1; else if indexw (prenom,"NAISSANCES")>0 then enfdec=1; else if indexw (prenom,"PAS DE NOM")>0 then enfdec=1; else if indexw (prenom,"EN COUCHE")>0 then enfdec=1; else if indexw (prenom,"GROSSESSE")>0 then enfdec=1; else if indexw (prenom,"MORTE NEE")>0 then enfdec=1; else if indexw (prenom,"NEE MORTE")>0 then enfdec=1; else if indexw (prenom,"NAISSANCE")>0 then enfdec=1; else if indexw (prenom,"MORT NEE")>0 then enfdec=1; else if indexw (prenom,"SANS NOM")>0 then enfdec=1; else if indexw (prenom,"SANS VIE")>0 then enfdec=1; else if indexw (prenom,"MORT NE")>0 then enfdec=1; else if indexw (prenom,"MORTNE")>0 then enfdec=1; else if indexw (prenom,"BEBE")>0 then enfdec=1; else if indexw (prenom,"PRESENTEMENT SANS VIE")>0 then enfdec=1; else if indexw (prenom,"DANS SA SEPULTURE")>0 then enfdec=1; else if indexw (prenom,"DANS SA TOMBE")>0 then enfdec=1; else if indexw (prenom,"DANS MON CŒUR")>0 then enfdec=1; else if indexw (prenom,"DANS SON URNE")>0 then enfdec=1; else if indexw (prenom,"DANS MA TETE")>0 then enfdec=1; else if indexw (prenom,"CIMMETIERE")>0 then enfdec=1; else if indexw (prenom,"AU PARADIS")>0 then enfdec=1; else if indexw (prenom,"NON VIVANT")>0 then enfdec=1; else if indexw (prenom,"CIMETIERE")>0 then enfdec=1; else if indexw (prenom,"A SA MORT")>0 then enfdec=1; else if indexw (prenom,"CIMETIERE")>0 then enfdec=1; else if indexw (prenom,"CIMETIER")>0 then enfdec=1; else if indexw (prenom,"DECEDEES")>0 then enfdec=1; else if indexw (prenom,"PARADIS")>0 then enfdec=1; else if indexw (prenom,"DECEDEE")>0 then enfdec=1; else if indexw (prenom,"DECEDER")>0 then enfdec=1; else if indexw (prenom,"DECEDES")>0 then enfdec=1; else if indexw (prenom,"AU CIEL")>0 then enfdec=1; else if indexw (prenom,"LE CIEL")>0 then enfdec=1; else if indexw (prenom,"DECEDEE")>0 then enfdec=1; else if indexw (prenom,"DEDECEE")>0 then enfdec=1; else if indexw (prenom,"DECDEE")>0 then enfdec=1; else if indexw (prenom,"DECEDE")>0 then enfdec=1; else if indexw (prenom,"DEDECE")>0 then enfdec=1; else if indexw (prenom,"A VECU")>0 then enfdec=1; else if indexw (prenom,"MORTE")>0 then enfdec=1; else if indexw (prenom,"DECEE")>0 then enfdec=1; else if indexw (prenom,"DECES")>0 then enfdec=1; else if indexw (prenom,"MORTE")>0 then enfdec=1; else if indexw (prenom,"CIEL")>0 then enfdec=1; else if indexw (prenom,"MORT")>0 then enfdec=1; else if indexw (prenom,"DECE")>0 then enfdec=1; else if indexw (prenom,"DCD")>0 then enfdec=1; /*A partir de la commune*/ else if indexw (com,"PRESENTEMENT SANS VIE")>0 then enfdec=1; else if indexw (com,"DANS SA SEPULTURE")>0 then enfdec=1; else if indexw (com,"DANS SA TOMBE")>0 then enfdec=1; else if indexw (com,"DANS MON CŒUR")>0 then enfdec=1; else if indexw (com,"DANS SON URNE")>0 then enfdec=1; else if indexw (com,"DANS MA TETE")>0 then enfdec=1; else if indexw (com,"CIMMETIERE")>0 then enfdec=1; else if indexw (com,"AU PARADIS")>0 then enfdec=1; else if indexw (com,"NON VIVANT")>0 then enfdec=1; else if indexw (com,"CIMETIERE")>0 then enfdec=1; else if indexw (com,"A SA MORT")>0 then enfdec=1; else if indexw (com,"CIMETIERE")>0 then enfdec=1; else if indexw (com,"CIMETIER")>0 then enfdec=1; else if indexw (com,"DECEDEES")>0 then enfdec=1; else if indexw (com,"PARADIS")>0 then enfdec=1; else if indexw (com,"DECEDEE")>0 then enfdec=1; else if indexw (com,"DECEDER")>0 then enfdec=1; else if indexw (com,"DECEDES")>0 then enfdec=1; else if indexw (com,"AU CIEL")>0 then enfdec=1; else if indexw (com,"LE CIEL")>0 then enfdec=1; else if indexw (com,"DECEDES")>0 then enfdec=1; else if indexw (com,"DECEDEE")>0 then enfdec=1; else if indexw (com,"DEDECEE")>0 then enfdec=1; else if indexw (com,"DECDEE")>0 then enfdec=1; else if indexw (com,"DECEDE")>0 then enfdec=1; else if indexw (com,"DEDECE")>0 then enfdec=1; else if indexw (com,"A VECU")>0 then enfdec=1; else if indexw (com,"MORTE")>0 then enfdec=1; else if indexw (com,"DECEE")>0 then enfdec=1; else if indexw (com,"DECES")>0 then enfdec=1; else if indexw (com,"MORTE")>0 then enfdec=1; else if indexw (com,"CIEL")>0 then enfdec=1; else if indexw (com,"MORT")>0 then enfdec=1; else if indexw (com,"DECE")>0 then enfdec=1; else if indexw (com,"DCD")>0 then enfdec=1; else if indexw (com,"PRESENTE S VIE")>0 then enfdec=1; else if indexw (com,"FAUSSE COUCHE")>0 then enfdec=1; else if indexw (com,"PAS DE PRENOM")>0 then enfdec=1; else if indexw (com,"SANS PRENOM")>0 then enfdec=1; else if indexw (com,"NAISSANCES")>0 then enfdec=1; else if indexw (com,"PAS DE NOM")>0 then enfdec=1; else if indexw (com,"EN COUCHE")>0 then enfdec=1; else if indexw (com,"GROSSESSE")>0 then enfdec=1; else if indexw (com,"MORTE NEE")>0 then enfdec=1; else if indexw (com,"NEE MORTE")>0 then enfdec=1; else if indexw (com,"NAISSANCE")>0 then enfdec=1; else if indexw (com,"MORT NEE")>0 then enfdec=1; else if indexw (com,"SANS NOM")>0 then enfdec=1; else if indexw (com,"SANS VIE")>0 then enfdec=1; else if indexw (com,"MORT NE")>0 then enfdec=1; else if indexw (com,"MORTNE")>0 then enfdec=1; else if indexw (com,"BEBE")>0 then enfdec=1; else enfdec=0; run; %end; %else %do; data imputenfant; set imputenfant; enfdec=0; run; %end; %mend; %ano; run; /*On transforme cette base imputenfant avec une ligne par enfant en base individus avec une ligne par enquêté*/ data imputenfant; set imputenfant; /*je supprime dans la base imputenfant les variables que je ne veux pas prendre car on les a dans la base indiv OU elles sont inutiles dans la base ego (variables indicatrices)*/ drop cabefl_ca cabfla cabbia cabbi_ca e11enfan e11nb_enf e11nb_enf_lgt e12enfan_c e12nb_enf_c e12nb_enf_lgt_c i_cabbi_enf i_e11_12enf i_e13aut_lgt i_e13tpslgt; run; /*on trie par le rang de l'enfant*/ proc sort data=imputenfant ; by cabefla rangenfantc; run; /* ************************* vérification**************************; proc sort data=imputenfant nodupkey out=essaib dupout=doublonsb; by cabefla rangenfantc; proc delete data=essaib doublonsb; run; * doublonsb has 0 observations; proc freq data=imputenfant ; table rangenfantc enfdec; run; */ /************************************************************************* on passe d'un fichier enfant à un fichier enquêté *************************************************************************/ /*on fait une macro transpose pour avoir une ligne par enquêté avec les informations des enfant en colonnes*/ *** Macro that transposes from a LONG to a WIDE structure; %MACRO MAKEWIDE (DATA=,OUT=out,COPY=,ID=, VAR=, TIME=time); /********************************************************************* FOR MORE RESSOURCES ON DATA PREPARATION FOR ANALYTICS CHECK OUT: http://www.sascommunity.org/wiki/Data_Preparation_for_Analytics Dr. Gerhard Svolba May 2008 ***********************************************************************/ /*** PARAMETERS ******************************************************* DATA and OUT The names of the input and output data sets, respectively. ID The name of the ID variable that identifies the subject. COPY A list of variables that occur repeatedly with each observation for a subject and will be copied to the resulting data set. Note that the COPY variable(s) must not be used in the COPY statement of PROC TRANSPOSE for our purposes, but are listed in the BY statement after the ID variable. We assume here that COPY variables have the same values within one ID. VAR The variables that holds the values to be transposed. TIME The variable that numerates the repeated measurements. **********************************************************************/ %MACRO MAKEWIDE_BASIS (DATA=,OUT=out,COPY=,ID=, VAR=, TIME=time); *** Macro that transposes one variable per by-group; *** Dr. Gerhard Svolba, May 2nd 2008 - Rel 2.1; PROC TRANSPOSE DATA = &data PREFIX = &var OUT = &out(DROP = _name_); BY &id © VAR &var; ID &time; RUN; %MEND; *** Calculate number of variables; %LET c=1; %DO %WHILE(%SCAN(&var,&c) NE); %LET c=%EVAL(&c+1); %END; %LET nvars=%EVAL(&c-1); %IF &nvars=1 %then %do; %*** macro is called with only one variable; %MAKEWIDE_BASIS(data=&data, out = &out, copy=©, id=&id, var=&var,time=&time); %END; %** end: only 1 variable; %ELSE %DO; ** more then 2 vars; %DO i = 1 %TO &nvars; %MAKEWIDE_BASIS(data=&data, out = _mw_tmp_&i., copy=©, id=&id, var=%scan(&var,&i),time=&time); %END; *** end do loop; data &out; merge %do i = 1 %to &nvars; _mw_tmp_&i. %end; ; by &id; run; %END; %MEND; %MAKEWIDE ( DATA=imputenfant , OUT=cabeflaenfant , ID=cabefla, VAR=E13_14agad E13_14anai E14agdep e13tpslgt e13aut_lgt e13lgt_aut_par e13lgt_autre e13lgt_etude dateenf infoenflog infoenfhlog cabbi_enfa E13_14cpart E13_14cpart_i E13_14part E13_14sexe e14reg e14resid imput loca partcpart infoenfnaiss infoenfsexe identa enfdec, TIME=rangenfantc); proc delete data= _mw_tmp_1 _mw_tmp_2 _mw_tmp_3 _mw_tmp_4 _mw_tmp_5 _mw_tmp_6 _mw_tmp_7 _mw_tmp_8 _mw_tmp_9 _mw_tmp_10 _mw_tmp_11 _mw_tmp_12 _mw_tmp_13 _mw_tmp_14 _mw_tmp_15 _mw_tmp_16 _mw_tmp_17 _mw_tmp_18 _mw_tmp_19 _mw_tmp_20 _mw_tmp_21 _mw_tmp_22 _mw_tmp_23 _mw_tmp_24 _mw_tmp_25 ; run; /************************************************************** on merge avec la base anonymisée ***************************************************************/ proc sort data=imputpage2; by cabefla; run; proc sort data=cabeflaenfant ; by cabefla; run; data imputpage2; merge imputpage2 cabeflaenfant ; by cabefla; run; proc delete data=cabeflaenfant imputenfant ;run; /************************************************************** imputations Q2 : nombre de frères et soeurs ***************************************************************/ /*Imputation par hotdeck sur les variables q2nbfreres q2nbsoeurs q2nbdemif q2nbdemis: si aucune réponse aux 4 variables, car bulletins ajoutés*/ Proc sort data=imputpage2 ; By groupesimput3 nbenftab2; Run; data imputpage2; set imputpage2; By groupesimput3 nbenftab2; retain n_ok n_miss pb; if first.nbenftab2 then do; n_ok=1; n_miss=2; end; if q2nbfreres not in (99) then do; num=n_ok; n_ok=n_ok+2; end; else if q2nbfreres in (99) then do; num=n_miss; n_miss=n_miss+2; end; else kk = 1 ; if last.nbenftab2 then do; if n_ok+1 < n_miss then pb = 1; end; run; proc sort data=imputpage2; by groupesimput3 nbenftab2 num; run; data imputpage2; set imputpage2; q2nbfreres_i=q2nbfreres; q2nbsoeurs_i=q2nbsoeurs; q2nbdemif_i=q2nbdemif; q2nbdemis_i=q2nbdemis; retain reserve reserve2 reserve3 reserve4;/*retain est fait sur le vecteur: la reserve*/ /*si il y a une reponse à q2nbfreres on remplit la réserve*/ if q2nbfreres not in (99) then reserve=q2nbfreres; if q2nbsoeurs not in (99) then reserve2=q2nbsoeurs; if q2nbdemif not in (99) then reserve3=q2nbdemif; if q2nbdemis not in (99) then reserve4=q2nbdemis; /*si la réponse est vide, on va piocher dans la réserve*/ if q2nbfreres in (99) then q2nbfreres_i=reserve; if q2nbsoeurs in (99) then q2nbsoeurs_i=reserve2; if q2nbdemif in (99) then q2nbdemif_i=reserve3; if q2nbdemis in (99) then q2nbdemis_i=reserve4; drop reserve reserve2 reserve3 reserve4 num n_miss n_ok pb kk; run; /********************* VERIFICATION ******************************** proc freq data=imputpage2; table q2nbfreres_i q2nbsoeurs_i q2nbdemif_i q2nbdemis_i q11enfan_i q11nb_enf_i q11nb_enf_lgt_i q12enfan_c_i q12nb_enf_c_i q12nb_enf_lgt_c_i; run; PROc freq data=imputpage2; table infodate; where q6annee_c_i=. and q3couple_i in ("1","2"); run; *On doit recoller les variables de départ pour comparaison; proc sort data=imputpage2; by cabefla; run; proc sort data=fpr.efl_individu; by cabefla; run; data pourverif; merge imputpage2 fpr.efl_individu; by cabefla; proc delete data=pourverif; run; proc print data=pourverif; var q2nbfreres q6annee_c q3couple i_q3couple; where q6annee_c_i not in (.) and q3couple_i in ("3","4"); run;* O observations => OK ; proc freq data=pourverif; table i_q3couple*q3couple/norow nocol nopercent; proc freq data=pourverif; table q7pacs*q7pacs_i/norow nocol nopercent; run; *************************************************************************/ /**********************************************************************/ /*** ***/ /*** CREATION VAR INDICATRICES IMPUTATION TABLEAU PAGE 3 ***/ /*** ***/ /**********************************************************************/ /*on crée les variables indicatrices dont on a besoin pour l'imputation des enfants*/ data imputpage2; set imputpage2; /*date de vie en couple*/ datecouple=q6annee_c_i; /*année 18 ans de ego*/ majoriteego=q1anai_i+18; if q4anai_C_i not in (.) then majoritecjt=q4anai_C_i+18; /*date de l'enquête*/ anenquete=2011; /*date de dernière rupture*/ if q10annee_s_i not in (9999,.) then anneerupture=q10annee_s_i; else if q10annee_d_i not in (9999,.) then anneerupture=q10annee_d_i; else anneerupture=.; ************************************************************************* ; /* %%% ajout LT mais il faut traiter en amont les cas où ces dates manquent (imputations incomplètes ?*/ if q3couple_i in ('3','4') then do ; if anneerupture = . then anneerupture = 2011 ; else if anneerupture < majoriteego then anneerupture = majoriteego ; end ; else if q3couple_i in ('1','2') then do ; if datecouple = . then datecouple = round(majoriteego/2)+1005 ; if majoritecjt = . then majoritecjt = majoriteego ; end ; *************************************************************************; /*infoenfnaisstot*/ infoenfnaisstot=cats(infoenfnaiss1,infoenfnaiss2,infoenfnaiss3,infoenfnaiss4,infoenfnaiss5,infoenfnaiss6,infoenfnaiss7, infoenfnaiss8,infoenfnaiss9,infoenfnaiss10,infoenfnaiss11,infoenfnaiss12,infoenfnaiss13,infoenfnaiss14,infoenfnaiss15, infoenfnaiss16,infoenfnaiss17); /*infoenfsexetot*/ infoenfsexetot=cats(infoenfsexe1,infoenfsexe2,infoenfsexe3,infoenfsexe4,infoenfsexe5,infoenfsexe6,infoenfsexe7, infoenfsexe8,infoenfsexe9,infoenfsexe10,infoenfsexe11,infoenfsexe12,infoenfsexe13,infoenfsexe14,infoenfsexe15, infoenfsexe16,infoenfsexe17); run; /************************ verification ************************************************/ /* proc freq data=imputpage2; table datecouple majoriteego majoritecjt anneerupture infoenfnaisstot infoenfsexetot; run; proc freq data=imputpage2; table majoriteego (datecouple majoritecjt anneerupture)*couple / missing norow nocol nopercent; run;*OK; */ ** %%% cas problématiques: situation de couple différente selon EFL et EAR; /* proc freq data=imputpage2; where couple = '1' and datecouple = . ; table Q11nb_enf Q11nb_enf_lgt Q12nb_enf_C Q12nb_enf_lgt_C nbenftab2 nbenftab132 nbenftab142 / missing; run; */ /*There were 2003 observations read from the data set IMPUTPAGE2. La variable couple vient de EAR, Q3couple vient de EFL */ /*****************************************************************************************/ /********************************************************************************** creation variable kk, problème d'ordre des événements **********************************************************************************/ data imputpage2; set imputpage2; /*les variables KK quand il y a un probleme d'"ordre" sur les enfants*/ /*kk1=1 quand ego est en couple et qu'il y a au moins un enfant ego ou cjt après un enfant du couple*/ if q3couple_i in ("1","2") and index(infoenfnaisstot,"82") then kk1=8; else if q3couple_i in ("1","2") and index(infoenfnaisstot,"12") then kk1=1; else if q3couple_i in ("1","2") and index(infoenfnaisstot,"89") then kk1=1; else if q3couple_i in ("1","2") and index(infoenfnaisstot,"19") then kk1=8; else kk1=0; /*kk2=1 quand ego n'est pas en couple et qu'il y a au moins un enfant ego ou cjt après un enfant du couple*/ if q3couple_i in ("3","4") and index(infoenfnaisstot,"82") then kk2=8; else if q3couple_i in ("3","4") and index(infoenfnaisstot,"12") then kk2=1; else if q3couple_i in ("3","4") and index(infoenfnaisstot,"89") then kk2=1; else if q3couple_i in ("3","4") and index(infoenfnaisstot,"19") then kk2=8; else kk2=0; /*kk3=1 quand ego n'est pas en couple et qu'il y a au moins un enfant du couple*/ if q3couple_i in ("3","4") and index(infoenfnaisstot,"1") then kk3=1; else if q3couple_i in ("3","4") and index(infoenfnaisstot,"9") then kk3=1; else kk3=0; run; /* proc freq data=imputpage2; table kk1 kk2 kk3; run; */ /**************************************************************** autres variables indicatrices *****************************************************************/ data imputpage2; set imputpage2; /*Variable indicatrice permettant de savoir si c'est un bulletin contenant toutes les dates de naissance des enfants*/ /*complet=1 quand c'est un bulletin avec toutes les dates de naissance des enfants*/ if index(infoenfnaisstot,"8") then complet=0; else if index(infoenfnaisstot,"9") then complet=0; else complet=1; /*en couple/pas en couple*/ if q3couple_i in ("1","2") then encouple=1; else encouple=0; /*enfant/pas enfant*/ if nbenftab2=. then enfant=0; else enfant=1; run; /* proc freq data=imputpage2; table complet encouple enfant; run; */ data imputpage2; set imputpage2; /*on fait des groupes d'age*/ /*date de naissance d'ego*/ datenaissego=mdy(q1mnai_i,15,q1anai_i); dateenquete=mdy(2,1,2011); ageego=(dateenquete-datenaissego)/365.25; anenquete = 2011 ; /*groupes d'age*/ if 30>ageego then gage=1; else if 40>ageego>=30 then gage=2; else if 50>ageego>=40 then gage=3; else if 60>ageego>=50 then gage=4; else if 70>ageego>=60 then gage=5; else if 80>ageego>=70 then gage=6; else if 110>ageego>=80 then gage=7; /*groupes d'agebx*/ if 25>ageego then gageb=1; else if 30>ageego>=25 then gageb=2; else if 35>ageego>=30 then gageb=3; else if 40>ageego>=35 then gageb=4; else if 45>ageego>=40 then gageb=5; else if 50>ageego>=45 then gageb=6; else if 55>ageego>=50 then gageb=7; else if 60>ageego>=55 then gageb=8; else if 65>ageego>=60 then gageb=9; else if 70>ageego>=65 then gageb=10; else if 75>ageego>=70 then gageb=11; else if 80>ageego>=75 then gageb=12; else if 85>ageego>=80 then gageb=13; else if 90>ageego>=85 then gageb=14; else if 110>ageego>=90 then gageb=15; /*kk4=1 si ego a un enfant avant 16 ans*/ kk4=0; if datepremenfego not in (9999,.) then ageegoenf=(datepremenfego-q1anai_i); if ageegoenf not in (.) and ageegoenf<16 then kk4=1; if datepremenfcjt not in (9999,.) then agecjtenf=(datepremenfcjt-q4anai_C_i); if agecjtenf not in (.) and agecjtenf<16 then kk4=kk4+2; run; /* proc freq data=imputpage2; table ageego gage gageb ageegoenf kk4; run; proc freq data=imputpage2; table ageegoenf; where kk4=1; run;* 303 enquêtés; */ /************************************************************ vérification ordre des dates de naissance renseignées ************************************************************/ /* proc freq data=imputpage2; table E13_14anai1 - E13_14anai17;run; */ /* pas de dates absurdes*/ data imputpage2 ; set imputpage2 ; array tab(17) E13_14anai1 - E13_14anai17; ordre_enf="oui"; nbenf=0; /*compteur enfant*/ do i=1 to 17; if tab(i) not in (9999 . ) then nbenf=nbenf+1; end; if nbenf=17 then max=16; else max=nbenf; /*test ordre enfant*/ do j=1 to max; if tab(j+1) not in (9999 .) and tab(j)>tab(j+1) then ordre_enf="non"; end; drop i j nbenf; run; /* proc freq;table ordre_enf;run; */ /********************************************************************** Imputation des dates de naissance des enfants **********************************************************************/ /*************************************************************************************** programme de Laurent pour les dates de naissance des enfants A faire tourner sur la base imputpage2 ancres si en couple actuellement : * enfant de Ego avant couple : majoriteego - datecouple * enfant de cjt avant couple : majoritecjt - datecouple * enfant de couple : datecouple - anenquete ancres si pas en couple actuellement : * enfant de Ego avant couple : majoriteego - anneerupture A regler d abord - pas d enfant avant majoriteego - nbenfego_nrcjt a imputer ou à corriger (pas du conjoint si date inconnue) et on augmente nbenfego d autant pour les complets, mais avec kk, soit on les corrige soit on les enlève pour l imputation * Verifs pralables enfant avant 18 ans verifier les kk verifier les donneurs et receveurs et calculer num pour trier * Imputations prealables : cpart inconnu et en couple **************************************************************************************/ /************************************************************ variable kkk qui regroupe les situations non ordinaires ************************************************************/ data imputpage2; set imputpage2; if kk1 in (1,8) or kk2 in (1,8) or kk3 in (1,8) or kk4 not in (. 0 ) /*or ordre_enf="non" */then kkk=1; else kkk=0; run; /* proc freq; table kkk;run; proc freq ; table kk1 kk2 kk3 kk4 complet kkk*complet kk3*kkk*complet /norow nocol nopercent; run; proc print data=imputpage2(obs=20); var datecouple q1anai_i e13_14anai1 e13_14anai2 e13_14anai3 e13_14anai4 Q3couple_i nbenftab2 KK1 KK2 KK3 KKK; where kkk=1 and complet=0; run; */ *********** on cree nbenfego, nbenfcjt et nbenfcou********************; data imputpage2; set imputpage2; array v_part(17) E13_14part1 - E13_14part17 ; /**/ array v_cpart(17) E13_14cpart1 - E13_14cpart17 ;/**/ nbenfego = 0 ;nbenfcjt = 0 ;nbenfcou = 0 ;nbkk = 0 ; if nbenftab2 > 0 then do ; do i = 1 to nbenftab2 ; if v_part(i) = '1' and v_cpart(i) = '1' then nbenfcou = nbenfcou + 1 ; else if v_part(i) = '1' and v_cpart(i) NE '1' then nbenfego = nbenfego + 1 ; else if v_part(i) NE '1' and v_cpart(i) = '1' then nbenfcjt = nbenfcjt +1 ; else nbkk = 1 ; end ; end ; drop i; /* proc freq data = imputpage2 ; table nbkk ;run ; * nbkk = 0 => OK; */ /****************************************************************************** ** %%% regrouper avec CS et créer num et vérifier les groupes ** %%% variables nbenfego, nbenfcjt et nbenfcou nécessaires aussi ** %%% On aurait pu trier par encouple cela aurait réglé quelques erreurs mais ce n'est pas grave ** debut du bout de programme recupere*/ /******************* tri préalable à l'imputation nbenfcou *************************/ /* il est important de vérifier s'il n'y a pas des groupes avec plus de donneurs que de receveurs, en effet dans le programme qui suit les donneurs et les receveurs doivent posseder les même "ancres temporelles" (dates que l'on a définies qui servent de repère, majorité dégo, majorité du conjoint, date de mise en couple,....)*/ /* on effectue des regroupements proc freq data=imputpage2; table groupesimput4 nbenfego nbenfcjt nbenfcou; run; */ data imputpage2 ; set imputpage2 ; length gimp_enf2 $2 gimp_enf3 $2 gimp_enf4 $2 ; /* *groupesimput4; gimp_enf1=groupesimput4; if groupesimput4="1011" then gimp_enf1="1021"; else if groupesimput4="1013" then gimp_enf1="1023"; else if groupesimput4="1014" then gimp_enf1="1024"; else if groupesimput4="1022" then gimp_enf1="1032"; else if groupesimput4="2013" then gimp_enf1="2023"; else if groupesimput4="2022" then gimp_enf1="2032"; else if groupesimput4="2022" then gimp_enf1="2032"; else if groupesimput4="2033" then gimp_enf1="1033"; */ *nbenfego; a=put(nbenfego,best2.); if nbenfego ne . then do; if nbenfego < 10 then gimp_enf2=cats("0",a); else gimp_enf2=a; end; *nbenfcjt; b=put(nbenfcjt,best1.); if nbenfcjt ne . then gimp_enf3=b; *nbenfcou; c=put(nbenfcou,best2.); if nbenfcou ne . then do; if nbenfcou < 10 then gimp_enf4=cats("0",c); else gimp_enf4=c; end; drop a b c; run; /* proc freq; table nbenfego gimp_enf2 nbenfcjt gimp_enf3 nbenfcou gimp_enf4; run; */ data imputpage2; set imputpage2 ; vdiscri_enf=cats(groupesimput4,gimp_enf2,gimp_enf3,gimp_enf4); run; /*proc freq; table vdiscri_enf; run; */ proc sort; by vdiscri_enf; run; data imputpage2 ; set imputpage2; By vdiscri_enf; retain n_ok n_miss a b c; if first.vdiscri_enf then do; n_ok=1; n_miss=2; a=0;b=0;c=0; end; a=a+1; if complet=1 and kkk=0 and enfant=1 then do; num=n_ok; n_ok=n_ok+2; b=b+1;end; * chgt GD ajout de kkk=0 pour ne prendre que les donneurs sains; * chgt GD ajout de enfant=1 pour ne prendre que les donneurs qui ont des enfants; else if complet not in (1) then do; num=n_miss ; n_miss=n_miss+2; c=c+1;end; else do;num=100000;end; if last.vdiscri_enf then do; if n_ok +1 < n_miss then do ; pb = 1; taille_groupe=a; donneurs=b; receveurs=c; donneurs_manquants=receveurs-donneurs; end; else pb=0; end; drop a b c n_miss n_ok ; run; /* proc freq; table pb; run; proc print;where pb=1; var vdiscri_enf taille_groupe donneurs receveurs donneurs_manquants; run; */ proc sort; by vdiscri_enf num; run; /* data _null_; set imputpage2 end=fin; a=length(vdiscri_enf); if fin then put a; run; */ /**************************imputation date naissance enfants********************************/ data imputpage2; set imputpage2 ; /* proc freq; table nbenftab2;run; */ /*on modifie nbenftab2= . en 0 quand il n'y a pas d'enfant dans les tableaux pour la boucle*/ if nbenftab2=. then nbenftab2=0; anenquete = 2011 ; if q3couple_i in ('3','4') then do ; if anneerupture = . then anneerupture = 2011 ; else if anneerupture < majoriteego then anneerupture = majoriteego ; end ; else if q3couple_i in ('1','2') then do ; if datecouple = . then datecouple = round(majoriteego/2)+1005 ; if majoritecjt = . then majoritecjt = majoriteego ; end ; length A10groupimput $9.; retain andon1-andon22 decal rangego rangcjt rangcou A1majego A2majcjt A3datecouple A4daterupt A5dateenq A6nbenftab2 A7nbenfego A8nbenfcjt A9nbenfcou 0 A10groupimput; ** les années que l on recupere ; array v_andon (22) andon1-andon22 ;* recues de EGO si complet, du precedent sinon ; array v_an (22) an1-an22 ;* variables de EGO ou du précédent si on impute ego; array v_rang (22) rang1-rang22 ;* receveur ; array v_anaienf(17) anaienf1-anaienf17 ;* annee de naissance de l enfant, receveur si complet; array v_13_14anai(17) E13_14anai1 - E13_14anai17 ;* annee de naissance de l enfant, receveur si complet; array v_anaienf_i(17) E13_14anai_i1 - E13_14anai_i17 ;* annee de naissance de l enfant, receveur si complet; array v_part(17) E13_14part1 - E13_14part17 ; /**/ array v_cpart(17) E13_14cpart1 - E13_14cpart17 ;/**/ ** on remplit v_anaienf: E13_14anai 0 si KK ; do i = 1 to 17 ; if 0 < v_13_14anai(i) < 2012 then v_anaienf(i) = v_13_14anai(i) ; else v_anaienf(i) = 0; v_anaienf_i(i) = v_anaienf(i) ;/* %%% valeur imputee initialisee */ end ; ** on initialise tout a zero; do i = 1 to 22 ; v_an(i) = 0 ;end ; rangego = 0 ;rangcjt = 0 ;rangcou = 0; ** decal pour arrondir de temps en temps en-dessous ; if decal = 0 then decal = -.01;else decal = 0; do i = 1 to 22 ; v_rang(i) = 0 ;end ;* on remplit les infos sur les enfants presents ; * on cree les variables de rang ; do i = 1 to nbenftab2 ;* rangtab = rang parmi les 22; * vrang(rangtab) rang dans le fichier ; if v_part(i) = '1' and v_cpart(i) = '1' then do ; rangcou = rangcou + 1 ;rangtab = 1 + nbenfego + 1 + 1 + nbenfcjt + 1 + rangcou ; end ; else if v_part(i) = '1' and v_cpart(i) NE '1' then do ; rangego = rangego + 1 ;rangtab = 1 + rangego ; end ; else if v_part(i) NE '1' and v_cpart(i) = '1' then do ; rangcjt = rangcjt + 1 ;rangtab = 1 + nbenfego + 1 + 1 + rangcjt ; end ; v_rang(rangtab) = i ;* v_rang(rangtab) = rang parmi les enfants dans le fichier qu on lit; * vrang(rangtab = rang parmi les 22; if 2012 > v_anaienf(i) > 0 then v_an(rangtab) = v_anaienf(i) ;* on remplit v_an avec les dates de N des enfants renseignées ; /* %%% erreur rectifiée: v_an(i) = v_anaienf(i) --> v_an(rangtab) = v_anaienf(i) */ end ; ** si Ego en couple ;** 22 valeurs car 5 ancres ; ** majoriteego - enfants de Ego avant couple - datecouple majoriteego - enfants de cjt avant couple - datecouple enfants de couple - anenquete ; * on remplit v_an avec les encres ; if encouple = 1 and majoritecjt < 2011 then do ; nmax = 1 + nbenfego + 1 + 1 + nbenfcjt + 1 + nbenfcou + 1 ; v_an(1) = majoriteego ; v_an(1 + nbenfego + 1) = datecouple ; v_an(1 + nbenfego + 1 + 1) = majoritecjt ; v_an(1 + nbenfego + 1 + 1 + nbenfcjt + 1) = datecouple ; v_an(1 + nbenfego + 1 + 1 + nbenfcjt + 1 + nbenfcou + 1) = anenquete ; end ; ************* ajout guilhem 18/09/2013; /* vérification intermédiaire on a quelques valeurs an qui sont supérieurs à 2011 à cause de majorité conjoint=2017 on corrige ci dessous*/ /*correction si conjoint mineur*/ else if encouple = 1 and majoritecjt >= 2011 then do; nmax = 1 + nbenfego + 1 + 1 + nbenfcjt + 1 + nbenfcou + 1 ; v_an(1) = majoriteego ; v_an(1 + nbenfego + 1) = datecouple ; v_an(1 + nbenfego + 1 + 1) = 2011 ; v_an(1 + nbenfego + 1 + 1 + nbenfcjt + 1) = datecouple ; v_an(1 + nbenfego + 1 + 1 + nbenfcjt + 1 + nbenfcou + 1) = anenquete ; end; **********************************; else if encouple NE 1 then do ; nmax = 1 + nbenfego + 1 ; v_an(1) = majoriteego ; v_an(1 + nbenfego + 1) = anneerupture; end ; *création d'une variable de suivi; suivi=0; /******************ok*/ ****************************************************************** ** individu complet ? ; complet = 1 ; do rangtab = 1 to nmax ; if v_an(rangtab) < 1900 or v_an(rangtab) = 9999 then complet = 0 ; end ; *%%% ici modifier si on ne garde que les donneurs kk=0 ; * %%% mettre num +1000 pour les complets vérolés ; * %%% dans l'hypothèse où on ne les corrige ni ne les nettoie; ****************************************************************** ** individu complet : on remplit v_andon ; if complet = 1 then do ; /* and kkk=0 ?*/ do rangtab = 1 to 22 ; v_andon(rangtab) = v_an(rangtab); end; A1majego= majoriteego; A2majcjt= majoritecjt; A3datecouple=datecouple; A4daterupt=anneerupture; A5dateenq=anenquete; A6nbenftab2=nbenftab2; A7nbenfego=nbenfego; A8nbenfcjt= nbenfcjt; A9nbenfcou=nbenfcou; A10groupimput=vdiscri_enf; end; /*********** jusqu'ici tout va bien ************** */ ** individu incomplet : on remplit les trous ; else if complet NE 1 then do ; do rangtab = 1 to nmax ; if v_an(rangtab) < 1900 or v_an(rangtab) = 9999 then do ;** debut d un trou ; debut = rangtab ;finmax = nmax - debut ;* debut OK ; fin = debut ;* on initialise la fin du trou ; fini=0;* initialise la boucle suivante; do j = 1 to finmax ; if fini=0 and v_an(debut+j) < 1900 or v_an(debut+j) = 9999 then fin = fin + 1 ;**fin du trou ; else fini=1; end; * fin OK ; longueur = fin - debut + 1 ;** nombre de dates a remplir ; avant = v_an(debut-1) ;apres = v_an(fin+1); duree = apres - avant ;** dates avant et apres trou ; avantdon = v_andon(debut-1) ;apresdon = v_andon(fin+1);dureedon = apresdon - avantdon ;** idem donneur ; ** on remplit le trou si dureedon > 0; * %%% A titre de verif on peut croiser dureedon et duree (j(ai regardé les cas bizarres) * mais ces cas sont très rares et a refaire avec le FPR ; if duree >=0 and dureedon > 0 then do ; do k = 1 to longueur ; v_an(debut-1+k) = round(avant + (duree / dureedon)* (v_andon(debut-1+k)-avantdon ) + decal) ; end ; suivi=1; end ; else if dureedon <= 0 and duree <= 0 then do ; ** problème (dureedon < 0) ou jumeaux : on attribue la même date a tous ; do k = 1 to longueur ; v_an(debut-1+k) = avant ; end ; suivi=2; end ; else if dureedon > 0 and duree < 0 then do ; ** problème (duree < 0) : on attribue la même date a tous ; do k = 1 to longueur ; v_an(debut-1+k) = avant ; end ; suivi=3; end ; else if dureedon <= 0 and duree > 0 then do ; ** on tape au milieu ou on répartit les remplissages ; ** a ne faire que dans les cas rares... ; do k = 1 to longueur ; ratio = k / (longueur + 1) ; v_an(debut-1+k) = round(avant + (duree*ratio) + decal) ; end ; suivi=4; end ; else suivi = 5 ; ******* rustine rajoutee le 20-9-2013 : donneurs pourris car pas dans le bon groupe ; ** quelques cas pathologiques oubliées ; ** les bornes sont OK (dureedon >=0) mais il y a des dates qui ne sont pas dans l intervalle ** par exemple parce que le donneur n est pas du bon groupe ** 200 cas %%% en tout ; ** On teste si il y a "un probleme dans le trou", c'est-a-dire une date pour le donneur qui ne soit ** pas dans l intervalle [avant-après) ; donpourri = 0 ; do k = 1 to longueur ; if v_andon(debut-1+k) < avantdon or v_andon(debut-1+k) > apresdon then donpourri = 1 ; end ; if donpourri = 1 then do ; do k = 1 to longueur ; ratio = k / (longueur + 1) ; v_an(debut-1+k) = round(avant + (duree*ratio) + decal) ; end ; suivi = 6 ; end ; /*****/ end ; end ; ** on remplit le fichier avec les données du trou rempli ; do rangtab = 1 to nmax ;* pour les enfants vrang(rangtab) > 0 ; if v_rang(rangtab) > 0 and v_anaienf(v_rang(rangtab)) = 0 then v_anaienf_i(v_rang(rangtab)) = v_an(rangtab) ; end ; end ; run; /************************************************************************************/ /******************* verification ************************************* proc freq; table suivi;run; proc means; var andon1-andon22 an1-an22;run; proc freq ; table E13_14anai_i1 - E13_14anai_i17;run; proc print ; where E13_14anai_i1>2011 or E13_14anai_i2 >2011; var andon1-andon3 an1-an3 E13_14anai_i1 - E13_14anai_i13;run; */ /*********************** identification des erreurs ********************************* data verif ;set test; array v_anaienf_i(17) E13_14anai_i1 - E13_14anai_i17 ;* annee de naissance de l enfant, receveur si complet; pb= 0 ; do i = 1 to nbenftab2 ; if (v_anaienf_i(i) < 1920 or v_anaienf_i(i) > 2011) then output; end ; run ; *The data set WORK.VERIF has 46 observations and 946 variables.; proc freq data=verif; table kkk*complet/norow nocol nopercent;run; proc freq data=verif; table kk1 kk2 kk3 kk4;run; proc freq; table q3couple_i datecouple bulltotdate anenquete anneerupture avant apres duree;run; proc freq; table suivi;run; ods html body="transit.xls" style=minimal; proc print; var CABEFLA q3couple_i an1-an8 andon1-andon8 E13_14anai1 - E13_14anai8 E13_14anai_i1 - E13_14anai_i8 num nmax nbenfego nbenfcjt nbenfcou couple nmax nbenftab2 majoriteego majoritecjt datecouple anneerupture anenquete avant apres duree groupesimput3 A1majego A2majcjt A3datecouple A4daterupt A5dateenq suivi; run; ods html close; proc delete data=verif;run; *********************** fin verification ******************************************/ /********************************************************************** Imputation sexe des enfants, création imputpage2b **********************************************************************/ /****Le sexe des enfants*******/ /*on impute selon le nombre d'enfants total, et les variables de groupimput3*/ /*on impute le sexe du premier selon le sexe du deuxième s'il est renseigné*/ /*on impute le sexe du deuxième selon le sexe du premier s'il est renseigné*/ /* %%% Pour simplifier on a imputé la variable "les deux premiers enfants sont-ils de même sexe" pour les cas où suel le premier ou le deuxième était renseigné */ /*on impute le sexe des deux premiers à partir d'un autre bulletin ou les deux premiers sexes sont renseignés*/ /*Pour les autres sexes manquants: du troisième enfant et plus, on impute en fonction des deux premiers*/ /* %%% On impute d'un côté les enfants d'Ego (du couple ou non) de l'autre les enfants du conjoint */ /* proc freq data=imputpage2; table infoenfsexetot / missing;run; */ /* proc contents data = imputpage2;run ; */ ** on reprend avec le fichier de la WORK ; data imputpage2b; set imputpage2; ** on separe les enfants d'Ego (couple ou non) et les autres ; array vsexenf(17) $ E13_14sexe1 - E13_14sexe17 ; array vpartenf(17) $ E13_14part1 - E13_14part17 ; ** on cree les enfants de Ego : vr pour le rang (parmi tous les enfants) et vs pour le sexe ; array vr_egoenf(17) rangego1-rangego17 ; array vs_egoenf(17) $ sexeego1-sexeego17 ; array vr_autenf(17) rangaut1-rangaut17 ; array vs_autenf(17) $ sexeaut1-sexeaut17 ; do i = 1 to 17;vr_egoenf(i)=0;vs_egoenf(i)='0';vr_autenf(i)=0;vs_autenf(i)='0';end ; nbego = 0;nbaut = 0 ; if nbenftab2 > 0 then do ; do i = 1 to nbenftab2; if vpartenf(i) = '1' then do ;* enfants de Ego ; nbego = nbego + 1 ;vr_egoenf(nbego)=i;vs_egoenf(nbego)=vsexenf(i); end ; else do ;* enfant pas de Ego ; nbaut = nbaut + 1 ;vr_autenf(nbaut)=i;vs_autenf(nbaut)=vsexenf(i); end ; end ; end ; if index(infoenfsexetot,"8") then complet=0; else if index(infoenfsexetot,"9") then complet=0; else complet=1; run; *****************************************************************; /** on commence par les enfants qui ne sont pas d'Ego*/ proc sort data = imputpage2b; by groupesimput3 nbego nbaut ; run; data imputpage2b; set imputpage2b; By groupesimput3 nbego nbaut ; retain n_ok n_miss pb; if first.nbaut then do; n_ok=1; n_miss=2; end; if complet=1 then do; num=n_ok; n_ok=n_ok+2; end; else if complet not in (1) then do; num=n_miss; n_miss=n_miss+2; end; else kk = 1 ; if last.nbaut then do; if n_ok < n_miss then pb = 1; end; run; proc sort data = imputpage2b; by groupesimput3 nbego nbaut num; run; data imputpage2b; set imputpage2b; retain sexeegodon1-sexeegodon17 sexeautdon1-sexeautdon17 'Y'; array vs_egoenf(17) $ sexeego1-sexeego17 ; array vs_egoenfdon(17) $ sexeegodon1-sexeegodon17 ; array vs_autenf(17) $ sexeaut1-sexeaut17 ; array vs_autenfdon(17) $ sexeautdon1-sexeautdon17 ; if complet = 1 then do ; do i = 1 to nbaut;vs_autenfdon(i) = vs_autenf(i);end ; if nbaut < 17 then do ;do i = nbaut+1 to 17;vs_autenfdon(i) = "Y";end ;end ; do i = 1 to nbego;vs_egoenfdon(i) = vs_egoenf(i);end ; if nbego < 17 then do ;do i = nbego+1 to 17;vs_egoenfdon(i) = "Y";end ;end ; end ; else do ; * un seul enfant ; if nbaut = 1 and vs_autenf(1) in(" ","Z") then vs_autenf(1) = vs_autenfdon(1) ; ** deux enfants ou plus, les deux premiers manquent ; else if vs_autenf(1) in(" ","Z") and vs_autenf(1) in(" ","Z") then do ; vs_autenf(1) = vs_autenfdon(1) ;vs_autenf(2) = vs_autenfdon(2) ; end ; ** deux enfants ou plus, seul le premier manque, le deuxième est de même sexe ; else if vs_autenf(1) in(" ","Z") and vs_autenf(2) = vs_autenfdon (2) then vs_autenf(1) = vs_autenfdon(1) ; ** deux enfants ou plus, seul le deuxième manque, le premier est de même sexe ; else if vs_autenf(2) in(" ","Z") and vs_autenf(1) = vs_autenfdon (1) then vs_autenf(2) = vs_autenfdon(2) ; ** deux enfants ou plus, seul le premier manque, le deuxième n est pas de même sexe ; ** Dans ce cas on inverse le sexe du premier (on impute la variable 'les deux enfants sont de même sexe') ; else if vs_autenf(1) in(" ","Z") and vs_autenf(2) NE vs_autenfdon (2) then do ; if vs_autenfdon(1) ='1' then vs_autenf(1) = '2';else vs_autenf(1) = '1'; end ; ** deux enfants ou plus, seul le deuxième manque, le premier n est pas de même sexe ; ** Dans ce cas on inverse le sexe du deuxième (on impute la variable 'les deux enfants sont de même sexe') ; else if vs_autenf(2) in(" ","Z") and vs_autenf(1) NE vs_autenfdon (1) then do ; if vs_autenfdon(2) ='1' then vs_autenf(2) = '2';else vs_autenf(2) = '1'; end ; end ; ** creation de la variable sexe des deux premiser enfants ; ** qui servira pour imputer le sexe des autres enfants ; sexe12autreenf = vs_autenf(1) ||vs_autenf(2) ; run ; ******************************************************** ** maintenant on impute les rangs 3 et plus ; proc sort data = imputpage2b; by groupesimput3 nbego nbaut sexe12autreenf ; run; data imputpage2b; set imputpage2b; By groupesimput3 nbego nbaut sexe12autreenf ; retain n_ok n_miss pb; if first.sexe12autreenf then do; n_ok=1; n_miss=2; end; if complet=1 then do; num=n_ok; n_ok=n_ok+2; end; else if complet not in (1) then do; num=n_miss; n_miss=n_miss+2; end; else kk = 1 ; if last.sexe12autreenf then do; if n_ok < n_miss then pb = 1; end; run; *%%% je n'ai pas regardé les PB; proc sort data = imputpage2b; by groupesimput3 nbego nbaut sexe12autreenf num; run; data imputpage2b; set imputpage2b; retain sexeegodon1-sexeegodon17 sexeautdon1-sexeautdon17 'Y'; array vs_egoenf(17) $ sexeego1-sexeego17 ; array vs_egoenfdon(17) $ sexeegodon1-sexeegodon17 ; array vs_autenf(17) $ sexeaut1-sexeaut17 ; array vs_autenfdon(17) $ sexeautdon1-sexeautdon17 ; if complet = 1 then do ; do i = 1 to nbaut;vs_autenfdon(i) = vs_autenf(i);end ; if nbaut < 17 then do ;do i = nbaut+1 to 17;vs_autenfdon(i) = "Y";end ;end ; do i = 1 to nbego;vs_egoenfdon(i) = vs_egoenf(i);end ; if nbego < 17 then do ;do i = nbego+1 to 17;vs_egoenfdon(i) = "Y";end ;end ; end ; else if nbaut > 2 then do ; * normalement on n a plus a imputer que les enfants de rang 3 et plus ; do i = 3 to nbaut ; if vs_autenf(i) in(" ","Z") then vs_autenf(i) = vs_autenfdon(i) ; end ; end ; run ; ****************************verification****************************************; data autenfb ; set imputpage2b (keep = sexeaut1-sexeaut17 nbaut num) ; array vs_autenf(17) sexeaut1-sexeaut17 ; if nbaut = 0 then delete ; else do ; do i = 1 to nbaut ; sexenf = vs_autenf(i) ;output ; end ; end ; run ; /* proc freq data = autenfb ; table sexenf ; run ;*29 enfants n'ont pas été imputés; */ /******************* correction des cas problématiques ****************************/ *(num = 2 toujours, donc pas de donneur) ; data imputpage2b; set imputpage2b; array vs_autenf(17) $ sexeaut1-sexeaut17 ; if nbaut > 0 then do ; do i = 1 to nbaut ; if vs_autenf(i) in("0","Y"," ","Z") then do ; alea = ranuni(3) ;if alea < .4878 then vs_autenf(i) = '2';else vs_autenf(i) = '1' ; end ; end ; end ; run ; ** ultime verif ; data autenfb ; set imputpage2b (keep = sexeaut1-sexeaut17 nbaut num) ; array vs_autenf(17) sexeaut1-sexeaut17 ; if nbaut = 0 then delete ; else do ; do i = 1 to nbaut ; sexenf = vs_autenf(i) ;output ; end ; end ; run ; /* proc freq data = autenfb ; table sexenf ; run ;* => OK; */ proc delete data=autenfb; run; ***************************************************************** ** on continue avec les enfants d'Ego ; proc sort data = imputpage2b; by groupesimput3 nbaut nbego ; run; data imputpage2b; set imputpage2b; By groupesimput3 nbaut nbego ; retain n_ok n_miss pb; if first.nbego then do; n_ok=1; n_miss=2; end; if complet=1 then do; num=n_ok; n_ok=n_ok+2; end; else if complet not in (1) then do; num=n_miss; n_miss=n_miss+2; end; else kk = 1 ; if last.nbego then do; if n_ok < n_miss then pb = 1; end; run; proc sort data = imputpage2b; by groupesimput3 nbaut nbego num; run; data imputpage2b; set imputpage2b; retain sexeegodon1-sexeegodon17 sexeautdon1-sexeautdon17 'Y'; array vs_egoenf(17) $ sexeego1-sexeego17 ; array vs_egoenfdon(17) $ sexeegodon1-sexeegodon17 ; array vs_autenf(17) $ sexeaut1-sexeaut17 ; array vs_autenfdon(17) $ sexeautdon1-sexeautdon17 ; if complet = 1 then do ; do i = 1 to nbego;vs_egoenfdon(i) = vs_egoenf(i);end ; if nbego < 17 then do ;do i = nbego+1 to 17;vs_egoenfdon(i) = "Y";end ;end ; do i = 1 to nbego;vs_egoenfdon(i) = vs_egoenf(i);end ; if nbego < 17 then do ;do i = nbego+1 to 17;vs_egoenfdon(i) = "Y";end ;end ; end ; else do ; * un seul enfant ; if nbego = 1 and vs_egoenf(1) in(" ","Z") then vs_egoenf(1) = vs_egoenfdon(1) ; ** deux enfants ou plus, les deux premiers manquent ; else if vs_egoenf(1) in(" ","Z") and vs_egoenf(1) in(" ","Z") then do ; vs_egoenf(1) = vs_egoenfdon(1) ;vs_egoenf(2) = vs_egoenfdon(2) ; end ; ** deux enfants ou plus, seul le premier manque, le deuxième est de même sexe ; else if vs_egoenf(1) in(" ","Z") and vs_egoenf(2) = vs_egoenfdon (2) then vs_egoenf(1) = vs_egoenfdon(1) ; ** deux enfants ou plus, seul le deuxième manque, le premier est de même sexe ; else if vs_egoenf(2) in(" ","Z") and vs_egoenf(1) = vs_egoenfdon (1) then vs_egoenf(2) = vs_egoenfdon(2) ; ** deux enfants ou plus, seul le premier manque, le deuxième n est pas de même sexe ; ** Dans ce cas on inverse le sexe du premier (on impute la variable 'les deux enfants sont de même sexe') ; else if vs_egoenf(1) in(" ","Z") and vs_egoenf(2) NE vs_egoenfdon (2) then do ; if vs_egoenfdon(1) ='1' then vs_egoenf(1) = '2';else vs_egoenf(1) = '1'; end ; ** deux enfants ou plus, seul le deuxième manque, le premier n est pas de même sexe ; ** Dans ce cas on inverse le sexe du deuxième (on impute la variable 'les deux enfants sont de même sexe') ; else if vs_egoenf(2) in(" ","Z") and vs_egoenf(1) NE vs_egoenfdon (1) then do ; if vs_egoenfdon(2) ='1' then vs_egoenf(2) = '2';else vs_egoenf(2) = '1'; end ; end ; ** creation de la variable sexe des deux premiser enfants ; ** qui servira pour imputer le sexe des autres enfants ; sexe12egoenf = vs_egoenf(1) ||vs_egoenf(2) ; run ; ******************************************************** ** maintenant on impute les rangs 3 et plus ; proc sort data = imputpage2b; by groupesimput3 nbaut nbego sexe12egoenf ; run; data imputpage2b; set imputpage2b; By groupesimput3 nbaut nbego sexe12egoenf ; retain n_ok n_miss pb; if first.sexe12egoenf then do; n_ok=1; n_miss=2; end; if complet=1 then do; num=n_ok; n_ok=n_ok+2; end; else if complet not in (1) then do; num=n_miss; n_miss=n_miss+2; end; else kk = 1 ; if last.sexe12egoenf then do; if n_ok < n_miss then pb = 1; end; run; proc sort data = imputpage2b; by groupesimput3 nbaut nbego sexe12egoenf num; run; data imputpage2b; set imputpage2b; retain sexeegodon1-sexeegodon17 sexeautdon1-sexeautdon17 'Y'; array vs_egoenf(17) $ sexeego1-sexeego17 ; array vs_egoenfdon(17) $ sexeegodon1-sexeegodon17 ; array vs_autenf(17) $ sexeaut1-sexeaut17 ; array vs_autenfdon(17) $ sexeautdon1-sexeautdon17 ; if complet = 1 then do ; do i = 1 to nbego;vs_egoenfdon(i) = vs_egoenf(i);end ; if nbego < 17 then do ;do i = nbego+1 to 17;vs_egoenfdon(i) = "Y";end ;end ; do i = 1 to nbego;vs_egoenfdon(i) = vs_egoenf(i);end ; if nbego < 17 then do ;do i = nbego+1 to 17;vs_egoenfdon(i) = "Y";end ;end ; end ; else if nbego > 2 then do ; * normalement on n a plus a imputer que les enfants de rang 3 et plus ; do i = 3 to nbego ; if vs_egoenf(i) in(" ","Z") then vs_egoenf(i) = vs_egoenfdon(i) ; end ; end ; run ; ***************************** verification************************************* ; data egoenfb ; set imputpage2b (keep = sexeego1-sexeego17 nbego num) ; array vs_egoenf(17) sexeego1-sexeego17 ; if nbego = 0 then delete ; else do ; do i = 1 to nbego ; sexenf = vs_egoenf(i) ;output ; end ; end ; run ; /* proc freq data = egoenfb ; table sexenf ; run ; */ ****************************correction ******************************************; ** 290 cas problématiques (num = 2 toujours, donc pas de donneur) ; data imputpage2b; set imputpage2b; array vs_egoenf(17) $ sexeego1-sexeego17 ; if nbego > 0 then do ; * on resout les 18 cas résiduels ; * en faisant un tirage aléatroire, sex ratio = 105 garçons pour 100 filles; do i = 1 to nbego ; if vs_egoenf(i) in("0","Y"," ","Z") then do ; alea = ranuni(3) ;if alea < .4878 then vs_egoenf(i) = '2';else vs_egoenf(i) = '1' ; end ; end ; end ; run ; ********************** ultime verif********************************************* ; data egoenfb ; set imputpage2b (keep = sexeego1-sexeego17 nbego num) ; array vs_egoenf(17) sexeego1-sexeego17 ; if nbego = 0 then delete ; else do ; do i = 1 to nbego ; sexenf = vs_egoenf(i) ;output ; end ; end ; run ; /* proc freq data = egoenfb ;table sexenf ;run ; */ proc delete data=egoenfb; run; ***************************************************************** ***************************************************************** ** on on remplit les variables initiales ; data imputpage2b; set imputpage2b; ** on separe les enfants d'Ego (couple ou non) et les autres ; array vsexenf(17) $ E13_14sexe1 - E13_14sexe17 ; array vsexenf_i(17) $1 E13_14sexe_i1 - E13_14sexe_i17 ;* variables a imputer ;/* %%% rajouté $1 */ array vpartenf(17) $ E13_14part1 - E13_14part17 ; ** on cree les enfants de Ego : vr pour le rang (parmi tous les enfants) et vs pour le sexe ; array vr_egoenf(17) rangego1-rangego17 ; array vs_egoenf(17) $ sexeego1-sexeego17 ; array vr_autenf(17) rangaut1-rangaut17 ; array vs_autenf(17) $ sexeaut1-sexeaut17 ; do i = 1 to 17;vsexenf_i(i) = vsexenf(i) ;end ; if nbego > 0 then do ; do i = 1 to nbego;* enfants de Ego ; vsexenf_i(vr_egoenf(i)) = vs_egoenf(i); end ; end ; if nbaut > 0 then do ; do i = 1 to nbaut;* autres enfants ; vsexenf_i(vr_autenf(i)) = vs_autenf(i); end ; end ; run ; /* proc freq data=imputpage2b; table E13_14sexe_i1 - E13_14sexe_i17/ missing;run; */ /****************************************************************************/ /******on copie les nouvelles informations dans la base imputpage2****/ * On en profite pour supprimer quelques variables inutiles ; data imputpage2;set imputpage2b; drop rangego1-rangego17 sexeego1-sexeego17 rangaut1-rangaut17 sexeaut1-sexeaut17 andon1-andon22 an1-an22 rang1-rang22 anaienf1-anaienf17 sexeautdon1-sexeautdon17 sexeegodon1-sexeegodon17 ; data imputpage2;set imputpage2;run ; /**************************************************************************************/ /**************************************************************************************/ /**************************************************************************************/ /**************************************************************************************/ /**************************************************************************************/ /**************************************************************************************/ /**************************************************************************************/ /**************************************************************************************/ /**************************************************************************************/ /**************************************************************************************/ /**************************************************************************************/ /**************************************************************************************/ /**************************************************************************************/ /**************************************************************************************/ /*** ***/ /*** creation de la table enfant ***/ /*** ***/ /**************************************************************************************/ /**************************************************************************************/ /**************************************************************************************/ /**************************************************************************************/ /**************************************************************************************/ /**************************************************************************************/ /**************************************************************************************/ /**************************************************************************************/ /**************************************************************************************/ /**************************************************************************************/ /**************************************************************************************/ /**************************************************************************************/ /*on pondere avec poidsind. On devrait corriger pour les orphelins, les enfants de parent séparés etc.mais on laisse ça à d'autres On ne tient compte que du sexe et de l'âge On pourrait tenir compte du milieu social de la survie des autres enfants ainsi que de l age au depart de chez les parents mais l'information est de tout emanière fortement perturbée par l absence de question */ /* Variables présentes dans imputpage2 : De 1 à 17 pour E13_14 E13_14agad1 Num. 8 E13_14anai1 Num. 8 E13_14cpart1 Texte 1 E13_14cpart_i1 Texte 1 E13_14part1 Texte 1 E13_14sexe1 Texte 1 E13_14sexe_i1 Texte 8 E14agdep1 Num. 8 c_autlgt1 Num. 8 c_tpslgt1 Num. 8 cabbi_enf1 Texte 10 dateenf17 Num. 8 e14reg17 Texte 2 e14resid17 Texte 1 imput17 Texte 1 infoenfhlog17 Num. 8 infoenflog17 Num. 8 infoenfnaiss17 Texte 1 infoenfsexe17 Texte 1 loca17 Texte 7 partcpart17 Texte 200 De 1 à 7 pour Q14 Q14agad_141_X Texte 2 Q14agdep_141_X Texte 2 Q14anai_141_X Texte 4 Q14cpart_141_X Texte 2 Q14dep_141_X Texte 2 Q14dom_141_X Texte 1 Q14part_141_X Texte 2 Q14sexe_141_X Texte 2 */ /*on garde que les variables de imputpage2b qui nous intéressent */ data imputpage2c; set imputpage2b; keep /*divers2*/ cabefla cabefla cabbia cabbi_ca poids_ind poids_men_fam_enf /*divers2*/ CS_i Q0sexe Q1anai_i Q5sexe_c REG_CODE PARIS /*questions 11 et 12*/ Q11enfan_i Q11nb_enf_i Q11nb_enf_lgt_i Q12enfan_C_i Q12nb_enf_C_i Q12nb_enf_lgt_C_i /*variables tableau*/ nbenftab2 E13_14sexe1-E13_14sexe17 E13_14anai1-E13_14anai17 E13_14cpart1 - E13_14cpart17 E13_14sexe_i1-E13_14sexe_i17 E13_14anai_i1-E13_14anai_i17 E13_14part1 - E13_14part17 E13_14cpart_i1 - E13_14cpart_i17 E13_14agad1 - E13_14agad17 E13tpslgt1 -E13tpslgt17 E13aut_lgt1 - E13aut_lgt17 E13lgt_aut_par1 - E13lgt_aut_par17 E13lgt_autre1 - E13lgt_autre17 E13lgt_etude1 - E13lgt_etude17 E14agdep1 - E14agdep17 e14reg1-e14reg17 e14resid1-e14resid17 loca1-loca17 /*autres*/ enfdec1-enfdec17; run; /* si utilisation de bases anonymisées la variable enfdec est vide proc freq;table enfdec1-enfdec17;run; */ data enfants ; set imputpage2c; ******var non imputées*******; array v_sex(17) E13_14sexe1-E13_14sexe17; array v_anai(17) E13_14anai1-E13_14anai17; array v_cpart(17) E13_14cpart1 - E13_14cpart17 ; array v_part(17) E13_14part1-E13_14part17;***** ajout ; array v_agad(17) E13_14agad1 - E13_14agad17;***** ajout ; array v_tpslgt(17) E13tpslgt1 - E13tpslgt17;***** ajout ; array v_autlgt(17) E13aut_lgt1 - E13aut_lgt17;***** ajout ; array v_autpar(17) E13lgt_aut_par1 - E13lgt_aut_par17;***** ajout ; array v_autre(17) E13lgt_autre1 - E13lgt_autre17;***** ajout ; array v_etude(17) E13lgt_etude1 - E13lgt_etude17 ;***** ajout ; array v_agdep(17) E14agdep1 - E14agdep17 ;***** ajout ; array v_reg(17) $ e14reg1-e14reg17; array v_resid(17) $ e14resid1-e14resid17 ; array v_loca(17) $ loca1-loca17 ; array v_enfdec(17) $ enfdec1-enfdec17 ; ******var imputées*******; array v_cpart_i(17) E13_14cpart_i1-E13_14cpart_i17;***** ajout ; array v_sexe(17) $ E13_14sexe_i1-E13_14sexe_i17 ; array v_an(17) E13_14anai_i1-E13_14anai_i17 ; do i = 1 to nbenftab2 ; rang = i ; ******var non imputées*******; E13_14sexe=v_sex(i); E13_14anai=v_anai(i); E13_14part=v_part(i); E13_14cpart=v_cpart(i); E13_14agad=v_agad(i); E13tpslgt =v_tpslgt(i); E13aut_lgt=v_autlgt(i); E13lgt_aut_par=v_autpar(i); E13lgt_autre =v_autre(i); E13lgt_etude=v_etude(i); E14agdep=v_agdep(i); reg = v_reg(i) ; resid = v_resid(i) ; loca = v_loca(i) ; enfdec= v_enfdec(i); ******var imputées*******; E13_14cpart_i=v_cpart_i(i); sexe = v_sexe(i) ; an = v_an(i) ; OUTPUT ; end ; keep /*divers1*/ cabefla cabefla cabbia cabbi_ca poids_ind poids_men_fam_enf /*divers2*/ CS_i Q0sexe Q1anai_i Q5sexe_c REG_CODE PARIS /*questions 11 et 12*/ Q11enfan_i Q11nb_enf_i Q11nb_enf_lgt_i Q12enfan_C_i Q12nb_enf_C_i Q12nb_enf_lgt_C_i /*variables enfant*/ nbenftab2 rang sexe an enfdec E13_14anai E13_14sexe E13_14part E13_14cpart E13_14cpart_i E13_14agad E13tpslgt E13aut_lgt E13lgt_aut_par E13lgt_autre E13lgt_etude E14agdep reg resid loca; run ; data enfants ;set enfants; rename Q11enfan_i=E11ENFAN_i Q11nb_enf_i=E11_NB_ENF_i Q11nb_enf_lgt_i=E11_NB_ENF_LGT_i Q12enfan_C_i=E12ENFAN_C_i Q12nb_enf_C_i=E12_NB_ENF_C_i Q12nb_enf_lgt_C_i=E12_NB_ENF_LGT_C_i; run; /* proc delete data=imputpage2b imputpage2c run; */ proc sort data =enfants ; By CABEFLA rang; run; /* proc freq data = enfants ;tables nbenftab2 rang sexe an reg resid loca/missing ;run ; proc freq data = enfants_imput ;tables an /missing ;run ; */ /* NOTE: There were 359770 observations read from the data set IMPUTPAGE2. NOTE: The data set WORK.ENFANTS has 611276 observations and 9 variables.*/ ** une rustine pour les années de naissances farfelues ; /* %%% A ENLEVER quand on aura nettoyé les donneurs merdiques */ data enfants ;set enfants; *if an < 1905 or an > 2011 then an = 1960 + round (ranuni(7)*50.0) ; ** survie de l'enfant : survie_min survie_max incertain si nmin et max différents; survie_min = 1;survie_max = 0;incertain = 1 ; * logement => vivant ; if loca='logemen' then do ;survie_min = 1 ;survie_max = 1 ;incertain = 0 ;end ; * region inconnue => incertains; * region DE => décédé;* region OK => vivant ; * %%% ici rajouter l'info sur enfdec ; else do ; if reg in ("","ZZ") then do ;incertain = 1 ;survie_min = 0 ;survie_max = 1 ;end ; else if reg in ("de") or enfdec = 1 then do ; incertain = 0 ;survie_min = 0 ;survie_max = 0 ; end ; else do ;incertain = 0 ;survie_min = 1 ;survie_max = 1 ;end ; end ; * Cas toujours incertains après REG, on essaie resid ; if incertain = 1 then do ; if resid in ("","Z") then do ;incertain = 1 ;survie_min = 0 ;survie_max = 1 ;end ; else if resid in ("D") then do ;incertain = 0 ;survie_min = 0 ;survie_max = 0 ;end ; else do ;incertain = 0 ;survie_min = 1 ;survie_max = 1 ;end ; end ; if survie_max = survie_min+incertain then kk = 0 ;else kk = 1 ; run ; /* proc freq data = enfants ;tables sexe an reg resid loca kk survie_min survie_max incertain /missing ;run ; proc freq data = enfants ;tables survie_min*survie_max*incertain /list missing ;run ; */ * je calcule les moyennes pondérées de survie_min et survie_max par sexe et âge ; proc means data = enfants noprint; class sexe an ;var survie_min survie_max ; output out=survie_avant_imput ; weight poids_ind ; run ; /* proc contents data = survie_avant_imput ; run; */ data survie_avant_imput2 ;set survie_avant_imput ; if _type_=3 and _stat_= 'MEAN' ;run ; ******************************************************************************** ** donnees de survie par sexe et âge ; ** voir Tablea-II-C-4.xlsx pour plus de détails ** survivants début 2011 dans Feuil1: F3:H112; data survie ; input an survH survF ; cards ; 1905 0.00005 0.000375 1906 0.00016 0.00108 1907 0.00037 0.002055 1908 0.000715 0.003875 1909 0.001205 0.006865 1910 0.001955 0.011195 1911 0.003375 0.01786 1912 0.005555 0.02724 1913 0.00879 0.03992 1914 0.013995 0.057435 1915 0.0202 0.07746 1916 0.02738 0.100285 1917 0.037235 0.127995 1918 0.049955 0.16088 1919 0.068195 0.20241 1920 0.089865 0.246015 1921 0.113195 0.289775 1922 0.138355 0.333935 1923 0.165265 0.37679 1924 0.19543 0.419805 1925 0.225175 0.457775 1926 0.2563 0.49462 1927 0.286695 0.528875 1928 0.316825 0.56005 1929 0.3489 0.59258 1930 0.380315 0.622815 1931 0.41053 0.648355 1932 0.438855 0.67122 1933 0.46705 0.692885 1934 0.494825 0.71255 1935 0.520335 0.729735 1936 0.544115 0.74576 1937 0.565855 0.75867 1938 0.584155 0.767105 1939 0.60147 0.773735 1940 0.623045 0.784495 1941 0.64382 0.79691 1942 0.658885 0.805725 1943 0.667615 0.807905 1944 0.67571 0.806955 1945 0.70391 0.826195 1946 0.736025 0.850685 1947 0.754775 0.862115 1948 0.770095 0.870375 1949 0.7843 0.87824 1950 0.79717 0.885675 1951 0.81083 0.89376 1952 0.82301 0.901245 1953 0.831885 0.90627 1954 0.841335 0.91206 1955 0.850435 0.917195 1956 0.85927 0.921745 1957 0.867865 0.926875 1958 0.876125 0.9325 1959 0.88344 0.93663 1960 0.88981 0.939865 1961 0.89578 0.94332 1962 0.901625 0.94615 1963 0.908005 0.9496 1964 0.914555 0.9528 1965 0.919705 0.95537 1966 0.924305 0.957835 1967 0.928905 0.960005 1968 0.932995 0.962075 1969 0.9376 0.96447 1970 0.94204 0.96724 1971 0.946025 0.9695 1972 0.94954 0.97128 1973 0.95263 0.972985 1974 0.95582 0.974675 1975 0.958985 0.97671 1976 0.961925 0.97859 1977 0.96467 0.97996 1978 0.9672 0.981165 1979 0.968905 0.98216 1980 0.970475 0.983115 1981 0.97247 0.984025 1982 0.974515 0.984915 1983 0.976415 0.985695 1984 0.97786 0.98655 1985 0.97933 0.987285 1986 0.980635 0.987965 1987 0.98175 0.98862 1988 0.983095 0.989045 1989 0.984485 0.98979 1990 0.985715 0.990465 1991 0.986975 0.991125 1992 0.988355 0.991865 1993 0.98967 0.992525 1994 0.990995 0.993325 1995 0.991925 0.993905 1996 0.99367 0.99432 1997 0.99517 0.994665 1998 0.995255 0.994765 1999 0.99533 0.994855 2000 0.99541 0.994945 2001 0.99549 0.99503 2002 0.99557 0.99511 2003 0.995645 0.99519 2004 0.995725 0.99528 2005 0.995815 0.99538 2006 0.99591 0.995485 2007 0.996025 0.995615 2008 0.99618 0.99579 2009 0.99641 0.996045 2010 0.9977 0.997466667 2011 1.0 1.0 ;; run ; data survie2 ;set survie ; keep sexe an survie ; sexe = '1';survie = survH; output ; sexe = '2';survie = survF; output ; run ; proc sort data = survie2 ; by sexe an ; proc sort data = survie_avant_imput2 ; by sexe an ; /* proc contents data = survie_avant_imput2 ;run ;*/ data survie_avant_imput3 ;merge survie_avant_imput2 survie2;by sexe an ; * maintenant pour chaque sexe et âge on a survie, qui représente * la probabilité qu'ils soient vivants ; * survie_min et survie_max sont les moyennes par sexe et âge dans le fichier; * on en déduit ratio tel que si on impute une proportion ratio des incertains * comme vivants, on arrive à survie ; data survie_imput ;set survie_avant_imput3 ; keep survie ratio an sexe ; if survie_max = survie_min then ratio = .5 ; else ratio = (survie - survie_min) / (survie_max - survie_min) ; if ratio < 0 then ratio = 0 ;else if ratio > 1 then ratio = 1 ; run ; /*proc print data = survie_avant_imput3 ;run ;*/ proc sort data = enfants ;by sexe an ; data enfants ;merge enfants(in=base2) survie_imput ;by sexe an ;if base2;drop base2;run ;/*************ajout guilhem*/ data enfants ;set enfants ; * vivant = 1 pour les vivants, 2 pour les morts ; if incertain = 0 then vivant = 2 - survie_min ; * si incertains on fait un tirage selon ratio ; else do ;alea = ranuni(3) ;if alea < ratio then vivant = 1 ; else vivant = 2 ;end ; run ; /* proc freq data = enfants ;tables vivant ;run ; */ proc means data = enfants noprint; class sexe an ;var vivant ; output out=vivants_apres_imput; weight poids_ind ; run ; /* proc print data = vivants_apres_imput; where _type_=3 and _stat_= 'MEAN' ; run ; proc contents data = enfants_imput ;run ; */ /*************** on renomme certaines variables**************/ data enfants ;set enfants ; rename sexe=E13_14sexe_i an =E13_14anai_i reg = E14reg resid = E14resid vivant=E13_14_vivant_i; run; /************on garde ou on supprime la variable enfdec **************/ * vérification du filtre; %put &donnees_ano; *suppression variables temporaires + enfdec; %macro supenfdec; %if &donnees_ano=non %then %do; data enfants ; set enfants ; drop enfdec survie_min survie_max kk survie ratio alea incertain; run; %end; %else %do; data enfants ; set enfants ; drop survie_min survie_max kk survie ratio alea incertain; run; %end; %mend; %supenfdec; /*************** on copie la base dans la librairie**************/ proc sort data = enfants ;by cabefla rang ;run ; data imput.enfants; set enfants; proc delete data=enfants; run; ***************************************************************************** ** on est très content mais on n'a pas tenu compte de la CS, de l'âge au départ * ni de la survie des autres enfants ni de rien d'autre que le sexe et l'âge ; ***************************************************************************** * On rappatrie l'information dans le fichier de départ ; ** on cree un fichier au niveau individu ; data survie_enfants ; set imput.enfants (keep = CABEFLA rang E13_14_vivant_i) ; by cabefla ; array v_vivant(17) E13_14_vivant_i1-E13_14_vivant_i17; retain E13_14_vivant_i1-E13_14_vivant_i17 ; if first.cabefla then do; do i = 1 to 17;v_vivant(i) = 0 ;end ;end ; if rang ne . then v_vivant(rang) = E13_14_vivant_i ; if last.cabefla then output ; run ; /********************************************************************** base imputpage2 **********************************************************************/ proc sort data = imputpage2 ;by cabefla ;run ; data imputpage2 ;merge survie_enfants imputpage2 ;by cabefla ;run ; data imputpage2 ;set imputpage2 ; array v_vivant(17) E13_14_vivant_i1-E13_14_vivant_i17; if E13_14_vivant_i1 = . then do ; do i = 1 to 17;v_vivant(i) = . ;end ; end ; do j=1 to 17;if v_vivant(j) = 0 then v_vivant(j) = .;end; run ; * Attention je n'ai pas suffixé les variables imputées ; * Attention aux variables numérotées: _i_3 et non pas _3_i ; /**********************************************************************/ /* on copie la base dans la bibliothèque*/ data imput.imputpage2 ;set imputpage2 ; /*suppression des bases de la work */ Proc delete data= imputpage2 survie survie2 survie_avant_imput survie_avant_imput2 survie_avant_imput3 survie_enfants survie_imput vivants_apres_imput ; Run ; /**********************************************************************/ /* verification nombre d'enfants dans la base imputpage2*/ data _null_; set imput.imputpage2 end =dernier; retain compt 0; array tab (17) E13_14anai_i1 - E13_14anai_i17; do n=1 to 17; if tab(n) not in (0 . 9999) then compt=compt+1; end; if dernier then put compt=; run; /* abcd */ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /*** ***/ /*** imputations page 3 ***/ /*** ***/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /*********************création d'une base réduite***********************/ data imputpage3; set imput.imputpage2; keep /*var EFL */ CABEFLA ageego q0sexe /*var EFL imputées*/ q1anai_i q3couple_i q7pacs_i q8mari_i q9tps_logr_i Q11ENFAN_i /* var EAR*/ cs dipl empl matr SITUAT_R /*indicateurs*/ /*var discriminantes*/ regroupCS regroupCSb groupage groupageb groupagec groupesimput groupesimput2 groupesimput3 groupesimput4; run; /*on récupère des variables du FPR*/ data transitFPR; set FPR.efl_individu; keep CABEFLA Q23CS_P Q23GS_P Q17CS_M Q17GS_M; proc sort; by CABEFLA; proc sort data=imputpage3; by CABEFLA; data imputpage3; merge imputpage3 transitFPR;by CABEFLA; proc delete data=transitFPR; run; /*on crée de nouvelles variables indicatrices*/ data imputpage3; set imputpage3; length csperemere $4; cspere=Q23CS_P; csmere=Q17CS_M; csperemere=cats(cspere,csmere); run; /*Imputations professions des parents*/ data imputpage3; set imputpage3; cspere_i=cspere; csmere_i=csmere; run; /* proc freq;table cspere csmere csperemere;run; */ /* *les non réponses; data test; set imputpage3; if cspere not in ("" "ZZ") then pere=1; else if cspere="ZZ" then pere=0; if csmere not in ("" "ZZ") then mere=1; else if csmere="ZZ" then mere=0; proc freq; table mere*pere/norow nocol nopercent missing; proc delete data=test; run; */ /************************************************************************/ /*On commence par imputer les cas où il manque seulement la prof du père*/ Proc sort data=imputpage3; By groupesimput3 csmere; Run; data imputpage3; set imputpage3; By groupesimput3 csmere; retain n_ok n_miss pb; if first.csmere then do; n_ok=1; n_miss=2; end; if cspere not in ("ZZ" "") then do; num=n_ok; n_ok=n_ok+2; end; else if cspere in ("ZZ") then do; num=n_miss; n_miss=n_miss+2; end; else kk=1; if last.csmere then do; if n_ok < n_miss then pb = 1; end; run; Proc sort data=imputpage3; By groupesimput3 csmere num;/*on ajoute num pour eviter les effets de bord*/ Run; data imputpage3; set imputpage3; retain reserve;/*retain est fait sur le vecteur: la reserve*/ /*si il y a une reponse à mari on remplit la réserve*/ if cspere not in ("" "ZZ") then reserve=cspere; /*si la réponse à année mari est vide on va piocher dans la réserve*/ if cspere in ("ZZ") and csmere ne "ZZ" then cspere_i=reserve; /*on impute */ drop reserve num n_miss n_ok pb kk; run; /************************************************************************/ /*On impute ensuite les cas où il manque seulement la prof de la mère*/ Proc sort data=imputpage3; By groupesimput3 cspere; Run; data imputpage3; set imputpage3; By groupesimput3 cspere; retain n_ok n_miss pb; if first.cspere then do; n_ok=1; n_miss=2; end; if csmere not in ("ZZ" "") then do; num=n_ok; n_ok=n_ok+2; end; else if csmere in ("ZZ") then do; num=n_miss; n_miss=n_miss+2; end; else kk=1; if last.cspere then do; if n_ok < n_miss then pb = 1; end; run; Proc sort data=imputpage3; By groupesimput3 cspere num;/*on ajoute num pour eviter les effets de bord*/ Run; data imputpage3; set imputpage3; retain reserve;/*retain est fait sur le vecteur: la reserve*/ /*si il y a une reponse à mari on remplit la réserve*/ if csmere not in ("ZZ" "") then reserve=csmere; /*si la réponse à année mari est vide on va piocher dans la réserve*/ if csmere in ("ZZ") and cspere ne "ZZ" then csmere_i=reserve; /*on impute */ drop reserve num n_miss n_ok pb kk; run; /************************************************************************/ /*On impute ensuite les cas où il manque la prof de la mère et celle du père*/ Proc sort data=imputpage3; By groupesimput3; Run; data imputpage3; set imputpage3; By groupesimput3; retain n_ok n_miss pb; if first.groupesimput3 then do; n_ok=1; n_miss=2; end; if csmere not in ("ZZ" "") and cspere not in ("ZZ" "") then do; num=n_ok; n_ok=n_ok+2; end; else if csmere = "ZZ" and cspere = "ZZ" then do; num=n_miss; n_miss=n_miss+2; end; else num=1000; if last.groupesimput3 then do; if n_ok < n_miss then pb = 1; end; run; Proc sort data=imputpage3; By groupesimput3 num;/*on ajoute num pour eviter les effets de bord*/ Run; data imputpage3; set imputpage3; retain reserve reserveb;/*retain est fait sur le vecteur: la reserve*/ /*si il y a une reponse à mari on remplit la réserve*/ if csmere not in ("ZZ" "") and cspere not in ("ZZ" "") then do; reserve=csmere; reserveb=cspere; end; /*si la réponse à année mari est vide on va piocher dans la réserve*/ else if csmere = "ZZ" and cspere = "ZZ" then do; csmere_i=reserve; cspere_i=reserveb; end; drop reserve reserveb num n_miss n_ok pb; run; /********************************verification****************************************/ /* proc freq data=imputpage3; table cspere_i cspere csmere csmere_i;run; proc freq data=imputpage3; table cspere*cspere_i csmere*csmere_i /norow nocol nopercent ; run; */ /**************************************************************************/ /*on renomme les variables comme celles du FPR*/ data imputpage3; set imputpage3; rename cspere_i=Q23CS_P_i csmere_i=Q17CS_M_i; run; /**************************************************************************/ /* on merge avec la base imputpage3*/ data imputpage3; set imputpage3; keep CABEFLA Q23CS_P_i Q17CS_M_i; proc sort ; by CABEFLA; proc sort data=imput.imputpage2;by CABEFLA; data imput.imputpage3; merge imput.imputpage2 imputpage3; by CABEFLA; run; proc delete data=imputpage3;run; /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /*** ***/ /*** imputations page 4 ***/ /*** ***/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /**********************************************************************/ /*base imputée*/ %let base_complete=imput.imputpage3; /*bases temporaires*/ %let imp1=base_imp1; %let imp2=base_imp2; /*********************création d'une base réduite*********************************/ /* */ data &imp1; set &base_complete; keep /*var EFL */ CABEFLA ageego q0sexe Q29TPS Q30TPSM Q31LGT_SEC Q31LGT_sec_fam Q31LGT_sec_trav Q31LGT_sec_et Q31LGT_sec_vac Q31LGT_sec_aut Q32NATAUTLGT Q34TPSAUTLGT Q35PERSAUTLGT_ego Q35PERSAUTLGT_c Q35PERSAUTLGT_fam Q35PERSAUTLGT_hfam Q35PERSAUTLGT_pers Q36PROPAUTLGT_ego Q36PROPAUTLGT_c Q36PROPAUTLGT_enf Q36PROPAUTLGT_par Q36PROPAUTLGT_autfam Q36PROPAUTLGT_ami Q36PROPAUTLGT_aut /*var EFL imputées*/ q1anai_i q3couple_i q7pacs_i q8mari_i q9tps_logr_i Q11ENFAN_i /*Q11ENFAN_i*/ /* var EAR*/ cs dipl empl matr SITUAT_R /*var discriminantes*/ regroupCS regroupCSb groupage groupageb groupagec groupesimput groupesimput2 groupesimput3 groupesimput4 gimput1 gimput2 gimput3 gimput4; /* nouvelles variables discriminantes (on enleve le sexe)*/ gimput1=substr(groupesimput,2,3); *groupage,regroupCS; gimput2=substr(groupesimput2,2,3); *groupageb,regroupCS; gimput3=substr(groupesimput3,2,3); *groupage,regroupCS avec regroupements; gimput4=substr(groupesimput4,2,3); *groupagec,regroupCSb; run; /********************création de formats temporaires********************/ /* ces formats ont été utilisés lors de la conception du programme*/ /* options fmtsearch=(work); proc format; value $q31a "1"="conjoint-famille" "2"="travail" "3"="études" "4"="loisirs-vacances" "5"="autres motifs" "6","7","8"="plusieurs motifs"; value $q31b "1"="conjoint-famille" "2"="travail" "3"="études" "4"="loisirs-vacances" "5"="autres motifs" "6"="loisirs vacances + conjoint-famille " "7"="travail + autres" "8"="autres combinaisons de motifs"; value $q35a "1"="ego seul" "2"="conjoint seul" "3"="famille" "4"="hors famille" "5"="personne" "6","7","8"="plusieurs reponses"; value $q35b "1"="ego seul " "2"="conjoint seul" "3"="famille" "4"="hors famille" "5"="personne" "6"="ego + (conjoint ou famille)" "7"="conjoint + famille" "8"="autres compositions"; value $q36a "01"="ego seul " "02"="conjoint seul" "03"="enfant seul" "04"="parents/beaux parents" "05"="autres membres famille" "06"="ami" "07"="autres" "08","09","10","11"="reponses multiples"; value $q36b "01"="ego seul" "02"="conjoint seul" "03"="enfant seul" "04"="parents/beaux parents" "05"="autres membres famille" "06"="ami" "07"="autres" "08"="ego + parents" "09"="ego + conjoint" "10"="conjoint + parents" "11"="plusieurs réponses"; value $q35q36_ "1"="logement d'égo" "2"="logement du conjoint" "3"="logement du couple (avec ou sans enfants)" "4"="logement d'autres membres famille" "5"="logement hors famille et amis" "6"="autres cas"; run; */ /**********************************************************************/ /*** ***/ /*** imputations page 4 ***/ /*** ***/ /**********************************************************************/ /* Pour chaque questions imputées on calcule au préalable le nombre de donneurs et le nombre de receveurs, la variable pb permet de connaitre le nombre de groupes dans lequel il manque des donneurs. Le programme à lancer est le suivant: proc freq; table pb; run; proc print;where pb=1; var vdiscri taille_groupe donneurs receveurs donneurs_manquants; run; */ /******************************************************** imputation q29_Etps ********************************************************/ /* création de vdiscri */ data &imp1; set &imp1; vdiscri= cats(q3couple_i,regroupCS,groupageb); Proc sort data=&imp1 ;By vdiscri CABEFLA;run; /*on compare le nombre de donneurs et de receveurs*/ data &imp1 ; set &imp1; By vdiscri; retain n_ok n_miss a b c; if first.vdiscri then do; n_ok=1; n_miss=2; a=0;b=0;c=0; end; a=a+1; if Q29TPS ne "Z" then do; num=n_ok; n_ok=n_ok+2; b=b+1;end; else if Q29TPS ="Z" then do; num=n_miss ; n_miss=n_miss+2; c=c+1;end; else kk = 1 ; if last.vdiscri then do; if n_ok +1 < n_miss then do ; pb = 1; taille_groupe=a; donneurs=b; receveurs=c; donneurs_manquants=receveurs-donneurs; end; else pb=0; end; drop a b c n_miss n_ok kk; run; /* *groupes pour lesquels il manque des donneurs; proc freq; table pb; run; proc print;where pb=1; var vdiscri taille_groupe donneurs receveurs donneurs_manquants; run; */ * imputation; Proc sort data=&imp1; By vdiscri num; data &imp1 ; set &imp1; Q29TPS_i=Q29TPS; retain reserveQ29TPS; if Q29TPS ne "Z" then reserveQ29TPS= Q29TPS; if Q29TPS ="Z" then Q29TPS_i =reserveQ29TPS; drop reserveQ29TPS num pb vdiscri taille_groupe donneurs receveurs donneurs_manquants; run; /* proc freq ; table Q29TPS*Q29TPS_i /nopercent nocol norow;run; */ /******************************************************** imputation Q30TPSM ********************************************************/ /* création de vdiscri */ data &imp1; set &imp1; vdiscri= cats(Q29TPS_i,q3couple_i,gimput3); Proc sort data=&imp1 ;By vdiscri CABEFLA;run; /*on compare le nombre de donneurs et de receveurs*/ data &imp1 ; set &imp1; By vdiscri; retain n_ok n_miss a b c; if first.vdiscri then do; n_ok=1; n_miss=2; a=0;b=0;c=0; end; a=a+1; if Q30TPSM ne "Z" then do; num=n_ok; n_ok=n_ok+2; b=b+1;end; else if Q30TPSM ="Z" then do; num=n_miss ; n_miss=n_miss+2; c=c+1;end; else kk = 1 ; if last.vdiscri then do; if n_ok +1 < n_miss then do ; pb = 1; taille_groupe=a; donneurs=b; receveurs=c; donneurs_manquants=receveurs-donneurs; end; else pb=0; end; drop a b c n_miss n_ok kk; run; /* imputation */ Proc sort data=&imp1; By vdiscri num; data &imp1 ; set &imp1; Q30TPSM_i=Q30TPSM; retain reserveQ30TPSM; if Q30TPSM ne "Z" then reserveQ30TPSM= Q30TPSM; if Q30TPSM ="Z" then Q30TPSM_i =reserveQ30TPSM; drop reserveQ30TPSM num pb vdiscri taille_groupe donneurs receveurs donneurs_manquants; run; /* proc freq ; table Q30TPSM*Q30TPSM_i /nopercent nocol norow;run; */ /******************************************************** imputation Q31LGT_SEC ********************************************************/ /* NOTE: Dans un premier temps on impute l'effectif de personnes en situation de multi-résidence, puis dans un second temps on impute les motifs d'utilisation de cet autre logement. Pour imputer les motifs de l'autre logement tout en gardant une cohérence au sein du bloc nous allons d'abord imputer la variable q31 (que nous créons) qui regroupe les réponses uniques et les réponses multiples aux motifs d'utilisation de l'autre logement. Une fois imputée nous utiliserons cette variable comme variable discriminante pour les imputations des non réponses aux questions du bloc.*/ /* création de vdiscri */ data &imp1; set &imp1; vdiscri= cats(Q29TPS_i,q3couple_i,Q11ENFAN_i,regroupCS,gimput3); Proc sort data=&imp1 ;By vdiscri CABEFLA;run; /*on compare le nombre de donneurs et de receveurs*/ data &imp1 ; set &imp1; By vdiscri; retain n_ok n_miss a b c; if first.vdiscri then do; n_ok=1; n_miss=2; a=0;b=0;c=0; end; a=a+1; if Q31LGT_SEC ne "Z" then do; num=n_ok; n_ok=n_ok+2; b=b+1;end; else if Q31LGT_SEC ="Z" then do; num=n_miss ; n_miss=n_miss+2; c=c+1;end; else kk = 1 ; if last.vdiscri then do; if n_ok +1 < n_miss then do ; pb = 1; taille_groupe=a; donneurs=b; receveurs=c; donneurs_manquants=receveurs-donneurs; end; else pb=0; end; drop a b c n_miss n_ok kk; /* imputation */ Proc sort data=&imp1; By vdiscri num; data &imp1 ; set &imp1; Q31LGT_SEC_i=Q31LGT_SEC; retain reserveQ31LGT_SEC; if Q31LGT_SEC ne "Z" then reserveQ31LGT_SEC= Q31LGT_SEC; if Q31LGT_SEC ="Z" then Q31LGT_SEC_i =reserveQ31LGT_SEC; drop reserveQ31LGT_SEC num pb vdiscri taille_groupe donneurs receveurs donneurs_manquants; run; /* proc freq ; table Q31LGT_sec*Q31LGT_sec_i/norow nocol nopercent;run; *39 994 enquêtés; */ /******************************************************************* creation variables regroupées pour les questions 31 35 36 *******************************************************************/ /*on ne garde que les enquêtés ayant répondu oui à la question 31 */ data &imp2; set &imp1 (where= (Q31LGT_SEC_i ="1")); /*création d'une nouvelle variable Q31 */ length q31 $1;compt_q31=0; array tabq31_1(5) $ Q31lgt_sec_fam Q31lgt_sec_trav Q31lgt_sec_et Q31lgt_sec_vac Q31lgt_sec_aut; array tabq31_2(5)$1 a1-a5 ("1" "2" "3" "4" "5"); do n=1 to 5;if tabq31_1(n)="1" then compt_q31=compt_q31 +1 ;end; if compt_q31=0 then q31="Z"; if compt_q31=1 then do m=1 to 5; if tabq31_1(m)="1" then Q31=tabq31_2(m) ; end; else if compt_q31>1 then do; if Q31lgt_sec_vac="1" and Q31lgt_sec_fam="1" then Q31="6"; else if Q31lgt_sec_trav="1" then Q31="7"; else Q31="8"; end; drop n m compt_q31 a1-a5; /*création d'une nouvelle variable Q35 */ compt_q35=0; array tabq35_1(5) $ Q35persautlgt_ego Q35persautlgt_c Q35persautlgt_fam Q35persautlgt_hfam Q35persautlgt_pers; array tabq35_2(5) $15 b1-b5("1" "2" "3" "4" "5"); do o=1 to 5; if tabq35_1(o)="1" then compt_q35=compt_q35+1;end; if compt_q35=0 then q35="Z"; else if compt_q35=1 then do p=1 to 5; if tabq35_1(p)="1" then Q35=tabq35_2(p); end; else if compt_q35=2 then do; if (Q35persautlgt_ego="1" and Q35persautlgt_fam="1") or (Q35persautlgt_ego="1" and Q35persautlgt_c="1")then Q35="6"; else if Q35persautlgt_c="1" and Q35persautlgt_fam="1" then Q35="7"; else Q35="8"; end; else if compt_q35>2 then Q35="8"; /*création d'une nouvelle variable q36 */ compt_q36=0; length Q36 $2; array tabq36_1(7) $ Q36propautlgt_ego Q36propautlgt_c Q36propautlgt_enf Q36propautlgt_par Q36propautlgt_autfam Q36propautlgt_ami Q36propautlgt_aut; array tabq36_2(7) $15 c1-c7("01" "02" "03" "04" "05" "06" "07"); do q=1 to 7; if tabq36_1(q)="1" then compt_q36=compt_q36+1;end; if compt_q36=0 then q36="ZZ"; if compt_q36=1 then do r=1 to 7; if tabq36_1(r)="1" then Q36=tabq36_2(r); end; else if compt_q36=2 then do; if Q36propautlgt_ego="1" and Q36propautlgt_par="1" then q36="08"; else if Q36propautlgt_ego="1" and Q36propautlgt_c="1" then q36="09"; else if Q36propautlgt_c="1" and Q36propautlgt_par="1" then q36="10"; else q36="11"; end; else if compt_q36>2 then q36="11"; drop b1-b5 c1-c7 o p q r compt_q35 compt_q36; /*creation de la variable q35q36 qui synthétise l'information contenue dans Q35 et Q36*/ if q35 in ("5" "1" ) and q36 ="01" then q35q36="1"; else if q35 ="2" and q36 in ("01" "02") then q35q36="2"; else if q35 ="3" and q36 in ("01" "04") then q35q36="4"; else if q35 ="5" and q36="04" then q35q36="4"; else if q35 in("4" "5") and q36="07" then q35q36="5"; else if q36="01" and Q35persautlgt_ego="1" then do; if Q35persautlgt_c="1" and Q35persautlgt_fam ne "1" and Q35persautlgt_hfam ne "1" and Q35persautlgt_pers ne "1" then q35q36="3"; if Q35persautlgt_c="1" and Q35persautlgt_fam="1" and Q35persautlgt_hfam ne "1" and Q35persautlgt_pers ne "1" then q35q36="3"; end; else if q35 ne "" and q36 ne "" then q35q36="6"; run; /* proc freq; table q31 q35 q36 q35q36; format q31 $q31a. q35 $q35a. q36 $q36a. q35q36 $q35q36_.; run; */ /************************************************************ repondants et non repondants aux questions Q32 Q35 et Q36 *************************************************************/ /* * creation indicateur de réponse Q32 et Q35Q36; data temp; set &imp2 ; if Q31lgt_sec_fam ="Z" then q31="Z"; else q31="R"; if q35q36 ="" then q35="Z"; else q35="R"; if Q32natautlgt ="Z" then q32="Z"; else q32="R"; proc freq ;table q35*q32/norow nocol nopercent; run; * on regroupe ces variables; data temp; set temp ; length discri $4; if q35="R" and q32="R" then discri="R"; else if q35="R" and q32 ne "R" then discri="Q35R"; else if q35 ne "R" and q32 = "R" then discri="Q32R"; else if q35 ne "R" and q32 ne "R" then discri="0R"; proc freq;table discri; proc freq;table q31*discri/norow nocol nopercent; proc delete data=temp; run; */ /******************************************************** imputation var regroupée 31 ********************************************************/ /* on sépare la base en 4 variables discriminantes - ceux qui n'ont pas répondu aux questions 32 et 35 age + CSP - ceux qui ont seulement répondu à la question 32 Q32natautlgt+ age + CSP - ceux qui ont seulement répondu à la question 35 q35q36 + age + CSP - ceux qui ont répondu aux questions 32 et 35 Q32natautlgt + q35q36 + age + CSP */ data base_a ; set &imp2; where Q31LGT_sec_fam ne "Z" or (Q31LGT_sec_fam="Z" and q35q36="" and Q32natautlgt="Z"); data base_b ; set &imp2; where (Q31LGT_sec_fam ne "Z" and q35q36 ne "" and Q32natautlgt ne "Z") or (Q31LGT_sec_fam ne "Z" and Q32natautlgt ne "Z" and q35q36="") or (Q31LGT_sec_fam = "Z" and Q32natautlgt ne "Z" and q35q36=""); data base_c ; set &imp2; where (Q31LGT_sec_fam ne "Z" and q35q36 ne "" and Q32natautlgt ne "Z") or (Q31LGT_sec_fam ne "Z" and Q32natautlgt = "Z" and q35q36 ne "") or (Q31LGT_sec_fam = "Z" and Q32natautlgt = "Z" and q35q36 ne ""); data base_d ; set &imp2; where (Q31LGT_sec_fam ne "Z" and q35q36 ne "" and Q32natautlgt ne "Z") or (Q31LGT_sec_fam = "Z" and q35q36 ne "" and Q32natautlgt ne "Z") ; run; /**** Base A ********/ data base_a ; set base_a; vdiscri=cats(gimput3,Q11ENFAN_i,q3couple_i); Proc sort ;By vdiscri CABEFLA; run; /*on compare le nombre de donneurs et de receveurs*/ data base_a ; set base_a; By vdiscri; retain n_ok n_miss a b c; if first.vdiscri then do; n_ok=1; n_miss=2; a=0;b=0;c=0; end; a=a+1; if q31 ne "Z" then do; num=n_ok; n_ok=n_ok+2; b=b+1;end; else if q31 ="Z" then do; num=n_miss ; n_miss=n_miss+2; c=c+1;end; else kk = 1 ; if last.vdiscri then do; if n_ok +1 < n_miss then do ; pb = 1; taille_groupe=a; donneurs=b; receveurs=c; donneurs_manquants=receveurs-donneurs; end; else pb=0; end; drop a b c n_miss n_ok kk; run; /*on impute*/ Proc sort data= base_a; By vdiscri num; data base_a; set base_a; q31_i=q31; retain reserveq31; if q31 ne "Z" then reserveq31= q31; if q31="Z" then q31_i =reserveq31; drop reserveq31 num pb vdiscri taille_groupe donneurs receveurs donneurs_manquants; run; /* proc freq; table q31*q31_i /norow nocol nopercent;run; */ /****** base B*****/ data base_b ; set base_b; vdiscri=cats(gimput3,Q32natautlgt,q3couple_i); Proc sort ;By vdiscri CABEFLA;run; data base_b ;set base_b; By vdiscri; retain n_ok n_miss a b c; if first.vdiscri then do; n_ok=1; n_miss=2; a=0;b=0;c=0; end; a=a+1; if q31 ne "Z" then do; num=n_ok; n_ok=n_ok+2; b=b+1;end; else if q31 ="Z" then do; num=n_miss ; n_miss=n_miss+2; c=c+1;end; else kk = 1 ; if last.vdiscri then do; if n_ok +1 < n_miss then do ; pb = 1; taille_groupe=a; donneurs=b; receveurs=c; donneurs_manquants=receveurs-donneurs; end; else pb=0; end; drop a b c n_miss n_ok kk; run; *on impute; Proc sort data= base_b; By vdiscri num; data base_b; set base_b; q31_i=q31; retain reserveq31; if q31 ne "Z" then reserveq31= q31; if q31="Z" then q31_i =reserveq31; drop reserveq31 num pb vdiscri taille_groupe donneurs receveurs donneurs_manquants; run; /* proc freq; table q31*q31_i /norow nocol nopercent;run; */ /***** Base C ****/ data base_c ; set base_c; vdiscri=cats(gimput3,q35q36,q3couple_i); /* SITUAT_R iletud Q11ENFAN_i*/ Proc sort ;By vdiscri CABEFLA;run; data base_c ;set base_c; By vdiscri; retain n_ok n_miss a b c; if first.vdiscri then do; n_ok=1; n_miss=2; a=0;b=0;c=0; end; a=a+1; if q31 ne "Z" then do; num=n_ok; n_ok=n_ok+2; b=b+1;end; else if q31 ="Z" then do; num=n_miss ; n_miss=n_miss+2; c=c+1;end; else kk = 1 ; if last.vdiscri then do; if n_ok +1 < n_miss then do ; pb = 1; taille_groupe=a; donneurs=b; receveurs=c; donneurs_manquants=receveurs-donneurs; end; else pb=0; end; drop a b c n_miss n_ok kk; run; /*on impute*/ Proc sort data= base_c; By vdiscri num; data base_c; set base_c; q31_i=q31; retain reserveq31; if q31 ne "Z" then reserveq31= q31; if q31="Z" then q31_i =reserveq31; drop reserveq31 num pb vdiscri taille_groupe donneurs receveurs donneurs_manquants; run; /* proc freq; table q31*q31_i /norow nocol nopercent;run; */ /**** Base D *******/ data base_d ; set base_d; vdiscri=cats(gimput3,Q32natautlgt,q35q36,q3couple_i); Proc sort;By vdiscri CABEFLA;run; data base_d ;set base_d; By vdiscri; retain n_ok n_miss a b c; if first.vdiscri then do; n_ok=1; n_miss=2; a=0;b=0;c=0; end; a=a+1; if q31 ne "Z" then do; num=n_ok; n_ok=n_ok+2; b=b+1;end; else if q31 ="Z" then do; num=n_miss ; n_miss=n_miss+2; c=c+1;end; else kk = 1 ; if last.vdiscri then do; if n_ok +1 < n_miss then do ; pb = 1; taille_groupe=a; donneurs=b; receveurs=c; donneurs_manquants=receveurs-donneurs; end; else pb=0; end; drop a b c n_miss n_ok kk; run; /*on impute*/ Proc sort data= base_d; By vdiscri num; data base_d; set base_d; q31_i=q31; retain reserveq31; if q31 ne "Z" then reserveq31= q31; if q31="Z" then q31_i =reserveq31; drop reserveq31 num pb vdiscri taille_groupe donneurs receveurs donneurs_manquants; run; /* proc freq; table q31*q31_i /norow nocol nopercent;run; */ /* fusion des bases A B C D */ proc sort data=base_a; by CABEFLA; proc sort data=base_b; by CABEFLA; proc sort data=base_c; by CABEFLA; proc sort data=base_d; by CABEFLA; data &imp2; merge base_a base_b base_c base_d; by CABEFLA; proc delete data=base_a base_b base_c base_d; run; /* proc freq data=&imp2; table q31*q31_i /nocol norow nopercent missing;run; proc freq data=&imp2; table q31*q31_i /nocol norow nopercent missing;format q31 $q31a. q31_i $q31a.;run; proc freq data=&imp2; table q31;format q31 $q31b. q31_i $q31b.;run; proc freq data=&imp2; table q31_i;format q31 $q31a. q31_i $q31a.;run; */ /******************************************************************* imputation motifs d'utilisation *******************************************************************/ /* pour les réponses uniques on se base sur la variable imputée q31_i */ data &imp2 ; set &imp2 ; if Q31lgt_sec_fam ne "Z" then Q31lgt_sec_fam_t=Q31lgt_sec_fam; else do; if q31_i="1" then Q31lgt_sec_fam_t="1"; else if q31_i in ("2" "3" "4" "5") then Q31lgt_sec_fam_t="2"; else if q31_i="6" then Q31lgt_sec_fam_t="1"; else Q31lgt_sec_fam_t="Z"; end; if Q31lgt_sec_trav ne "Z" then Q31lgt_sec_trav_t=Q31lgt_sec_trav; else do; if q31_i="2" then Q31lgt_sec_trav_t="1"; else if q31_i in ("1" "3" "4" "5") then Q31lgt_sec_trav_t="2"; else if q31_i="7" then Q31lgt_sec_trav_t="1"; else Q31lgt_sec_trav_t="Z"; end; if Q31lgt_sec_et ne "Z" then Q31lgt_sec_et_t=Q31lgt_sec_et; else do; if q31_i="3" then Q31lgt_sec_et_t="1"; else if q31_i in ("1" "2" "4" "5") then Q31lgt_sec_et_t="2"; else Q31lgt_sec_et_t="Z"; end; if Q31lgt_sec_vac ne "Z" then Q31lgt_sec_vac_t=Q31lgt_sec_vac; else do; if q31_i="4" then Q31lgt_sec_vac_t="1"; else if q31_i in ("1" "2" "3" "5") then Q31lgt_sec_vac_t="2"; else if q31_i="6" then Q31lgt_sec_vac_t="1"; else Q31lgt_sec_vac_t="Z"; end; if Q31lgt_sec_aut ne "Z" then Q31lgt_sec_aut_t=Q31lgt_sec_aut; else do; if q31_i="5" then Q31lgt_sec_aut_t="1"; else if q31_i in ("1" "2" "3" "4") then Q31lgt_sec_aut_t="2"; else Q31lgt_sec_aut_t="Z"; end; run; /* proc freq; table Q31lgt_sec_fam_t Q31lgt_sec_trav_t Q31lgt_sec_et_t Q31lgt_sec_vac_t Q31lgt_sec_aut_t; run; */ /**** Q31LGT_sec_fam_i *******/ data &imp2 ; set &imp2; vdiscri=cats(q31_i,q3couple_i,groupage); Proc sort;By vdiscri CABEFLA;run; data &imp2 ; set &imp2; By vdiscri; retain n_ok n_miss a b c; if first.vdiscri then do; n_ok=1; n_miss=2; a=0;b=0;c=0; end; a=a+1; if Q31LGT_sec_fam_t ne "Z" then do; num=n_ok; n_ok=n_ok+2; b=b+1;end; else if Q31LGT_sec_fam_t ="Z" then do; num=n_miss ; n_miss=n_miss+2; c=c+1;end; else kk = 1 ; if last.vdiscri then do; if n_ok +1 < n_miss then do ; pb = 1; taille_groupe=a; donneurs=b; receveurs=c; donneurs_manquants=receveurs-donneurs; end; else pb=0; end; drop a b c n_miss n_ok kk; run; /*on impute*/ Proc sort data= &imp2; By vdiscri num; data &imp2; set &imp2; Q31LGT_sec_fam_i=Q31LGT_sec_fam_t; retain reserveQ31LGT_sec_fam_t; if Q31LGT_sec_fam_t ne "Z" then reserveQ31LGT_sec_fam_t= Q31LGT_sec_fam_t; if Q31LGT_sec_fam_t ="Z" then Q31LGT_sec_fam_i =reserveQ31LGT_sec_fam_t; drop reserveQ31LGT_sec_fam_t num pb vdiscri taille_groupe donneurs receveurs donneurs_manquants; run; /* proc freq; table Q31LGT_sec_fam_t*Q31LGT_sec_fam_i /norow nocol nopercent;run; */ /**** Q31LGT_sec_trav_i *******/ data &imp2 ; set &imp2; vdiscri=cats(q31_i,regroupCS,groupage); Proc sort;By vdiscri CABEFLA;run; data &imp2 ; set &imp2; By vdiscri; retain n_ok n_miss a b c; if first.vdiscri then do; n_ok=1; n_miss=2; a=0;b=0;c=0; end; a=a+1; if Q31LGT_sec_trav_t ne "Z" then do; num=n_ok; n_ok=n_ok+2; b=b+1;end; else if Q31LGT_sec_trav_t ="Z" then do; num=n_miss ; n_miss=n_miss+2; c=c+1;end; else kk = 1 ; if last.vdiscri then do; if n_ok +1 < n_miss then do ; pb = 1; taille_groupe=a; donneurs=b; receveurs=c; donneurs_manquants=receveurs-donneurs; end; else pb=0; end; drop a b c n_miss n_ok kk; run; /*on impute*/ Proc sort data= &imp2; By vdiscri num; data &imp2; set &imp2; Q31LGT_sec_trav_i=Q31LGT_sec_trav_t; retain reserveQ31LGT_sec_trav_t; if Q31LGT_sec_trav_t ne "Z" then reserveQ31LGT_sec_trav_t= Q31LGT_sec_trav_t; if Q31LGT_sec_trav_t ="Z" then Q31LGT_sec_trav_i =reserveQ31LGT_sec_trav_t; drop reserveQ31LGT_sec_trav_t num pb vdiscri taille_groupe donneurs receveurs donneurs_manquants; run; /* proc freq; table Q31LGT_sec_trav_c*Q31LGT_sec_trav_i /norow nocol nopercent;run; */ /**** Q31LGT_sec_et_i *******/ data &imp2 ; set &imp2; vdiscri=cats(q31_i,regroupCS,groupage); Proc sort;By vdiscri CABEFLA;run; data &imp2 ; set &imp2; By vdiscri; retain n_ok n_miss a b c; if first.vdiscri then do; n_ok=1; n_miss=2; a=0;b=0;c=0; end; a=a+1; if Q31LGT_sec_et_t ne "Z" then do; num=n_ok; n_ok=n_ok+2; b=b+1;end; else if Q31LGT_sec_et_t ="Z" then do; num=n_miss ; n_miss=n_miss+2; c=c+1;end; else kk = 1 ; if last.vdiscri then do; if n_ok +1 < n_miss then do ; pb = 1; taille_groupe=a; donneurs=b; receveurs=c; donneurs_manquants=receveurs-donneurs; end; else pb=0; end; drop a b c n_miss n_ok kk; run; /*on impute*/ Proc sort data= &imp2; By vdiscri num; data &imp2; set &imp2; Q31LGT_sec_et_i=Q31LGT_sec_et_t; retain reserveQ31LGT_sec_et_t; if Q31LGT_sec_et_t ne "Z" then reserveQ31LGT_sec_et_t= Q31LGT_sec_et_t; if Q31LGT_sec_et_t ="Z" then Q31LGT_sec_et_i =reserveQ31LGT_sec_et_t; drop reserveQ31LGT_sec_et_t num pb vdiscri taille_groupe donneurs receveurs donneurs_manquants; run; /* proc freq; table Q31LGT_sec_et_t*Q31LGT_sec_et_i /norow nocol nopercent;run; */ /**** Q31LGT_sec_vac_i *******/ data &imp2 ; set &imp2; vdiscri=cats(q31_i,regroupCS,groupage); Proc sort;By vdiscri CABEFLA;run; data &imp2 ; set &imp2; By vdiscri; retain n_ok n_miss a b c; if first.vdiscri then do; n_ok=1; n_miss=2; a=0;b=0;c=0; end; a=a+1; if Q31LGT_sec_vac_t ne "Z" then do; num=n_ok; n_ok=n_ok+2; b=b+1;end; else if Q31LGT_sec_vac_t ="Z" then do; num=n_miss ; n_miss=n_miss+2; c=c+1;end; else kk = 1 ; if last.vdiscri then do; if n_ok +1 < n_miss then do ; pb = 1; taille_groupe=a; donneurs=b; receveurs=c; donneurs_manquants=receveurs-donneurs; end; else pb=0; end; drop a b c n_miss n_ok kk; run; /*on impute*/ Proc sort data= &imp2; By vdiscri num; data &imp2; set &imp2; Q31LGT_sec_vac_i=Q31LGT_sec_vac_t; retain reserveQ31LGT_sec_vac_t; if Q31LGT_sec_vac_t ne "Z" then reserveQ31LGT_sec_vac_t= Q31LGT_sec_vac_t; if Q31LGT_sec_vac_t ="Z" then Q31LGT_sec_vac_i =reserveQ31LGT_sec_vac_t; drop reserveQ31LGT_sec_vac_t num pb vdiscri taille_groupe donneurs receveurs donneurs_manquants; run; /* proc freq; table Q31LGT_sec_vac_t*Q31LGT_sec_vac_i /norow nocol nopercent;run; */ /**** Q31LGT_sec_aut_t *******/ data &imp2 ; set &imp2; vdiscri=cats(q31_i,regroupCS,groupage); Proc sort;By vdiscri CABEFLA;run; data &imp2 ; set &imp2; by vdiscri; retain n_ok n_miss a b c; if first.vdiscri then do; n_ok=1; n_miss=2; a=0;b=0;c=0; end; a=a+1; if Q31LGT_sec_aut_t ne "Z" then do; num=n_ok; n_ok=n_ok+2; b=b+1;end; else if Q31LGT_sec_aut_t ="Z" then do; num=n_miss ; n_miss=n_miss+2; c=c+1;end; else kk = 1 ; if last.vdiscri then do; if n_ok +1 < n_miss then do ; pb = 1; taille_groupe=a; donneurs=b; receveurs=c; donneurs_manquants=receveurs-donneurs; end; else pb=0; end; drop a b c n_miss n_ok kk; run; /*on impute*/ Proc sort data= &imp2; By vdiscri num; data &imp2; set &imp2; Q31LGT_sec_aut_i=Q31LGT_sec_aut_t; retain reserveQ31LGT_sec_aut_t; if Q31LGT_sec_aut_t ne "Z" then reserveQ31LGT_sec_aut_t= Q31LGT_sec_aut_t; if Q31LGT_sec_aut_t ="Z" then Q31LGT_sec_aut_i =reserveQ31LGT_sec_aut_t; drop reserveQ31LGT_sec_aut_t num pb vdiscri taille_groupe donneurs receveurs donneurs_manquants; run; /* proc freq; table Q31LGT_sec_aut_t*Q31LGT_sec_aut_i /norow nocol nopercent;run; */ /*on supprime les variables temporaires*/ data &imp2 ; set &imp2; drop q31_i Q31lgt_sec_fam_t Q31lgt_sec_trav_t Q31lgt_sec_et_t Q31lgt_sec_vac_t Q31lgt_sec_aut_t; run; /* *verification: tous les enquêtés ont renseigné au moins un motif; data temp;set &imp2; array tab (5) $ Q31lgt_sec_aut_i Q31lgt_sec_et_i Q31lgt_sec_fam_i Q31lgt_sec_trav_i Q31lgt_sec_vac_i; compt=0; do n=1 to 5; if tab(n)="1" then compt=compt+1; end; proc freq; table compt; options obs=20; proc print ; var Q31lgt_sec_aut_i Q31lgt_sec_et_i Q31lgt_sec_fam_i Q31lgt_sec_trav_i Q31lgt_sec_vac_i ; where compt=0; options obs=max; proc delete data=temp; run; */ /* on recrée la variable q31_i à partir des variables imputées de la question 31*/ data &imp2; set &imp2; length q31_i $1; compt_q31_i=0; array tabq31_1(5) $ Q31lgt_sec_fam_i Q31lgt_sec_trav_i Q31lgt_sec_et_i Q31lgt_sec_vac_i Q31lgt_sec_aut_i; array tabq31_2(5)$1 a1-a5 ("1" "2" "3" "4" "5"); do n=1 to 5; if tabq31_1(n)="1" then compt_q31_i=compt_q31_i+1 ; end; if compt_q31_i=1 then do m=1 to 5; if tabq31_1(m)="1" then Q31_i=tabq31_2(m) ; end; else if compt_q31_i>1 then do; if Q31lgt_sec_vac_i="1" and Q31lgt_sec_fam_i="1" then Q31_i="6"; else if Q31lgt_sec_trav_i="1" then Q31_i="7"; else Q31_i="8"; end; drop n m compt_q31_i a1-a5; run; /* proc freq; table q31_i; format q31_i $q31a. ;run; */ /**************************************************************** imputation Q32NATAUTLGT ****************************************************************/ /* création de vdiscri */ data &imp2; set &imp2 ; vdiscri= cats(Q31_i,gimput3,q3couple_i); Proc sort data=&imp2 ;By vdiscri;run; /*on compare le nombre de donneurs et de receveurs*/ data &imp2 ; set &imp2; By vdiscri; retain n_ok n_miss a b c; if first.vdiscri then do; n_ok=1; n_miss=2; a=0;b=0;c=0; end; a=a+1; if Q32NATAUTLGT ne "Z" then do; num=n_ok; n_ok=n_ok+2; b=b+1;end; else if Q32NATAUTLGT ="Z" then do; num=n_miss ; n_miss=n_miss+2; c=c+1;end; else kk = 1 ; if last.vdiscri then do; if n_ok +1 < n_miss then do ; pb = 1; taille_groupe=a; donneurs=b; receveurs=c; donneurs_manquants=receveurs-donneurs; end; else pb=0; end; drop a b c n_miss n_ok kk; run; /*on impute*/ Proc sort data=&imp2 ; By vdiscri num; data &imp2 ;set &imp2; Q32NATAUTLGT_i=Q32NATAUTLGT; retain reserveQ32NATAUTLGT; if Q32NATAUTLGT ne "Z" then reserveQ32NATAUTLGT= Q32NATAUTLGT; if Q32NATAUTLGT ="Z" then Q32NATAUTLGT_i =reserveQ32NATAUTLGT; drop reserveQ32NATAUTLGT num pb vdiscri taille_groupe donneurs receveurs donneurs_manquants; run; /* proc freq ; table Q32NATAUTLGT*Q32NATAUTLGT_i /nopercent nocol norow;run; */ /**************************************************************** imputation Q34TPSAUTLGT ****************************************************************/ /* creation vdiscri*/ data &imp2; set &imp2 ; vdiscri= cats(Q31_i,gimput3,Q29TPS_i); Proc sort data=&imp2 ;By vdiscri;run; /*on compare le nombre de donneurs et de receveurs*/ data &imp2 ; set &imp2; By vdiscri; retain n_ok n_miss a b c; if first.vdiscri then do; n_ok=1; n_miss=2; a=0;b=0;c=0; end; a=a+1; if Q34TPSAUTLGT ne "Z" then do; num=n_ok; n_ok=n_ok+2; b=b+1;end; else if Q34TPSAUTLGT ="Z" then do; num=n_miss ; n_miss=n_miss+2; c=c+1;end; else kk = 1 ; if last.vdiscri then do; if n_ok +1 < n_miss then do ; pb = 1; taille_groupe=a; donneurs=b; receveurs=c; donneurs_manquants=receveurs-donneurs; end; else pb=0; end; drop a b c n_miss n_ok kk; run; /*on impute*/ Proc sort data=&imp2 ; By vdiscri num; data &imp2 ;set &imp2; Q34TPSAUTLGT_i=Q34TPSAUTLGT; retain reserveQ34TPSAUTLGT; if Q34TPSAUTLGT ne "Z" then reserveQ34TPSAUTLGT= Q34TPSAUTLGT; if Q34TPSAUTLGT ="Z" then Q34TPSAUTLGT_i =reserveQ34TPSAUTLGT; drop reserveQ34TPSAUTLGT num pb vdiscri taille_groupe donneurs receveurs donneurs_manquants; run; /* proc freq ; table Q34TPSAUTLGT*Q34TPSAUTLGT_i /nopercent nocol norow;run; */ /**************************************************************** imputation Q35 ****************************************************************/ /*on impute d'abord la variable regroupée Q35, ce qui permet de faire sortir les motifs uniques et les motifs multiples, puis on impute les variables Q35PERSAUTLGT_EGO, ....*/ /************************* imputation Q35_i *********************/ /* creation vdiscri*/ data &imp2 ;set &imp2; vdiscri= cats(Q31_i,gimput3,q3couple_i); Proc sort data=&imp2 ;By vdiscri;run; /*on compare le nombre de donneurs et de receveurs*/ data &imp2 ; set &imp2; By vdiscri; retain n_ok n_miss a b c; if first.vdiscri then do; n_ok=1; n_miss=2; a=0;b=0;c=0; end; a=a+1; if q35 ne "Z" then do; num=n_ok; n_ok=n_ok+2; b=b+1;end; else if q35 ="Z" then do; num=n_miss ; n_miss=n_miss+2; c=c+1;end; else kk = 1 ; if last.vdiscri then do; if n_ok +1 < n_miss then do ; pb = 1; taille_groupe=a; donneurs=b; receveurs=c; donneurs_manquants=receveurs-donneurs; end; else pb=0; end; drop a b c n_miss n_ok kk; run; /*on impute*/ Proc sort data=&imp2 ; By vdiscri num; data &imp2 ;set &imp2; q35_i=q35; retain reserveq35; if q35 ne "Z" then reserveq35= q35; if q35 ="Z" then q35_i =reserveq35; drop reserveq35 num pb vdiscri taille_groupe donneurs receveurs donneurs_manquants; run; /* proc freq ; table q35*q35_i /nopercent nocol norow;run; */ /***** on copie l'information sur des variables intermédiaires *******/ data &imp2 ; set &imp2 ; if Q35PERSAUTLGT_ego ne "Z" then Q35PERSAUTLGT_ego_t=Q35PERSAUTLGT_ego; else do; if q35_i="1" then Q35PERSAUTLGT_ego_t="1"; else if q35_i in ("2" "3" "4" "5") then Q35PERSAUTLGT_ego_t="2"; else if q35_i="6" then Q35PERSAUTLGT_ego_t="1"; else Q35PERSAUTLGT_ego_t="Z"; end; if Q35PERSAUTLGT_c ne "Z" then Q35PERSAUTLGT_c_t=Q35PERSAUTLGT_c; else do; if q35_i="2" then Q35PERSAUTLGT_c_t="1"; else if q35_i in ("1" "3" "4" "5") then Q35PERSAUTLGT_c_t="2"; else if q35_i in ("6" "7") then Q35PERSAUTLGT_c_t="1"; else Q35PERSAUTLGT_c_t="Z"; end; if Q35PERSAUTLGT_fam ne "Z" then Q35PERSAUTLGT_fam_t=Q35PERSAUTLGT_fam; else do; if q35_i="3" then Q35PERSAUTLGT_fam_t="1"; else if q35_i in ("1" "2" "4" "5") then Q35PERSAUTLGT_fam_t="2"; else if q35_i in ("6" "7") then Q35PERSAUTLGT_fam_t="1"; else Q35PERSAUTLGT_fam_t="Z"; end; if Q35PERSAUTLGT_hfam ne "Z" then Q35PERSAUTLGT_hfam_t=Q35PERSAUTLGT_hfam; else do; if q35_i="4" then Q35PERSAUTLGT_hfam_t="1"; else if q35_i in ("1" "2" "3" "5") then Q35PERSAUTLGT_hfam_t="2"; else Q35PERSAUTLGT_hfam_t="Z"; end; if Q35PERSAUTLGT_pers ne "Z" then Q35PERSAUTLGT_pers_t=Q35PERSAUTLGT_pers; else do; if q35_i="5" then Q35PERSAUTLGT_pers_t="1"; else if q35_i in ("1" "2" "3" "4") then Q35PERSAUTLGT_pers_t="2"; else Q35PERSAUTLGT_pers_t="Z"; end; run; /* proc freq; table Q35PERSAUTLGT_ego_t Q35PERSAUTLGT_c_t Q35PERSAUTLGT_fam_t Q35PERSAUTLGT_hfam_t Q35PERSAUTLGT_pers_t; run; proc freq; table Q35PERSAUTLGT_ego*Q35PERSAUTLGT_ego_t /norow nocol nopercent; table Q35PERSAUTLGT_c*Q35PERSAUTLGT_ego_t /norow nocol nopercent; table Q35PERSAUTLGT_fam*Q35PERSAUTLGT_fam_t /norow nocol nopercent; table Q35PERSAUTLGT_hfam* Q35PERSAUTLGT_hfam_t/norow nocol nopercent; table Q35PERSAUTLGT_pers*Q35PERSAUTLGT_pers_t/norow nocol nopercent; run; */ /* imputation Q35PERSAUTLGT_ego */ data &imp2 ;set &imp2; vdiscri= cats(Q31_i,gimput3,q3couple_i); Proc sort data=&imp2 ;By vdiscri;run; data &imp2 ; set &imp2; By vdiscri; retain n_ok n_miss a b c; if first.vdiscri then do; n_ok=1; n_miss=2; a=0;b=0;c=0; end; a=a+1; if Q35PERSAUTLGT_ego_t ne "Z" then do; num=n_ok; n_ok=n_ok+2; b=b+1;end; else if Q35PERSAUTLGT_ego_t ="Z" then do; num=n_miss ; n_miss=n_miss+2; c=c+1;end; else kk = 1 ; if last.vdiscri then do; if n_ok +1 < n_miss then do ; pb = 1; taille_groupe=a; donneurs=b; receveurs=c; donneurs_manquants=receveurs-donneurs; end; else pb=0; end; drop a b c n_miss n_ok kk; run; /*on impute*/ Proc sort data=&imp2 ; By vdiscri num; data &imp2 ;set &imp2; Q35PERSAUTLGT_ego_i=Q35PERSAUTLGT_ego_t; retain reserve; if Q35PERSAUTLGT_ego_t ne "Z" then reserve= Q35PERSAUTLGT_ego_t; if Q35PERSAUTLGT_ego_t ="Z" then Q35PERSAUTLGT_ego_i =reserve; drop reserve num pb vdiscri taille_groupe donneurs receveurs donneurs_manquants; run; /* proc freq ; table Q35PERSAUTLGT_ego*Q35PERSAUTLGT_ego_i /nopercent nocol norow;run; */ /* imputation Q35PERSAUTLGT_C */ data &imp2 ;set &imp2; vdiscri= cats(Q31_i,gimput3,q3couple_i); Proc sort data=&imp2 ;By vdiscri;run; data &imp2 ; set &imp2; By vdiscri; retain n_ok n_miss a b c; if first.vdiscri then do; n_ok=1; n_miss=2; a=0;b=0;c=0; end; a=a+1; if Q35PERSAUTLGT_C_t ne "Z" then do; num=n_ok; n_ok=n_ok+2; b=b+1;end; else if Q35PERSAUTLGT_C_t ="Z" then do; num=n_miss ; n_miss=n_miss+2; c=c+1;end; else kk = 1 ; if last.vdiscri then do; if n_ok +1 < n_miss then do ; pb = 1; taille_groupe=a; donneurs=b; receveurs=c; donneurs_manquants=receveurs-donneurs; end; else pb=0; end; drop a b c n_miss n_ok kk; run; /*on impute*/ Proc sort data=&imp2 ; By vdiscri num; data &imp2 ;set &imp2; Q35PERSAUTLGT_C_i=Q35PERSAUTLGT_C_t; retain reserve; if Q35PERSAUTLGT_C_t ne "Z" then reserve= Q35PERSAUTLGT_C_t; if Q35PERSAUTLGT_C_t ="Z" then Q35PERSAUTLGT_C_i =reserve; drop reserve num pb vdiscri taille_groupe donneurs receveurs donneurs_manquants; run; /* proc freq ; table Q35PERSAUTLGT_C*Q35PERSAUTLGT_C_i /nopercent nocol norow;run; */ /* imputation Q35PERSAUTLGT_FAM */ data &imp2; set &imp2 ; vdiscri= cats(Q31_i,gimput3,q3couple_i); Proc sort data=&imp2 ;By vdiscri;run; data &imp2 ; set &imp2; By vdiscri; retain n_ok n_miss a b c; if first.vdiscri then do; n_ok=1; n_miss=2; a=0;b=0;c=0; end; a=a+1; if Q35PERSAUTLGT_FAM_t ne "Z" then do; num=n_ok; n_ok=n_ok+2; b=b+1;end; else if Q35PERSAUTLGT_FAM_t ="Z" then do; num=n_miss ; n_miss=n_miss+2; c=c+1;end; else kk = 1 ; if last.vdiscri then do; if n_ok +1 < n_miss then do ; pb = 1; taille_groupe=a; donneurs=b; receveurs=c; donneurs_manquants=receveurs-donneurs; end; else pb=0; end; drop a b c n_miss n_ok kk; run; /*on impute*/ Proc sort data=&imp2 ; By vdiscri num; data &imp2 ;set &imp2; Q35PERSAUTLGT_FAM_i=Q35PERSAUTLGT_FAM_t; retain reserve; if Q35PERSAUTLGT_FAM_t ne "Z" then reserve= Q35PERSAUTLGT_FAM_t; if Q35PERSAUTLGT_FAM_t ="Z" then Q35PERSAUTLGT_FAM_i =reserve; drop reserve num pb vdiscri taille_groupe donneurs receveurs donneurs_manquants; run; /* proc freq ; table Q35PERSAUTLGT_FAM*Q35PERSAUTLGT_FAM_i /nopercent nocol norow;run; */ /* imputation Q35PERSAUTLGT_HFAM */ data &imp2; set &imp2 ; vdiscri= cats(Q31_i,gimput3,q3couple_i); Proc sort data=&imp2 ;By vdiscri;run; data &imp2 ; set &imp2; By vdiscri; retain n_ok n_miss a b c; if first.vdiscri then do; n_ok=1; n_miss=2; a=0;b=0;c=0; end; a=a+1; if Q35PERSAUTLGT_HFAM_t ne "Z" then do; num=n_ok; n_ok=n_ok+2; b=b+1;end; else if Q35PERSAUTLGT_HFAM_t ="Z" then do; num=n_miss ; n_miss=n_miss+2; c=c+1;end; else kk = 1 ; if last.vdiscri then do; if n_ok +1 < n_miss then do ; pb = 1; taille_groupe=a; donneurs=b; receveurs=c; donneurs_manquants=receveurs-donneurs; end; else pb=0; end; drop a b c n_miss n_ok kk; run; /*on impute*/ Proc sort data=&imp2 ; By vdiscri num; data &imp2 ;set &imp2; Q35PERSAUTLGT_HFAM_i=Q35PERSAUTLGT_HFAM_t; retain reserve; if Q35PERSAUTLGT_HFAM_t ne "Z" then reserve= Q35PERSAUTLGT_HFAM_t; if Q35PERSAUTLGT_HFAM_t ="Z" then Q35PERSAUTLGT_HFAM_i =reserve; drop reserve num pb vdiscri taille_groupe donneurs receveurs donneurs_manquants; run; /* proc freq ; table Q35PERSAUTLGT_HFAM_t*Q35PERSAUTLGT_HFAM_i /nopercent nocol norow;run; */ /* imputation Q35PERSAUTLGT_PERS */ data &imp2; set &imp2 ; vdiscri= cats(Q31_i,gimput3,q3couple_i); Proc sort data=&imp2 ;By vdiscri;run; data &imp2 ; set &imp2; By vdiscri; retain n_ok n_miss a b c; if first.vdiscri then do; n_ok=1; n_miss=2; a=0;b=0;c=0; end; a=a+1; if Q35PERSAUTLGT_PERS_t ne "Z" then do; num=n_ok; n_ok=n_ok+2; b=b+1;end; else if Q35PERSAUTLGT_PERS_t ="Z" then do; num=n_miss ; n_miss=n_miss+2; c=c+1;end; else kk = 1 ; if last.vdiscri then do; if n_ok +1 < n_miss then do ; pb = 1; taille_groupe=a; donneurs=b; receveurs=c; donneurs_manquants=receveurs-donneurs; end; else pb=0; end; drop a b c n_miss n_ok kk; run; /*on impute*/ Proc sort data=&imp2 ; By vdiscri num; data &imp2 ;set &imp2; Q35PERSAUTLGT_PERS_i=Q35PERSAUTLGT_PERS_t; retain reserve; if Q35PERSAUTLGT_PERS_t ne "Z" then reserve= Q35PERSAUTLGT_PERS_t; if Q35PERSAUTLGT_PERS_t ="Z" then Q35PERSAUTLGT_PERS_i =reserve; drop reserve num pb vdiscri taille_groupe donneurs receveurs donneurs_manquants; run; /* proc freq ; table Q35PERSAUTLGT_PERS*Q35PERSAUTLGT_PERS_i /nopercent nocol norow;run; */ /* on vérifie si aucun enquêté a répondu non à toutes les modalités de la Q35*/ data _null_; set &imp2 end=fin; retain compt 0; if Q35persautlgt_ego_i="2" and Q35persautlgt_c_i="2" and Q35persautlgt_fam_i="2" and Q35persautlgt_hfam_i="2" and Q35PERSAUTLGT_PERS_i="2" then compt=compt+1; if fin then put compt=; run; /*si les réponses imputées étaient toujours négatives à la question 35 alors on suppose que l'enquêté aurait du noter "personne"*/ /* data &imp2 ;set &imp2; if Q35persautlgt_ego_i="2" and Q35persautlgt_i="2" and Q35persautlgt_fam_i="2" and Q35persautlgt_hfam_i="2" then Q35PERSAUTLGT_PERS_i="1"; run; */ /*tris à plat des variables imputées*/ /* proc freq data=&imp2; table Q35PERSAUTLGT_ego_i Q35PERSAUTLGT_c_i Q35PERSAUTLGT_fam_i Q35PERSAUTLGT_hfam_i Q35PERSAUTLGT_pers_i; run; proc freq; table Q35PERSAUTLGT_ego*Q35PERSAUTLGT_ego_t /norow nocol nopercent; table Q35PERSAUTLGT_c*Q35PERSAUTLGT_ego_t /norow nocol nopercent; table Q35PERSAUTLGT_fam*Q35PERSAUTLGT_fam_t /norow nocol nopercent; table Q35PERSAUTLGT_hfam* Q35PERSAUTLGT_hfam_t/norow nocol nopercent; table Q35PERSAUTLGT_pers*Q35PERSAUTLGT_pers_t/norow nocol nopercent; run; */ /************************************************************************* imputation question Q36 **************************************************************************/ /*on impute d'abord la variable regroupée Q35, ce qui permet de faire sortir les motifs uniques et les motifs multiples, puis on impute les variables Q36 ....*/ /************************* imputation Q36_i *********************/ /* creation vdiscri*/ data &imp2 ;set &imp2; vdiscri= cats(Q31_i,gimput3,q3couple_i); Proc sort data=&imp2 ;By vdiscri;run; /*on compare le nombre de donneurs et de receveurs*/ data &imp2 ; set &imp2; By vdiscri; retain n_ok n_miss a b c; if first.vdiscri then do; n_ok=1; n_miss=2; a=0;b=0;c=0; end; a=a+1; if q36 ne "ZZ" then do; num=n_ok; n_ok=n_ok+2; b=b+1;end; else if q36 ="ZZ" then do; num=n_miss ; n_miss=n_miss+2; c=c+1;end; else kk = 1 ; if last.vdiscri then do; if n_ok +1 < n_miss then do ; pb = 1; taille_groupe=a; donneurs=b; receveurs=c; donneurs_manquants=receveurs-donneurs; end; else pb=0; end; drop a b c n_miss n_ok kk; run; /*on impute*/ Proc sort data=&imp2 ; By vdiscri num; data &imp2 ;set &imp2; q36_i=q36; retain reserve; if q36 ne "ZZ" then reserve= q36; if q36 ="ZZ" then q36_i =reserve; drop reserve num pb vdiscri taille_groupe donneurs receveurs donneurs_manquants; run; /* proc freq ; table q36*q36_i /nopercent nocol norow;run; proc freq ; table q36*q36_i /nopercent nocol norow;format q36 q36_i $q36a.;run; */ /***** on copie l'information sur des variables intermédiaires *******/ data &imp2 ; set &imp2 ; er=0; if Q36PROPAUTLGT_EGO ne "Z" then Q36PROPAUTLGT_EGO_t=Q36PROPAUTLGT_EGO; else do; if q36_i="01" then Q36PROPAUTLGT_ego_t="1"; else if q36_i in ("02" "03" "04" "05" "06" "07" "10") then Q36PROPAUTLGT_ego_t="2"; else if q36_i in ("08" "09") then Q36PROPAUTLGT_ego_t="1"; else if q36_i="11" then Q36PROPAUTLGT_ego_t="Z"; else er=1; end; if Q36PROPAUTLGT_c ne "Z" then Q36PROPAUTLGT_c_t=Q36PROPAUTLGT_c; else do; if q36_i="02" then Q36PROPAUTLGT_c_t="1"; else if q36_i in ("01" "03" "04" "05" "06" "07" "08") then Q36PROPAUTLGT_c_t="2"; else if q36_i in ("09" "10") then Q36PROPAUTLGT_c_t="1"; else if q36_i="11" then Q36PROPAUTLGT_c_t="Z"; else er=2; end; if Q36PROPAUTLGT_enf ne "Z" then Q36PROPAUTLGT_enf_t=Q36PROPAUTLGT_enf; else do; if q36_i="03" then Q36PROPAUTLGT_enf_t="1"; else if q36_i in ("01" "02" "04" "05" "06" "07" "08" "09" "10") then Q36PROPAUTLGT_enf_t="2"; else if q36_i="11" then Q36PROPAUTLGT_enf_t="Z"; else er=3; end; if Q36PROPAUTLGT_par ne "Z" then Q36PROPAUTLGT_par_t=Q36PROPAUTLGT_par; else do; if q36_i="04" then Q36PROPAUTLGT_par_t="1"; else if q36_i in ("01" "02" "03" "05" "06" "07" "09") then Q36PROPAUTLGT_par_t="2"; else if q36_i in ("08" "10") then Q36PROPAUTLGT_par_t="1"; else if q36_i="11" then Q36PROPAUTLGT_par_t="Z"; else er=4; end; if Q36PROPAUTLGT_autfam ne "Z" then Q36PROPAUTLGT_autfam_t=Q36PROPAUTLGT_autfam; else do; if q36_i="05" then Q36PROPAUTLGT_autfam_t="1"; else if q36_i in ("01" "02" "03" "04" "06" "07" "08" "09" "10") then Q36PROPAUTLGT_autfam_t="2"; else if q36_i="11" then Q36PROPAUTLGT_autfam_t="Z"; else er=5; end; if Q36PROPAUTLGT_ami ne "Z" then Q36PROPAUTLGT_ami_t=Q36PROPAUTLGT_ami; else do; if q36_i="06" then Q36PROPAUTLGT_ami_t="1"; else if q36_i in ("01" "02" "03" "04" "05" "07" "08" "09" "10") then Q36PROPAUTLGT_ami_t="2"; else if q36_i="11" then Q36PROPAUTLGT_ami_t="Z"; else er=6; end; if Q36PROPAUTLGT_aut ne "Z" then Q36PROPAUTLGT_aut_t=Q36PROPAUTLGT_aut; else do; if q36_i="07" then Q36PROPAUTLGT_aut_t="1"; else if q36_i in ("01" "02" "03" "04" "05" "06" "08" "09" "10") then Q36PROPAUTLGT_aut_t="2"; else if q36_i="11" then Q36PROPAUTLGT_aut_t="Z"; else er=7; end; run; /* *vérification qualité de l'imputation; proc freq;table er;run; */ /* proc freq; table Q36propautlgt_ego Q36propautlgt_c Q36propautlgt_par Q36propautlgt_autfam Q36propautlgt_ami Q36propautlgt_aut; run; */ /* imputation Q36PROPAUTLGT_EGO_t*/ /*creation vdiscri*/ data &imp2 ;set &imp2; vdiscri= cats(Q31_i,gimput3,q3couple_i); Proc sort data=&imp2 ;By vdiscri;run; data &imp2 ; set &imp2; By vdiscri; retain n_ok n_miss a b c; if first.vdiscri then do; n_ok=1; n_miss=2; a=0;b=0;c=0; end; a=a+1; if Q36PROPAUTLGT_EGO_t ne "Z" then do; num=n_ok; n_ok=n_ok+2; b=b+1;end; else if Q36PROPAUTLGT_EGO_t ="Z" then do; num=n_miss ; n_miss=n_miss+2; c=c+1;end; else kk = 1 ; if last.vdiscri then do; if n_ok +1 < n_miss then do ; pb = 1; taille_groupe=a; donneurs=b; receveurs=c; donneurs_manquants=receveurs-donneurs; end; else pb=0; end; drop a b c n_miss n_ok kk; run; /*on impute*/ Proc sort data=&imp2 ; By vdiscri num; data &imp2 ;set &imp2; Q36PROPAUTLGT_EGO_i=Q36PROPAUTLGT_EGO_t; retain reserve; if Q36PROPAUTLGT_EGO_t ne "Z" then reserve= Q36PROPAUTLGT_EGO_t; if Q36PROPAUTLGT_EGO_t ="Z" then Q36PROPAUTLGT_EGO_i =reserve; drop reserve num pb vdiscri taille_groupe donneurs receveurs donneurs_manquants; run; /* proc freq ; table Q36PROPAUTLGT_EGO_t*Q36PROPAUTLGT_EGO_i /nopercent nocol norow;run; */ /* imputation Q36PROPAUTLGT_C_t*/ data &imp2 ;set &imp2; vdiscri= cats(Q31_i,gimput3,q3couple_i); Proc sort data=&imp2 ;By vdiscri;run; data &imp2 ; set &imp2; By vdiscri; retain n_ok n_miss a b c; if first.vdiscri then do; n_ok=1; n_miss=2; a=0;b=0;c=0; end; a=a+1; if Q36PROPAUTLGT_C_t ne "Z" then do; num=n_ok; n_ok=n_ok+2; b=b+1;end; else if Q36PROPAUTLGT_C_t ="Z" then do; num=n_miss ; n_miss=n_miss+2; c=c+1;end; else kk = 1 ; if last.vdiscri then do; if n_ok +1 < n_miss then do ; pb = 1; taille_groupe=a; donneurs=b; receveurs=c; donneurs_manquants=receveurs-donneurs; end; else pb=0; end; drop a b c n_miss n_ok kk; run; /*on impute*/ Proc sort data=&imp2 ; By vdiscri num; data &imp2 ;set &imp2; Q36PROPAUTLGT_C_i=Q36PROPAUTLGT_C_t; retain reserve; if Q36PROPAUTLGT_C_t ne "Z" then reserve= Q36PROPAUTLGT_C_t; if Q36PROPAUTLGT_C_t ="Z" then Q36PROPAUTLGT_C_i =reserve; drop reserve num pb vdiscri taille_groupe donneurs receveurs donneurs_manquants; run; /* proc freq ; table Q36PROPAUTLGT_C_t*Q36PROPAUTLGT_C_i /nopercent nocol norow;run; */ /* imputation Q36PROPAUTLGT_ENF_t*/ data &imp2 ;set &imp2; vdiscri= cats(Q31_i,gimput3,q3couple_i); Proc sort data=&imp2 ;By vdiscri;run; data &imp2 ; set &imp2; By vdiscri; retain n_ok n_miss a b c; if first.vdiscri then do; n_ok=1; n_miss=2; a=0;b=0;c=0; end; a=a+1; if Q36PROPAUTLGT_ENF_t ne "Z" then do; num=n_ok; n_ok=n_ok+2; b=b+1;end; else if Q36PROPAUTLGT_ENF_t ="Z" then do; num=n_miss ; n_miss=n_miss+2; c=c+1;end; else kk = 1 ; if last.vdiscri then do; if n_ok +1 < n_miss then do ; pb = 1; taille_groupe=a; donneurs=b; receveurs=c; donneurs_manquants=receveurs-donneurs; end; else pb=0; end; drop a b c n_miss n_ok kk; run; /*on impute*/ Proc sort data=&imp2 ; By vdiscri num; data &imp2 ;set &imp2; Q36PROPAUTLGT_ENF_i=Q36PROPAUTLGT_ENF_t; retain reserve; if Q36PROPAUTLGT_ENF_t ne "Z" then reserve= Q36PROPAUTLGT_ENF_t; if Q36PROPAUTLGT_ENF_t ="Z" then Q36PROPAUTLGT_ENF_i =reserve; drop reserve num pb vdiscri taille_groupe donneurs receveurs donneurs_manquants; run; /* proc freq ; table Q36PROPAUTLGT_ENF_t*Q36PROPAUTLGT_ENF_i /nopercent nocol norow;run; */ /* imputation Q36PROPAUTLGT_PAR_t*/ data &imp2 ;set &imp2; vdiscri= cats(Q31_i,gimput3,q3couple_i); Proc sort data=&imp2 ;By vdiscri;run; data &imp2 ; set &imp2; By vdiscri; retain n_ok n_miss a b c; if first.vdiscri then do; n_ok=1; n_miss=2; a=0;b=0;c=0; end; a=a+1; if Q36PROPAUTLGT_PAR_t ne "Z" then do; num=n_ok; n_ok=n_ok+2; b=b+1;end; else if Q36PROPAUTLGT_PAR_t ="Z" then do; num=n_miss ; n_miss=n_miss+2; c=c+1;end; else kk = 1 ; if last.vdiscri then do; if n_ok +1 < n_miss then do ; pb = 1; taille_groupe=a; donneurs=b; receveurs=c; donneurs_manquants=receveurs-donneurs; end; else pb=0; end; drop a b c n_miss n_ok kk; run; /*on impute*/ Proc sort data=&imp2 ; By vdiscri num; data &imp2 ;set &imp2; Q36PROPAUTLGT_PAR_i=Q36PROPAUTLGT_PAR_t; retain reserve; if Q36PROPAUTLGT_PAR_t ne "Z" then reserve= Q36PROPAUTLGT_PAR_t; if Q36PROPAUTLGT_PAR_t ="Z" then Q36PROPAUTLGT_PAR_i =reserve; drop reserve num pb vdiscri taille_groupe donneurs receveurs donneurs_manquants; run; /* proc freq ; table Q36PROPAUTLGT_PAR_t*Q36PROPAUTLGT_PAR_i /nopercent nocol norow;run; */ /* imputation Q36PROPAUTLGT_AUTFAM_t*/ data &imp2 ;set &imp2; vdiscri= cats(Q31_i,gimput3,q3couple_i); Proc sort data=&imp2 ;By vdiscri;run; data &imp2 ; set &imp2; By vdiscri; retain n_ok n_miss a b c; if first.vdiscri then do; n_ok=1; n_miss=2; a=0;b=0;c=0; end; a=a+1; if Q36PROPAUTLGT_AUTFAM_t ne "Z" then do; num=n_ok; n_ok=n_ok+2; b=b+1;end; else if Q36PROPAUTLGT_AUTFAM_t ="Z" then do; num=n_miss ; n_miss=n_miss+2; c=c+1;end; else kk = 1 ; if last.vdiscri then do; if n_ok +1 < n_miss then do ; pb = 1; taille_groupe=a; donneurs=b; receveurs=c; donneurs_manquants=receveurs-donneurs; end; else pb=0; end; drop a b c n_miss n_ok kk; run; /*on impute*/ Proc sort data=&imp2 ; By vdiscri num; data &imp2 ;set &imp2; Q36PROPAUTLGT_AUTFAM_i=Q36PROPAUTLGT_AUTFAM_t; retain reserve; if Q36PROPAUTLGT_AUTFAM_t ne "Z" then reserve= Q36PROPAUTLGT_AUTFAM_t; if Q36PROPAUTLGT_AUTFAM_t ="Z" then Q36PROPAUTLGT_AUTFAM_i =reserve; drop reserve num pb vdiscri taille_groupe donneurs receveurs donneurs_manquants; run; /* proc freq ; table Q36PROPAUTLGT_AUTFAM_t*Q36PROPAUTLGT_AUTFAM_i /nopercent nocol norow;run; */ /* imputation Q36PROPAUTLGT_AMI_t*/ data &imp2 ;set &imp2; vdiscri= cats(Q31_i,gimput3,q3couple_i); Proc sort data=&imp2 ;By vdiscri;run; data &imp2 ; set &imp2; By vdiscri; retain n_ok n_miss a b c; if first.vdiscri then do; n_ok=1; n_miss=2; a=0;b=0;c=0; end; a=a+1; if Q36PROPAUTLGT_AMI_t ne "Z" then do; num=n_ok; n_ok=n_ok+2; b=b+1;end; else if Q36PROPAUTLGT_AMI_t ="Z" then do; num=n_miss ; n_miss=n_miss+2; c=c+1;end; else kk = 1 ; if last.vdiscri then do; if n_ok +1 < n_miss then do ; pb = 1; taille_groupe=a; donneurs=b; receveurs=c; donneurs_manquants=receveurs-donneurs; end; else pb=0; end; drop a b c n_miss n_ok kk; run; /*on impute*/ Proc sort data=&imp2 ; By vdiscri num; data &imp2 ;set &imp2; Q36PROPAUTLGT_AMI_i=Q36PROPAUTLGT_AMI_t; retain reserve; if Q36PROPAUTLGT_AMI_t ne "Z" then reserve= Q36PROPAUTLGT_AMI_t; if Q36PROPAUTLGT_AMI_t ="Z" then Q36PROPAUTLGT_AMI_i =reserve; drop reserve num pb vdiscri taille_groupe donneurs receveurs donneurs_manquants; run; /* proc freq ; table Q36PROPAUTLGT_AMI_t*Q36PROPAUTLGT_AMI_i /nopercent nocol norow;run; */ /* imputation Q36PROPAUTLGT_AUT_t*/ data &imp2 ;set &imp2; vdiscri= cats(Q31_i,gimput3,q3couple_i); Proc sort data=&imp2 ;By vdiscri;run; data &imp2 ; set &imp2; By vdiscri; retain n_ok n_miss a b c; if first.vdiscri then do; n_ok=1; n_miss=2; a=0;b=0;c=0; end; a=a+1; if Q36PROPAUTLGT_AUT_t ne "Z" then do; num=n_ok; n_ok=n_ok+2; b=b+1;end; else if Q36PROPAUTLGT_AUT_t ="Z" then do; num=n_miss ; n_miss=n_miss+2; c=c+1;end; else kk = 1 ; if last.vdiscri then do; if n_ok +1 < n_miss then do ; pb = 1; taille_groupe=a; donneurs=b; receveurs=c; donneurs_manquants=receveurs-donneurs; end; else pb=0; end; drop a b c n_miss n_ok kk; run; /*on impute*/ Proc sort data=&imp2 ; By vdiscri num; data &imp2 ;set &imp2; Q36PROPAUTLGT_AUT_i=Q36PROPAUTLGT_AUT_t; retain reserve; if Q36PROPAUTLGT_AUT_t ne "Z" then reserve= Q36PROPAUTLGT_AUT_t; if Q36PROPAUTLGT_AUT_t ="Z" then Q36PROPAUTLGT_AUT_i =reserve; drop reserve num pb vdiscri taille_groupe donneurs receveurs donneurs_manquants; run; /* proc freq ; table Q36PROPAUTLGT_AUT_t*Q36PROPAUTLGT_AUT_i /nopercent nocol norow;run; */ /****************************************************************************/ /* on vérifie si il existe un enquêté qui a répondu non à toutes les modalités de la Q36*/ data _null_; set &imp2 end=fin; retain compt 0; rep=0; array tab(7) Q36propautlgt_ego_i Q36propautlgt_c_i Q36propautlgt_enf_i Q36propautlgt_par_i Q36propautlgt_autfam_i Q36propautlgt_ami_i Q36propautlgt_aut_i ; do n=1 to 7; if tab(n)="1" then rep=rep+1; end; if rep= 0 then compt=compt+1; if fin then put compt=; run; /* OK */ /*si les réponses imputées étaient toujours négatives à la question 36 alors on suppose que l'enquêté aurait du noter "personne" data &imp2 ;set &imp2; if Q36propautlgt_ego_i="2" and Q36propautlgt_i="2" and Q36propautlgt_enf_i="2" and Q36propautlgt_par_i="2" and Q36propautlgt_autfam_i="2" and Q36propautlgt_ami_i="2" then Q36propautlgt_aut_i="1"; run; */ /************************************************************************************** on rassemble les bases temporaires 1 et 2 **************************************************************************************/ /* on ne garde que les variables imputées */ data temp1; set &imp1; keep CABEFLA Q29TPS_i Q30TPSM_i Q31LGT_SEC_i; proc sort; by CABEFLA; data temp2; set &imp2; keep CABEFLA Q31LGT_sec_fam_i Q31LGT_sec_trav_i Q31LGT_sec_et_i Q31LGT_sec_vac_i Q31LGT_sec_aut_i Q32NATAUTLGT_i Q34TPSAUTLGT_i Q35PERSAUTLGT_ego_i Q35PERSAUTLGT_c_i Q35PERSAUTLGT_fam_i Q35PERSAUTLGT_hfam_i Q35PERSAUTLGT_pers_i Q36PROPAUTLGT_ego_i Q36PROPAUTLGT_c_i Q36PROPAUTLGT_enf_i Q36PROPAUTLGT_par_i Q36PROPAUTLGT_autfam_i Q36PROPAUTLGT_ami_i Q36PROPAUTLGT_aut_i; proc sort; by CABEFLA; data imput.imputpage4; merge &base_complete temp1 temp2;by CABEFLA; proc delete data=temp1 temp2 &imp1 &imp2; run; /****************************************************************/ /****************************************************************/ /****************************************************************/ /****************************************************************/ /****************************************************************/ /****************************************************************/ /****************************************************************/ /****************************************************************/ /****************************************************************/ /****************************************************************/ /****************************************************************/ /****************************************************************/ /****************************************************************/ /****************************************************************/ /****************************************************************/ /*** creation des base finales ***/ /****************************************************************/ /****************************************************************/ /****************************************************************/ /****************************************************************/ /****************************************************************/ /****************************************************************/ /****************************************************************/ /****************************************************************/ /****************************************************************/ /****************************************************************/ /****************************************************************/ /****************************************************************/ /****************************************************************/ /**************************EFL_individu_imput *************************/ data imput.EFL_individu_imput; set imput.imputpage4; keep /*divers 1*/ CABEFLA CABFLA CABBIA CABBI_CA POIDSINITIAL POIDS_IND POIDS_MEN_FAM_ENF NUMF /*divers 2*/ CS_i dipl LIENF MOCO PARIS REG_CODE /*page 1*/ q0sexe /*non imputé*/ q1anai_i q1mnai_i q2nbfreres_i q2nbsoeurs_i q2nbdemif_i q2nbdemis_i q3couple_i q4anai_c_i q4mnai_c_i q5sexe_c /*non imputé*/ q6annee_c_i q6mois_c_i q7pacs_i q7mois_pacs_i q7annee_pacs_i q8mari_i q8annee_mari_i q8mois_mari_i q9tps_logr_i q10cause_r_i q10annee_s_i q10annee_d_i /*page 2*/ nbenftab2 enfdec1-enfdec17 q11enfan_i q11nb_enf_i q11nb_enf_lgt_i q12enfan_c_i q12nb_enf_c_i q12nb_enf_lgt_c_i E13_14sexe_i1-E13_14sexe_i17 E13_14anai_i1 - E13_14anai_i17 E13_14part1 - E13_14part17 /*non imputé*/ E13_14cpart_i1 - E13_14cpart_i17 E13_14agad1 - E13_14agad17 /*non imputé*/ E13tpslgt1 - E13tpslgt17 /*non imputé*/ E13aut_lgt1 - E13aut_lgt17 /*non imputé*/ E13lgt_aut_par1 - E13lgt_aut_par17 /*non imputé*/ E13lgt_autre1 - E13lgt_autre17 /*non imputé*/ E13lgt_etude1 - E13lgt_etude17 /*non imputé*/ E14agdep1-E14agdep17 /*non imputé*/ E14reg1-E14reg17 /*non imputé*/ E14resid1-E14resid17 /*non imputé*/ E13_14_vivant_i1-E13_14_vivant_i17 /*page 3*/ Q17CS_M_i Q23CS_P_i Q15REG /*non imputé*/ Q15LNAI /*non imputé*/ Q15NSP_M /*non imputé*/ Q16NAT_M /*non imputé*/ Q17GS_M /*non imputé*/ Q17NJT_M /*non imputé*/ Q18STATUT_M /*non imputé*/ Q19VIV_M /*non imputé*/ Q19ADEC_M /*non imputé*/ Q20RES_LGT_M /*non imputé*/ Q20RES_AUT_M /*non imputé*/ Q20REG /*non imputé*/ Q20RESID /*non imputé*/ Q21PAY /*non imputé*/ Q21REG /*non imputé*/ Q21LNAI /*non imputé*/ Q21NSP_P /*non imputé*/ Q22NAT_P /*non imputé*/ Q23GS_P /*non imputé*/ Q23NJT_P /*non imputé*/ Q24STATUT_P /*non imputé*/ Q25VIV_P /*non imputé*/ Q25ADEC_P /*non imputé*/ Q26RES_AVECM_P /*non imputé*/ Q26RES_LGT_P /*non imputé*/ Q26RES_AUT_P /*non imputé*/ Q26REG /*non imputé*/ Q26RESID /*non imputé*/ Q27GRP /*non imputé*/ Q27NBPENF /*non imputé*/ Q27AGPENF /*non imputé*/ /*page 4*/ Q29TPS_i Q30TPSM_i Q31LGT_SEC_i Q31LGT_sec_fam_i Q31LGT_sec_trav_i Q31LGT_sec_et_i Q31LGT_sec_vac_i Q31LGT_sec_aut_i Q32NATAUTLGT_i Q34TPSAUTLGT_i Q35PERSAUTLGT_ego_i Q35PERSAUTLGT_c_i Q35PERSAUTLGT_fam_i Q35PERSAUTLGT_hfam_i Q35PERSAUTLGT_pers_i Q36PROPAUTLGT_ego_i Q36PROPAUTLGT_c_i Q36PROPAUTLGT_enf_i Q36PROPAUTLGT_par_i Q36PROPAUTLGT_autfam_i Q36PROPAUTLGT_ami_i Q36PROPAUTLGT_aut_i; run; /*************************variable enfdec*****************************/ /* variable vide si imputations à partir de données anonymisées, donc à supprimer*/ %macro creabasef; %if &donnees_ano=non %then %do; data imput.EFL_individu_imput; set imput.EFL_individu_imput; drop enfdec1-enfdec17; run; %end; %mend; %creabasef; /*************************EFL_enfant_imput*****************************/ data imput.EFL_enfant_imput; set imput.enfants; length identa $35; identa=cats(put(CABEFLA,best10.),"_",rang); run; /***************suppression bases temporaires******************************/ proc delete data= imput.imputpage1 imput.imputpage2 imput.imputpage3 imput.imputpage4 imput.imputenfant imput.enfants; run; /**************************************************************** tri à plat des variables imputées ****************************************************************/ /* proc freq data=imput.EFL_individu_imput; table enfdec1-enfdec17; table E13_14_vivant_i1-E13_14_vivant_i17; run; proc freq data=imput.EFL_enfant_imput; table E13_14_vivant_i enfdec; run; */ ods listing close; ods html style=minimal; proc freq data=imput.EFL_individu_imput; table cs_i q1anai_i q1mnai_i q3couple_i q4anai_c_i q4mnai_c_i q5sexe_c q6annee_c_i q6mois_c_i q7pacs_i q7mois_pacs_i q7annee_pacs_i q8mari_i q8annee_mari_i q8mois_mari_i q9tps_logr_i q10cause_r_i q10annee_s_i q10annee_d_i; run; /* page 2*/ proc freq data=imput.EFL_individu_imput; table q11enfan_i q11nb_enf_i q11nb_enf_lgt_i q12enfan_c_i q12nb_enf_c_i q12nb_enf_lgt_c_i E13_14sexe_i1-E13_14sexe_i17 E13_14anai_i1 - E13_14anai_i17; run; /* page 2*/ proc freq data=imput.EFL_individu_imput ; table q11enfan_i q11nb_enf_i q11nb_enf_lgt_i q12enfan_c_i q12nb_enf_c_i q12nb_enf_lgt_c_i E13_14sexe_i1-E13_14sexe_i17 E13_14anai_i1 - E13_14anai_i17 E13_14part1 - E13_14part17 /*non imputé*/ E13_14cpart_i1 - E13_14cpart_i17 E13_14agad1 - E13_14agad17 /*non imputé*/ E13tpslgt1 - E13tpslgt17 /*non imputé*/ E13aut_lgt1 - E13aut_lgt17 /*non imputé*/ E13lgt_aut_par1 - E13lgt_aut_par17 /*non imputé*/ E13lgt_autre1 - E13lgt_autre17 /*non imputé*/ E13lgt_etude1 - E13lgt_etude17 /*non imputé*/ E14agdep1-E14agdep17 /*non imputé*/ E14reg1-E14reg17 /*non imputé*/ E14resid1-E14resid17 /*non imputé*/; run; /* page 3*/ proc freq data=imput.EFL_individu_imput; table Q17CS_M_i Q23CS_P_i; run; /* page 4*/ proc freq data=imput.EFL_individu_imput; table Q29TPS_i Q30TPSM_i Q31LGT_SEC_i Q31LGT_sec_fam_i Q31LGT_sec_trav_i Q31LGT_sec_et_i Q31LGT_sec_vac_i Q31LGT_sec_aut_i Q32NATAUTLGT_i Q34TPSAUTLGT_i Q35PERSAUTLGT_ego_i Q35PERSAUTLGT_c_i Q35PERSAUTLGT_fam_i Q35PERSAUTLGT_hfam_i Q35PERSAUTLGT_pers_i Q36PROPAUTLGT_ego_i Q36PROPAUTLGT_c_i Q36PROPAUTLGT_enf_i Q36PROPAUTLGT_par_i Q36PROPAUTLGT_autfam_i Q36PROPAUTLGT_ami_i Q36PROPAUTLGT_aut_i; run; ods html close; ods listing ;