**************************************************************************************************** * PROGRAM OVERVIEW **************************************************************************************************** * * PROGRAM: ms_runmodel.sas * * Created (mm/dd/yyyy): 12/07/2015 * Last modified: 05/18/2017 * Version: 1.1 * *-------------------------------------------------------------------------------------------------- * PURPOSE: Run logit models and associated diagnostics * *-------------------------------------------------------------------------------------------------- * CONTACT INFO: * Mini-Sentinel Coordinating Center * info@mini-sentinel.org * *-------------------------------------------------------------------------------------------------- * CHANGE LOG: * * Version Date Initials Comment (reference external documentation when available) * ------- -------- -------- --------------------------------------------------------------- * 1.1 05/18/2017 AP Added race/hispanic to diagnostics * ****************************************************************************************************; %macro ms_runmodel(model_num, infile, CategoricalVars, ContinuousVars, HDPSVars, var_exposure, var_patient_id, outfile); %put NOTE: Running PS model &model_num; %put NOTE: The PS model will predict &var_exposure; %put NOTE: Categorical variables, if any, are &CategoricalVars.; %put NOTE: Continuous variables, if any, are &ContinuousVars.; %put NOTE: HDPS variables, if any, are &HDPSVars; proc datasets library=work nowarn nolist; delete t_c t_converge hd_&model_num; quit; /* create a default output dataset with missing PS */ /* this will exist even if the logistic model fails */ DATA &outfile.; SET &infile(KEEP=&var_patient_id); ps = .; RUN; %if &DIAGNOSTICS.=1 %then %do; ods rtf file="&MSOC.&RUNID._runmodel_out_&comp._&look..rtf"; %end; TITLE "Logistic Regression with COMP=&grp1. and CONTROL=&grp2."; ods output Association = fit; ods output ConvergenceStatus = converge; *Defensive coding if no class variables; %put &CategoricalVars.; %IF "&CategoricalVars." ne "" %THEN %DO; ods output ClassFreq = ClassFreqs; %END; ods output Nobs = Nobs; ods output SimpleStatistics = simple; ods output ParameterEstimates = param; %if &DIAGNOSTICS.=1 %then %do; ods output IterHistory = itprint; %end; proc logistic data = &infile(keep=&var_patient_id &var_exposure &CategoricalVars &ContinuousVars &HDPSVars) descending simple; class &CategoricalVars; model &var_exposure = &CategoricalVars &ContinuousVars &HDPSVars %if &DIAGNOSTICS.=1 %then %do;/ITPRINT;%end;; output out = &outfile.(keep=&var_patient_id ps) pred=ps; run; %if &DIAGNOSTICS.=1 %then %do; ods rtf close; %end; PROC SORT DATA=&outfile.; BY &var_patient_id; RUN; *Correlation Diagnostics; %if &DIAGNOSTICS.=1 %then %do; %LET corrClassVars=%TRIM(%SYSFUNC(TranWrd(%LOWCASE(&classvars.), sex, %STR()))); %LET corrClassVars=%TRIM(%SYSFUNC(TranWrd(%LOWCASE(&corrClassVars.), time, %STR()))); %LET corrClassVars=%TRIM(%SYSFUNC(TranWrd(%LOWCASE(&corrClassVars.), year, %STR()))); %LET corrClassVars=%TRIM(%SYSFUNC(TranWrd(%LOWCASE(&corrClassVars.), race, %STR()))); %LET corrClassVars=%TRIM(%SYSFUNC(TranWrd(%LOWCASE(&corrClassVars.), hispanic, %STR()))); %LET corrNoClassVars=%TRIM(%SYSFUNC(TranWrd(%LOWCASE(&noclassvars.), sex, %STR()))); %LET corrNoClassVars=%TRIM(%SYSFUNC(TranWrd(%LOWCASE(&corrNoClassVars.), time, %STR()))); *year could stil be used as continuous; %put &corrClassVars.; %put &corrNoClassVars.; %let racevar_fordiagnostics=; %let racevar_forreg=; %let hispvar_fordiagnostics=; %let hispvar_forreg=; %if %index(%lowcase(&classvars.), race) > 0 %then %do; %let racevar_fordiagnostics = race_0-race_5; %let racevar_forreg = race_1-race_5; %end; %if %index(%lowcase(&classvars.), hispanic) > 0 %then %do; %let hispvar_fordiagnostics = hispanic_y hispanic_n hispanic_u; %let hispvar_forreg = hispanic_n hispanic_u; %end; %local maxYr minYr; proc sql noprint; select max(year) into :maxYr from &infile.; select min(year) into :minYr from &infile.; quit; %put &minYr. &maxYr.; *remove leading space; data _NULL_; call symputx("minYr",&minYr.); call symputx("maxYr",&maxYr.); run; %put &minYr. &maxYr.; %macro wrapper; %global yearvars; %let yearvars=; data corrsfile; set temp3; if SEX="F" then sex_F=1;else sex_F=0; if SEX="M" then sex_M=1;else sex_M=0; if SEX="O" then sex_O=1;else sex_O=0; %if %index(%lowcase(&classvars.), race) > 0 %then %do; if race="0" then race_0=1; else race_0 = 0; if race="1" then race_1=1; else race_1 = 0; if race="2" then race_2=1; else race_2 = 0; if race="3" then race_3=1; else race_3 = 0; if race="4" then race_4=1; else race_4 = 0; if race="5" then race_5=1; else race_5 = 0; %end; %if %index(%lowcase(&classvars.), hispanic) > 0 %then %do; if hispanic = 'Y' then hispanic_y = 1; else hispanic_y = 0; if hispanic = 'N' then hispanic_n = 1; else hispanic_n = 0; if hispanic = 'U' then hispanic_u = 1; else hispanic_u = 0; %end; %do i=&minYr. %to &maxYr.; if year=&i. then year&i.=1;else year&i.=0; %end; *for proc reg; if "&minYr." ne "&maxYr." then call symputx("yearvars","year%eval(&minYr+1)-year&maxYr."); run; %put &yearvars.; %mend; %wrapper; ods output PearsonCorr=corrs; proc corr data=corrsfile; var sex_F sex_M sex_O &racevar_fordiagnostics. &hispvar_fordiagnostics. year&minYr.-year&maxYr. &corrClassVars. &corrNoClassVars.; run; ods output close; data corrs; set corrs; keep Variable sex_F sex_M sex_O &racevar_fordiagnostics. &hispvar_fordiagnostics. year&minYr.-year&maxYr. &corrClassVars. &corrNoClassVars.; run; proc sort;by Variable; run; proc transpose data=corrs out=corrst; by Variable; run; data msoc.&RUNID._corr_&comp._&look.; set corrst; if _N_=1 then set infolder.&COMPARE_INPUT.(keep=comp control comp_order where=(comp_order=%eval(&COMP.))); rename Variable=Var1 _NAME_=Var2 col1=Corr; run; ods rtf file="&MSOC.&RUNID._runreg_&comp._&look..rtf"; ODS GRAPHICS OFF; TITLE "OLS Regression with COMP=&grp1. and CONTROL=&grp2."; proc reg data=corrsfile; model &var_exposure = sex_F /*sex_M*/ sex_O &hispvar_forreg. &racevar_forreg. &yearvars. &corrClassVars. &corrNoClassVars. &HDPSVars /COLLINOINT VIF; quit; ODS GRAPHICS ON; ods rtf close; proc datasets library=work nowarn nolist; delete corrs:; quit; TITLE; %end; %mend;