/*********************************************************************/ /*********************************************************************/ ** January 12, 2009 ** This program automatically runs and tabulates bivariate analyses of a ** a logistic regression for the occurrence of delirium within ** 48 hours of ICU admission. We evaluate the Type 3 association with the ** Chi-Square stat based on the Likelihood Ratio and its associated p-value ** from proc genmod to create a subset of candidate variables ** for potential inclusion in a multi-variable model. The column names ** in output table were changed to "LRchisquare" and "pval" respectively ** to more clearly indicate they are generated from proc genmod type 3. Proc ** logistic is also used to generate labels and information that ** facilitate creation of the table. Much of this code was first written by ** Katy Araujo at the Yale Program on Aging as part of her work on the EPIC ** project under Margaret Pisani, M.D. ; /* Copyright (C) 2009 Terrence E. Murphy, PhD This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ /*********************************************************************/; *libname grasp 'e:\PepperCenter\GRASP\submissions\MacroBivarMurphy\'; data tempIN; set /*grasp.*/ MacroBivDataSanMurphy; run; /*MACROS*/ /*CONTINUOUS VARIABLES*/ * first macro is created for continuous variables as it tabulates * mean and SD whereas the second macro, for categorical variables, * calculates prevalence *run logistic model for information on Number of observations; title 'Bivariate Analyses of Risk Factors for ICU Delirium'; %macro cont (var1); proc logistic DATA = tempIN descending ; model icuconf_day1 = &var1 / lackfit link = logit; ODS OUTPUT nobs=observ responseprofile=profile ModelInfo=mi; run; *run genmod to generate type 3 LR chi-squ stat and output ODS tables; proc genmod DATA = tempIN descending ; model icuconf_day1 = &var1 /d = b type3 ; ODS OUTPUT type3=pvalue; run; /* Save means information on continuous variables for table*/ proc means data=tempIN; var &var1; ods output summary=mstd; run; data mean; set mstd; mean=&var1._mean; std=&var1._stddev; keep mean std; run; /* Process observation data generated by proc logistic */ data obs; set observ (keep = nobsread nobsused); by nobsread; if first.nobsread; run; *Keep only first observation from table OBSERV; *Trim OBSERV table to only variables of interest (number of observations read and used); /* data odds; set or (keep = oddsratioest); run; *Trim OR table to only variables of interest (odds ratio); data estimates; set pe (keep = variable probchisq); if upcase(variable)=upcase("&var1"); run; *Trim PE table to only variables of interest (p-value); */ /* here we merge the output data created by procs logistic and genmod for creation of final output table */ *Merge ODS tables to create a dataset with variables of interest for the report from continuous; data &var1; merge obs pvalue(keep=source chisq probchisq) mean; length vname $ 32.; vname=source; LRchisquare=chisq; pval=probchisq; run; %mend; /*CATEGORICAL VARIABLES*/ * this second macro, for categorical variables, * calculates prevalence rather than mean and SD; %macro categ (var1); *run logistic model for observations numbers; proc logistic DATA = tempIN descending ; model icuconf_day1 = &var1 /lackfit link = logit ; ODS OUTPUT nobs=observ ModelInfo=mi; run; *run genmod for type 3 stats; proc genmod DATA = tempIN descending ; class &var1 / ref=first param=ref; model icuconf_day1 = &var1 / d = b type3 ; ODS OUTPUT type3=pvalue; run; quit; *run proc freq for calc. of prevalence ; proc freq data=tempIN; tables &var1; ods output onewayfreqs=categ; run; data categ; set categ (keep = &var1 frequency); if &var1=1; run; *Keep only first observation from table OBSERV; *Trim OBSERV table to only variables of interest (number of observations read and used); data obs; set observ (keep = nobsread nobsused); by nobsread; if first.nobsread; run; /* data odds; set or (keep = oddsratioest); run; *Trim OR table to only variables of interest (odds ratio); data estimates; set pe (keep = variable probchisq); if upcase(variable)=upcase("&var1"); run; *Trim PE table to only variables of interest (p-value); */ *Merge ODS tables to create a dataset with variables of interest for the report from categorical; data &var1; merge obs pvalue(keep=source chisq probchisq) categ; length vname $ 32.; LRchisquare=chisq; pval=probchisq; vname=source; prevalence=frequency/nobsused; run; %mend; /*CALL THE CORRESPONDING MACRO FOR EACH OF THE VARIABLES OF INTEREST */ /*BE SURE TO PICK THE CORRECT MACRO, I.E. CATEGORICAL OR CONTINUOUS*/ %categ(buncr18_san); %categ(dep_san); %categ(HiAlt_san); %categ(iqcodea_san); %cont(aps17_25_san); %cont(bmi_san); %cont(ventilated_san); /* generate list of final variables for final output table*/ data final; set buncr18_san DEP_san hiAlt_san iqcodea_san aps17_25_san bmi_san ventilated_san; /*!!!TERRY - ADD ALL VARIABLES OF INTEREST HERE*/ run; /*USE PROC CONTENTS TO OUTPUT THE VARIABLE LABELS*/ proc contents data = tempIN; ods output variables = varlabel;run; proc sort data=varlabel; by variable;run; proc sort data=final; by vname;run; /*CREATE REPORT DATASET*/ data report; merge final (in=a) varlabel (keep = variable label rename=(variable=vname)); by vname; if a; run; /*OUTPUT REPORT TO WORD DOCUMENT*/ ods rtf file = 'e:\PepperCenter\GRASP\submissions\MacroBivarMurphy\MacroBivOutputMurphy.rtf'; proc print data=report noobs; var vname label prevalence mean std LRchisquare pval nobsused; run; ods rtf close;