/*___________________________________________________________________ ¦ MACRO: AGREEMENT ¦ ¦ JOB: Data Quality ¦ ¦ PROGRAMMER: Mahmoud Azimaee ¦ ¦ DATE: April 2011 ¦ ¦ DESCRIPTION: This Macro checks the agreement between a dataset ¦ ¦ and the Registry for the same individuals and ¦ ¦ produces Kappa Statistics for Sex and Date of Birth¦ ¦ PARAMETERS: DS= Name of Dataset ¦ ¦ REGYR= Latest Available Registry File(Default=2010)¦ ¦ PHIN= Variable containing PHIN (Default=SCRPHIN) ¦ ¦ SEX= Variable containing SEX (Default=SEX) ¦ ¦ M= Representing value for Males (Default=1) ¦ ¦ F= Representing value for Females (Default=2) ¦ ¦ BIRTHDT= Variable containing Date of Birth ¦ ¦ (Default=BIRTHDT) ¦ ¦ EXAMPLE: %AGREEMENT (DS=health.MHCPL_SPsection_19922010); ¦ ¦ EXAMPLE: %AGREEMENT (DS=health.MHCPL_SPsection_19922010 ¦ ¦ , REGYR=2009); ¦ ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯*/ **********************************************************************; %MACRO AGREEMENT (DS=, REGYR=2010 ,PHIN=SCRPHIN, SEX=SEX, M=1, F=2, BIRTHDT=BIRTHDT); %PUT ___________________________________________________________________; %PUT ¦ Manitoba Centre for Health policy (MCHP) ¦; %PUT ¦ MACRO: AGREEMENT ¦; %PUT ¦ JOB: Data Quality ¦; %PUT ¦ PROGRAMMER: Mahmoud Azimaee ¦; %PUT ¦ DATE: April 2011 ¦; %PUT ¦ Running for: &DS; %PUT ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯; %IF &PHIN=SCRPHIN %THEN %LET PHINTYPE=SCRPHINTYPE; %ELSE %LET PHINTYPE=FILEPHINTYPE; data reg; set REGISTRY.MHMRS_UNIQPHIN_1970®YR (keep=&PHIN RIBIRTHDT SEX rename=(SEX=Reg_SEX)); by &PHIN; if last.&PHIN; run; proc sort data=&DS (keep=&PHIN &BIRTHDT &SEX &PHINTYPE) out=sorted; by &PHIN; run; data demo; merge sorted (in=in_data) reg (in=in_reg ); by &PHIN; if in_data; if last.&PHIN; if &PHINTYPE in('0','1','2','3','6'); reg_birth=substr(put(RIBIRTHDT,YYMMDD6.),1,4); data_birth=substr(put(&BIRTHDT,YYMMDD6.),1,4); if &SEX="&M" then &SEX='1'; if &SEX="&F" then &SEX='2'; if &SEX ^in ('1', '2') then &SEX='' ; if &SEX='' | Reg_SEX='' then do; &SEX=''; Reg_SEX=''; end; if reg_birth='' | data_birth='' then do; reg_birth=''; data_birth=''; end; run; proc freq data=demo noprint; table &sex*reg_sex / list AGREE; output out=kappa_sex agree; run; *** To have equal number of columns and rows which is required for KAPPA Agreement Test, this part of the macro creates all possible combination of DOB (MMYY only) and then runs a PROC FREQ with the ZEROS option; proc freq data=demo noprint ; table reg_birth*data_birth / sparse out=demo_out ; run; data demo_out; set demo_out; if reg_birth='' | data_birth='' then delete; run; data reg_birth(keep=data_birth rename=(data_birth=birth)) data_birth(keep=reg_birth rename=(reg_birth=birth)); set demo_out; run; data birth; set data_birth reg_birth; reg_birth=birth; rename birth=data_birth; run; proc sort data=birth nodupkey; by reg_birth data_birth; run; proc freq data=birth noprint; table reg_birth*data_birth/ sparse list out=demo_tmp; run; data demo_tmp; set demo_tmp; keep reg_birth data_birth; run; proc sort data=demo_tmp; by reg_birth data_birth; run; data demo_new; merge demo_out demo_tmp; by reg_birth data_birth; if Count=. then count=0; drop PERCENT; run; proc freq data=demo_new noprint; table reg_birth*data_birth / list AGREE ; weight count/ zeros; output out=kappa_dob agree; run; Data kappa; set kappa_sex (in=in_sex) kappa_dob (in=in_dob); if in_sex then Var='SEX '; if in_dob then Var='Date of Birth'; label VAR='Agreement Variable'; run; Title"KAPPA Statistics for Agreement Between &DS and REGISTRY.MHMRS_UNIQPHIN_1970®YR"; Title2'Categoriziation for Date of Birth was done by truncating DD and keeping YYMM'; proc print data=kappa label noobs; var VAR N _KAPPA_ ; run; proc sql; create table kappa as select vAR ,N ,_KAPPA_ from kappa; quit; %LET FILENAME= &DS._Agreement.xls; PROC EXPORT DATA= WORK.kappa OUTFILE= "/dq/saswork/&spdsuser/&FILENAME" /*where /dq/saswork/&spdsuser is the Directory to save the output*/ DBMS=XLS REPLACE; RUN; proc Datasets lib=work; delete demo reg kappa_sex kappa_dob birth data_birth demo_new demo_out demo_tmp kappa reg_birth sorted; run; quit; %MEND AGREEMENT;