/*=============================================================== * File: PDI_Area.SAS * Title: MONAHRQ Utility Files for SAS; * * Description: * Reformats the SAS QI to WinQI style output; * for PDI Area level QIs; * * Prepared by Truven Health Analytics; * * VERSION 1.0, AUGUST 2012; * *===============================================================*/ options ls=120 ps=55 nocenter ; FILENAME CONTROL 'C:\PATHNAME\CONTROL_PDI.SAS'; *<===USER MUST modify; %include control ; %let pgm_=PDI_Area; *---------------------------------*; * get the variable names from the *; * output SAS data set produced by *; * SAS qi *; *---------------------------------*; proc contents data=outp3.PDa3 noprint out=PDa3Vars ; run ; proc print data=PDa3Vars ; var name label ; title3 "output from proc contents on PDa3 data set" ; run cancel ; data toNull ; set PDa3Vars(keep=name) ; if upcase(substr(name,3,2))='PQ' ; QI=compress("PQI"||upcase(substr(name,5,2))) ; Varclass=compress(substr(name,1,4)||'xx'); run ; proc sort data=toNull ; by qi Varclass name ; run ; proc print data=toNull ; title3 "List of variables to convert, sorted" ; run ; *--------------------------*; * grab location of SAS work*; * directory. *; *--------------------------*; %let wdir_ = %sysfunc(getoption(work)); %put &wdir_. is the working directory; *-----------------------------*; * Create a data step for each *; * QI and output variables from*; * Battelle SAS data set. *; *-----------------------------*; data _null_ ; set ToNull ; by qi Varclass name ; file "&wdir_.\&pgm_._temp.txt" ; length keeplist $200 ; retain keeplist ' ' ; if first.qi then do ; put "Data " qi " ;" / " set outp3.PDa3 ; " / " QI='" QI "' ;" ; keeplist=trim(keeplist)||" QI marea POPcat sexcat racecat "; end ; put " " varclass "=" name " ;" ; keeplist=trim(keeplist)||" "||varclass ; if last.qi then do ; put " keep " keeplist " ;" ; put "run ;" ; keeplist='' ; end ; run ; *-------------------------*; * Run the data steps. *; *-------------------------*; %include "&wdir_.\&pgm_._temp.txt" ; *----------------------------------*; * Create SAS steps to concatenate *; * all the QI specific data sets *; * into one. *; *----------------------------------*; proc sort data=toNull out=QIlist(keep=qi) nodupkey ; by qi ; run ; proc print data=QIlist ; title3 "Unique QIs in output data set from Battelle SAS qi" ; run ; data _null_ ; set QIlist end=eof ; file "&wdir_.\&pgm_._temp2.txt" ; by qi ; if _n_=1 then do ; put "Data PDI_A3(rename=(charArea=County)) ;" / " length Module $3 Ind_num $3 ; " / " retain module Ind_num charArea taPQxx paPQxx oaPQxx obslci obsuci " / " eaPQxx oe refpop raPQxx laPQxx uaPQxx saPQxx ; " / " keep module Ind_num charArea taPQxx paPQxx oaPQxx obslci obsuci " / " eaPQxx oe refpop raPQxx laPQxx uaPQxx saPQxx ; " / " set " ; end ; put " " qi / ; if eof then do ; *-----------------------------------*; * 30Apr12tak: Steal logic from A3 in*; * SAS QI process for PQI to calc *; * Observed Se and CIs *; *-----------------------------------*; put " ; " / " drop Marea ; " / " charArea=put(compress(Marea),$county.) ; " / " if compress(charArea)='' then charArea='TOTAL' ; " / " module=substr(compress(QI),1,3) ; " / " Ind_Num=substr(compress(QI),4) ; " / " if POPcat=. and sexcat=. and racecat=. then do ;" / " if OaPQxx > . then do ; " / " OE=OaPQxx/EaPQxx ; " / " ObsSe=sqrt( (OaPQxx*(1-OaPQxx))/(PaPQxx) ) ; " / " ObsVr=ObsSe**2 ; " / " end ; " / " end ; " / " else do ; " / " if OaPQxx > . then do ; " / " OE=OaPQxx/EaPQxx ; " / " ObsSe=sqrt( (OaPQxx*(1-OaPQxx))/(PaPQxx) ) / EaPQxx ; " / " ObsVr=. ; " / " end ; " / " end ; " / " if OaPQxx > . then do ; " / " ObsLCI=OaPQxx-(1.96 * ObsSe) ;" / " ObsUCI=OaPQxx+(1.96 * ObsSe) ;" / " if . < ObsLCI < 0 then ObsLCI=0 ; " / " if ObsUCI > 1 then ObsUCI=1 ; " / " end ; " / " RefPOP=. ;" / " label " / " module='Module' " / " Ind_num='Indicator Number' " / " charArea='County' " / " TaPQxx='Observed Numerator' " / " PaPQxx='Observed Denominator' " / " OaPQxx='Observed Rate' " / " ObsLCI='Observed Conf Int. Low' " / " ObsUCI='Observed Conf Int. High' " / " EaPQxx='Expected Rate' " / " OE='O-E Ratio'" / " RefPOP='Reference Pop Rate' " / " RaPQxx='Risk Adjusted Rate' " / " LaPQxx='Risk Adj Conf Int. Low' " / " UaPQxx='Risk Adj Conf Int. High'" / " SaPQxx='Smoothed Rate' ;" / "run ;" ; end ; run ; proc format ; value $county ''='TOTAL' ; run ; %include "&wdir_.\&pgm_._temp2.txt" ; proc print data=PDI_A3 noobs ; id module ; title3 "New version of A3 output from Battelle SAS QI" ; run ; *---------------------------------------*; * export to a csv *; *---------------------------------------*; %let _EFIERR_ = 0; /* set the ERROR detection macro variable */ %let _EFIREC_ = 0; /* clear export record count macro variable */ data _null_; file "&pgm_._PDI_A3.csv" delimiter=',' DSD DROPOVER lrecl=32767; if _n_ = 1 then do; /* write column labels */ put "Module" ',' "Indicator Number" ',' "County" ',' "Observed Numerator" ',' "Observed Denominator" ',' "Observed Rate" ',' "Observed Conf Int. Low" ',' "Observed Conf Int. High" ',' "Expected Rate" ',' "O-E Ratio" ',' "Reference Pop Rate" ',' "Risk Adjusted Rate" ',' "Risk Adj Conf Int. Low" ',' "Risk Adj Conf Int. High" ',' "Smoothed Rate" ; end; set PDI_A3 end=EFIEOD; format Module $3. ; format Ind_num $3. ; format County $5. ; format taPQxx best12. ; format paPQxx best12. ; format oaPQxx best12. ; format obslci best12. ; format obsuci best12. ; format eaPQxx best12. ; format oe best12. ; format refpop best12. ; format raPQxx best12. ; format laPQxx best12. ; format uaPQxx best12. ; format saPQxx best12. ; do; EFIOUT + 1; put Module $ @; put Ind_num $ @; put County $ @; put taPQxx @; put paPQxx @; put oaPQxx @; put obslci @; put obsuci @; put eaPQxx @; put oe @; put refpop @; put raPQxx @; put laPQxx @; put uaPQxx @; put saPQxx ; ; end; if _ERROR_ then call symputx('_EFIERR_',1); /* set ERROR detection macro variable */ if EFIEOD then call symputx('_EFIREC_',EFIOUT); run; /**//****************************//**/