/*=============================================================== * File: PSI_Area.SAS * Title: MONAHRQ Utility Files for SAS; * * Description:; * Reformats the SAS QI to WinQI style output; * for PSI Area level QIs; * * Prepared by Truven Health Analytics; * * VERSION 1.0, AUGUST 2012; * *===============================================================*/ options ls=120 ps=55 nocenter ; FILENAME CONTROL 'C:\PATHNAME\CONTROL_PSI.SAS'; *<===USER MUST modify; %include control ; %let pgm_=PSI_Area; *---------------------------------*; * get the variable names from the *; * output SAS data set produced by *; * SAS qi *; *---------------------------------*; proc contents data=outp3.PSa2 noprint out=PSa2Vars ; run ; proc print data=PSa2Vars ; var name label ; title3 "output from proc contents on PSa2 data set" ; run cancel ; data toNull ; set PSa2Vars(keep=name) ; if upcase(substr(name,3,2))='PS' ; QI=compress("PSI"||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.PSa2 ; " / " QI='" QI "' ;" ; keeplist=trim(keeplist)||" QI marea agecat 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 PSI_a2(rename=(charArea=County)) ;" / " length Module $3 Ind_num $3 ; " / " retain module Ind_num charArea taPSxx paPSxx oaPSxx obslci obsuci " / " eaPSxx oe refpop raPSxx laPSxx uaPSxx saPSxx ; " / " keep module Ind_num charArea taPSxx paPSxx oaPSxx obslci obsuci " / " eaPSxx oe refpop raPSxx laPSxx uaPSxx saPSxx ; " / " set " ; end ; put " " qi / ; if eof then do ; *-----------------------------------*; * 30Apr12tak: Steal logic from a2 in*; * SAS QI process for PSI 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) ; " / " eaPSxx=. ; " / " raPSxx=. ; " / " laPSxx=. ; " / " uaPSxx=. ; " / " RefPOP=. ;" / " SaPSxx=. ;" / " if agecat=. and sexcat=. and racecat=. then do ;" / " if OaPSxx > . then do ; " / " OE=OaPSxx/EaPSxx ; " / " ObsSe=sqrt( (OaPSxx*(1-OaPSxx))/(PaPSxx) ) ; " / " ObsVr=ObsSe**2 ; " / " end ; " / " end ; " / " else do ; " / " if OaPSxx > . then do ; " / " OE=OaPSxx/EaPSxx ; " / " ObsSe=sqrt( (OaPSxx*(1-OaPSxx))/(PaPSxx) ) / EaPSxx ; " / " ObsVr=. ; " / " end ; " / " end ; " / " if OaPSxx > . then do ; " / " ObsLCI=OaPSxx-(1.96 * ObsSe) ;" / " ObsUCI=OaPSxx+(1.96 * ObsSe) ;" / " if . < ObsLCI < 0 then ObsLCI=0 ; " / " if ObsUCI > 1 then ObsUCI=1 ; " / " end ; " / " label " / " module='Module' " / " Ind_num='Indicator Number' " / " charArea='County' " / " TaPSxx='Observed Numerator' " / " PaPSxx='Observed Denominator' " / " OaPSxx='Observed Rate' " / " ObsLCI='Observed Conf Int. Low' " / " ObsUCI='Observed Conf Int. High' " / " EaPSxx='Expected Rate' " / " OE='O-E Ratio'" / " RefPOP='Reference Pop Rate' " / " RaPSxx='Risk Adjusted Rate' " / " LaPSxx='Risk Adj Conf Int. Low' " / " UaPSxx='Risk Adj Conf Int. High'" / " SaPSxx='Smoothed Rate' ;" / "run ;" ; end ; run ; proc format ; value $county ''='TOTAL' ; run ; %include "&wdir_.\&pgm_._temp2.txt" ; proc print data=PSI_a2 noobs ; id module ; title3 "New version of a2 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_._PSI_a2.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 PSI_a2 end=EFIEOD; format Module $3. ; format Ind_num $3. ; format County $5. ; format taPSxx best20. ; format paPSxx best20. ; format oaPSxx best20. ; format obslci best20. ; format obsuci best20. ; format eaPSxx best20. ; format oe best20. ; format refpop best20. ; format raPSxx best20. ; format laPSxx best20. ; format uaPSxx best20. ; format saPSxx best20. ; do; EFIOUT + 1; put Module $ @; put Ind_num $ @; put County $ @; put taPSxx @; put paPSxx @; put oaPSxx @; put obslci @; put obsuci @; put eaPSxx @; put oe @; put refpop @; put raPSxx @; put laPSxx @; put uaPSxx @; put saPSxx ; ; end; if _ERROR_ then call symputx('_EFIERR_',1); /* set ERROR detection macro variable */ if EFIEOD then call symputx('_EFIREC_',EFIOUT); run; /**//****************************//**/