/* This program combines the results from any or all of the three Charlson Comorbidity Index diagnosis macros, and summarizes the results for an overall diagnosis flag per patient, as well as a total score from all 17 diagnosis groups. It allows the specification of BY groups, which can identify patients (e.g., by scrphin), as well as provide additional grouping per patient, such as by diagnosis year. All BY group variables must already be defined in all input datasets, and data in these datasets must already be sorted by these groups. Using only the patient identifier (e.g., scrphin) as the BY group will produce a longitudinal index score over many years. Date: January 27, 2023 Author: Gilles Detillieux File Name: S:\support\maclib\_charlson_total.sas */ %macro _Charlson_total (DATA =, /* list of input datasets */ OUT =ccgrps, /* output dataset */ BYGRPS =, /* BY groups for individual summaries */ debug =off ) ; %put Charlson Comorbidity Index Summary ; %put Manitoba Centre for Health Policy ; %put Version 1.0 January 27, 2023 ; %* put default options into &opts variable ; %let opts=%sysfunc(getoption(mprint,)) %sysfunc(getoption(notes,)) ; %if &debug=1 | %lowcase(&debug)=debug | %lowcase(&debug)=on %then %do ; options mprint notes ; %end ; %else %do ; options nomprint nonotes ; %end ; %* Check if previous data step, or procdure had an error and stop running the macro. This assumes that the previous step is used in the macro.; %if %eval(&SYSERR>0) %then %goto out1 ; %* Check if input data specified ; %if %length(&data)=0 %then %goto out2 ; data &OUT; set &DATA ; %if %length(&BYGRPS)>0 %then BY &BYGRPS ; ; /* set up arrays for CCI group counters, initialize summaries to 0 */ array CC_INP{*} CC_GRP_1 - CC_GRP_17; array CC_OUT{*} ccgrp1 - ccgrp17; retain ccgrp1 - ccgrp17; /* with BY groups, only initialize on 1st record of last specified group */ %if %length(&BYGRPS)>0 %then if first.%scan(&BYGRPS,-1,%str( )) then ; do i = 1 to dim(CC_OUT); CC_OUT{i} = 0; end; do i = 1 to dim(CC_OUT); if CC_INP{i} then CC_OUT{i} = 1; end; %if %length(&BYGRPS)>0 %then %do; if last.%scan(&BYGRPS,-1,%str( )) then do; totalcc = sum(of ccgrp1-ccgrp17); wgtcc = sum(of ccgrp1-ccgrp10) + sum(of ccgrp11-ccgrp14)*2 + ccgrp15*3 + sum(of ccgrp16-ccgrp17)*6; output; end; %end; %else %do; totalcc = sum(of ccgrp1-ccgrp17); wgtcc = sum(of ccgrp1-ccgrp10) + sum(of ccgrp11-ccgrp14)*2 + ccgrp15*3 + sum(of ccgrp16-ccgrp17)*6; %end; label ccgrp1 = 'Charlson Comorbidity Group 1: Myocardial Infarction' ccgrp2 = 'Charlson Comorbidity Group 2: Congestive Heart Failure' ccgrp3 = 'Charlson Comorbidity Group 3: Peripheral Vascular Disease' ccgrp4 = 'Charlson Comorbidity Group 4: Cerebrovascular Disease' ccgrp5 = 'Charlson Comorbidity Group 5: Dementia' ccgrp6 = 'Charlson Comorbidity Group 6: Chronic Pulmonary Disease' ccgrp7 = 'Charlson Comorbidity Group 7: Connective Tissue Disease-Rheumatic Disease' ccgrp8 = 'Charlson Comorbidity Group 8: Peptic Ulcer Disease' ccgrp9 = 'Charlson Comorbidity Group 9: Mild Liver Disease' ccgrp10 = 'Charlson Comorbidity Group 10: Diabetes without complications' ccgrp11 = 'Charlson Comorbidity Group 11: Diabetes with complications' ccgrp12 = 'Charlson Comorbidity Group 12: Paraplegia and Hemiplegia' ccgrp13 = 'Charlson Comorbidity Group 13: Renal Disease' ccgrp14 = 'Charlson Comorbidity Group 14: Cancer' ccgrp15 = 'Charlson Comorbidity Group 15: Moderate or Severe Liver Disease' ccgrp16 = 'Charlson Comorbidity Group 16: Metastatic Carcinoma' ccgrp17 = 'Charlson Comorbidity Group 17: HIV/AIDS' totalcc = 'Sum of 17 Charlson Comorbidity Groups' wgtcc = 'Weighted Sum of 17 Charlson Comorbidity Groups'; run; options notes ; %put ; %put NOTE: _Charlson_total Finished &out created ; %put ; %goto exit ; %out1: %put ERROR: Prior Step failed with an Error submit a null data step to correct ; %goto exit ; %out2: %put ERROR: Input Datasets Were Not Specified; %goto exit ; %exit: %**** Reset the SAS options ; options &opts ; %mend _Charlson_total; /************ Example Program Code ***************** %let keepdad=scrphin acqdt provcd admdt sepdt hosp transact abstracttype los admitstatus admcategory sex diag01-diag25 diagtype01-diagtype25; data hosp10; set health.mhhosp_2016apr_dad (in=dad keep=&keepdad.) health.mhhosp_2017apr_dad (in=dad keep=&keepdad.) health.mhhosp_2018apr_dad (in=dad keep=&keepdad.) health.mhhosp_2019apr_dad (in=dad keep=&keepdad.); where mod(scrphin,1e6) = 0 and provcd = 'MB' and "01apr2016"d <= admdt <= "31mar2021"d; dxyear = year(admdt); run; proc sort data=hosp10; by scrphin dxyear; run; data med; set health.mhmed_1997apr (keep=scrphin acqdt servdt diag diagicd prefix tariff md refmd mdbloc nserv fee opd ngc mgc) health.mhmed_2018sep (keep=scrphin acqdt servdt diag diag_icd5 diagicd prefix tariff md_code refmd_code mdbloc nserv fee opd ngc mgc); where mod(scrphin,1e6) = 0 and prefix = '7' and "01apr2016"d <= servdt <= "31mar2021"d and diag ^in: (' ','A','B','C'); *** exclude missing & chiropractic diag; dxyear = year(servdt); run; proc sort data=med; by scrphin dxyear; run; * macro calls *; %_CharlsonICD9med(data=med); %_CharlsonICD10(data=hosp10, type=on); %_Charlson_total(DATA =hosp10 med, OUT =CC_groups, BYGRPS =scrphin dxyear); **************************************************; * Analysis Section of program *; **************************************************; PROC FREQ data=CC_groups; TITLE1 "Charlson Comorbidity Groups in Hospital and Medical Records"; TITLE2 "Using ICD-10-CA and ICD-9-CM Coding"; TABLES ccgrp: totalcc wgtcc; RUN; ****/