%let TOTPOP = 764000; data degreM; input strateN _TOTAL_; datalines; 1 108 2 108 3 109 4 108 5 111 ; data degreJ; input vagueN _TOTAL_; datalines; 1 90 2 91 3 92 4 92 ; title ' '; %macro TOTAL (table_selection, identifiant, strate, vague, mater, jour, poids, variable,methode); /* table_selection=nom de la table où sont les données. Il faut dans cette table, les champs suivants: - Les variables de calage CS_1 à CS_XX - identifiant = champs identifiant les enregistrements ID... - strate = champs qui identifie la strate de la maternité. Par défaut M00M1_MATSTRATEC1 - vague = champs qui identifie la vague de l'enquête. Par défaut M00M1_VAGUE - mater = champs qui identifie la maternité. Par défaut M00M1_IDGROUPNAMEALEAC1 - jour = champs qui identifie le jour. Par défaut M00M2_JNAISSEALEA - poids = nom de la variable de pondération. Par exemple M00E_PONDVALC2 - variable = nom de la variable pour laquelle on va calcuelr le totale et sa variance. si on veut calculer ces elements pour une modalité particulière d'une variable (par exemple SEXE = 1), il faut que variable = 1 si sexe = 1 et variable = 0 sinon. methode=1 si enquete AVANT 3 ans 1/2, methode = 2 si enquete 3 ans 1/2 et suivantes */ %if &methode=1 %then %let listeCALAGE= CS_1 CS_2 CS_3 CS_4 CS_5 CS_6 ; %if &methode=2 %then %let listeCALAGE= CS_1 CS_2 CS_3 CS_4 CS_5 CS_6 CS_7 CS_8 CS_9 CS_10 CS_11 CS_12 CS_13; data table_pour_var; set &table_selection; strateN=&strate+0; vagueN=&vague+0; run; data table_pour_var; set table_pour_var; where &poids>0 and strateN in (1,2,3,4,5) and &mater ne .; run; data table_pour_var; set table_pour_var; if &strate = 1 then _TOTALMAT_=108; else if &strate = 2 then _TOTALMAT_=108; else if &strate = 3 then _TOTALMAT_=109; else if &strate = 4 then _TOTALMAT_=108; else if &strate = 5 then _TOTALMAT_=111; if &strate = 1 then _MATsel_=25; else if &strate = 2 then _MATsel_=44; else if &strate = 3 then _MATsel_=62; else if &strate = 4 then _MATsel_=88; else if &strate = 5 then _MATsel_=101; if &vague = 1 then _TOTALJOUR_=90; else if &vague = 2 then _TOTALJOUR_=91; else if &vague = 3 then _TOTALJOUR_=92; else if &vague = 4 then _TOTALJOUR_=92; if &vague = 1 then _JOURsel_=4; else if &vague = 2 then _JOURsel_=6; else if &vague = 3 then _JOURsel_=7; else if &vague = 4 then _JOURsel_=8; pondAVANT_calage = (_TOTALMAT_ * _TOTALJOUR_) / (_MATsel_ * _JOURsel_) ; probaR=pondAVANT_calage/&poids; run; proc sql; create table ESTIMATION_TOTAL as select sum (&variable * &poids) as estimation from table_pour_var; quit; data _null_; set ESTIMATION_TOTAL; CALL SYMPUT('TOTAL',estimation); run; /* regression pondérée par poids de la var d'interet sur les variavbles de calage*/ proc glm data=table_pour_var noprint ; class &listeCALAGE ; model &variable = &listeCALAGE ; weight &poids; output out=residus RESIDUAL = res; run; data residus (keep= &identifiant res); set residus; run; /* fin regression */ proc sort data= table_pour_var; by &identifiant; run; proc sort data= residus; by &identifiant; run; data tableRES; merge table_pour_var residus; by &identifiant; run; /* ------------------- estimation VARIANCE sur residus-------------------------------------------- ------------------------------------------------------------------------------------------------------- */ title 'surveymeans sur RES - ne pas prendre en compte'; proc surveymeans data=tableRES total=degreM mean clm stderr var sum clsum std varsum ; *clm = IC de la moyenne, clmsum=IC de la somme std= standar erreur de la somme; weight &poids; cluster &mater; strata strateN; var res; ods output Statistics=MyStatM; run; proc surveymeans data=tableRES total=degreJ mean clm stderr var sum clsum std varsum ; *clm = IC de la moyenne, clmsum=IC de la somme std= standar erreur de la somme; weight &poids; cluster &jour; strata vagueN; var res; ods output Statistics=MyStatJ; run; * variance due à la NR; proc sql; create table NR_calage as select sum (res*res*(1-probaR)/(probaR*probaR*(1/pondAVANT_calage)*(1/pondAVANT_calage))) as effetNR from tableRES; run;quit; data _null_; set MyStatM; CALL SYMPUT('var_calage_effetMAT',varsum); run; data _null_; set MyStatJ; CALL SYMPUT('var_calage_effetJOUR',varsum); run; data _null_; set NR_calage; CALL SYMPUT('NR_calage',effetNR); run; proc sql; create table recapTOTAL_&variable as select &TOTAL as total, &var_calage_effetMAT as var_calage_effetMAT, &var_calage_effetJOUR as var_calage_effetJOUR, &NR_calage as variance_NR, &NR_calage+&var_calage_effetJOUR+&var_calage_effetMAT as variance_TOTALE, &var_calage_effetMAT+&NR_calage as variance_PLAN_SIMPLIFIE, sqrt(&var_calage_effetMAT+&NR_calage) as etype_PLAN_SIMPLIFIE, &TOTAL - 1.96* sqrt(&var_calage_effetMAT+&NR_calage) as borneinf95_PLAN_SIMPLIFIE, &TOTAL + 1.96* sqrt(&var_calage_effetMAT+&NR_calage) as bornesup95_PLAN_SIMPLIFIE from ESTIMATION_TOTAL ; run;quit; title 'resultat estimation TOTAL: données stockées dans la table recapTOTAL_&variable'; proc sql; select * from recapTOTAL_&variable ; run; quit; proc delete data=table_pour_var;run; proc delete data=ESTIMATION_TOTAL;run; proc delete data=residus;run; proc delete data=tableres;run; proc delete data=nr_calage;run; %mend; %macro RATIO (table_selection, identifiant, strate, vague, mater,jour, poids, variable1, variable2, methode); title ''; /* table_selection=nom de la table où sont les données. Il faut dans cette table, les champs suivants: - Les variables de calage CS_1 à CS_XX - identifiant = champs identifiant les enregistrements ID... - strate = champs qui identifie la strate de la maternité. Par défaut M00M1_MATSTRATEC1 - vague = champs qui identifie la vague de l'enquête. Par défaut M00M1_VAGUE - mater = champs qui identifie la maternité. Par défaut M00M1_IDGROUPNAMEALEAC1 - jour = champs qui identifie le jour. Par défaut M00M2_JNAISSEALEA - poids = nom de la variable de pondération. Par exemple M00E_PONDVALC2 - variable1 = nom de la variable pour laquelle on va calcuelr le NUMERATEUR - variable2 = nom de la variable pour laquelle on va calcuelr le DENOMINATEUR methode=1 si enquete AVANT 3 ans 1/2, methode = 2 si enquete 3 ans 1/2 et suivantes */ %if &methode=1 %then %let listeCALAGE= CS_1 CS_2 CS_3 CS_4 CS_5 CS_6 ; %if &methode=2 %then %let listeCALAGE= CS_1 CS_2 CS_3 CS_4 CS_5 CS_6 CS_7 CS_8 CS_9 CS_10 CS_11 CS_12 CS_13; data table_pour_var; set &table_selection; strateN=&strate+0; vagueN=&vague+0; run; data table_pour_var; set table_pour_var; where &poids>0 and strateN in (1,2,3,4,5) and &mater ne .; run; data table_pour_var; set table_pour_var; if &strate = 1 then _TOTALMAT_=108; else if &strate = 2 then _TOTALMAT_=108; else if &strate = 3 then _TOTALMAT_=109; else if &strate = 4 then _TOTALMAT_=108; else if &strate = 5 then _TOTALMAT_=111; if &strate = 1 then _MATsel_=25; else if &strate = 2 then _MATsel_=44; else if &strate = 3 then _MATsel_=62; else if &strate = 4 then _MATsel_=88; else if &strate = 5 then _MATsel_=101; if &vague = 1 then _TOTALJOUR_=90; else if &vague = 2 then _TOTALJOUR_=91; else if &vague = 3 then _TOTALJOUR_=92; else if &vague = 4 then _TOTALJOUR_=92; if &vague = 1 then _JOURsel_=4; else if &vague = 2 then _JOURsel_=6; else if &vague = 3 then _JOURsel_=7; else if &vague = 4 then _JOURsel_=8; pondAVANT_calage = (_TOTALMAT_ * _TOTALJOUR_) / (_MATsel_ * _JOURsel_) ; probaR=pondAVANT_calage/&poids; run; proc sql; create table ESTIMATION_TOTAL as select N as estim_NUM,D as estim_DEN,N/D as estimateur from (select sum (&variable1 * &poids) as N, sum (&variable2 * &poids) as D from table_pour_var) as t; quit; data _null_; set ESTIMATION_TOTAL; CALL SYMPUT('numerateur',estim_NUM); CALL SYMPUT('denominateur',estim_DEN); CALL SYMPUT('ratio',estimateur); run; data table_pour_var; set table_pour_var ; /*pour ration X/Y: uk = (1/Ty).(Xk - R Yk)*/ Ratio_i = (1/&denominateur)*(&variable1 - &ratio*&variable2); run; /* regression pondérée par poids de la var d'interet sur les variavbles de calage*/ proc glm data=table_pour_var noprint ; class &listeCALAGE ; model Ratio_i = &listeCALAGE ; * ATTENTION/ quel POIDS ?????; weight &poids; output out=residus RESIDUAL = res; run; data residus (keep= &identifiant res); set residus; run; /* fin regression */ proc sort data= table_pour_var; by &identifiant; run; proc sort data= residus; by &identifiant; run; data tableRES; merge table_pour_var residus; by &identifiant; run; /* ------------------- estimation VARIANCE sur residus-------------------------------------------- ------------------------------------------------------------------------------------------------------- */ title 'surveymeans sur RES - ne pas prendre en compte'; proc surveymeans data=tableRES total=degreM mean clm stderr var sum clsum std varsum; *clm = IC de la moyenne, clmsum=IC de la somme std= standar erreur de la somme; weight &poids; cluster &mater; strata strateN; var res; ods output Statistics=StatRATM; run; proc surveymeans data=tableRES total=degreJ mean clm stderr var sum clsum std varsum; *clm = IC de la moyenne, clmsum=IC de la somme std= standar erreur de la somme; weight &poids; cluster &jour; strata vagueN; var res; ods output Statistics=StatRATJ; run; * variance due à la NR; proc sql; create table NR_calage as select sum (res*res*(1-probaR)/(probaR*probaR*(1/pondAVANT_calage)*(1/pondAVANT_calage))) as effetNR from tableRES; run;quit; data _null_; set StatRATM; CALL SYMPUT('var_calage_effetMAT',varsum); run; data _null_; set StatRATJ; CALL SYMPUT('var_calage_effetJOUR',varsum); run; data _null_; set NR_calage; CALL SYMPUT('NR_calage',effetNR); run; proc sql; create table recapRATIO_&variable1 as select &numerateur as numerateur, &denominateur as denominateur, &ratio as ratio, &var_calage_effetMAT as var_calage_effetMAT, &var_calage_effetJOUR as var_calage_effetJOUR, &NR_calage as variance_NR, &NR_calage+&var_calage_effetJOUR+&var_calage_effetMAT as variance_TOTALE, &var_calage_effetMAT+&NR_calage as variance_PLAN_SIMPLIFIE, sqrt(&var_calage_effetMAT+&NR_calage) as etype_PLAN_SIMPLIFIE, &ratio - 1.96* sqrt(&var_calage_effetMAT+&NR_calage) as borneinf95_PLAN_SIMPLIFIE, &ratio + 1.96* sqrt(&var_calage_effetMAT+&NR_calage) as bornesup95_PLAN_SIMPLIFIE from ESTIMATION_TOTAL ; run;quit; title 'RESULTATS estimation ratio: données stockées table recapRATIO_&variable1'; proc sql; select * from recapRATIO_&variable1 ; run; quit; proc delete data=table_pour_var;run; proc delete data=ESTIMATION_TOTAL;run; proc delete data=residus;run; proc delete data=tableres;run; proc delete data=nr_calage;run; %mend;