****************************************************************************************************
* PROGRAM OVERVIEW
****************************************************************************************************
*
* PROGRAM: figure_t5_createdata.sas
* Created (mm/dd/yyyy): 09/08/2021
*
*--------------------------------------------------------------------------------------------------
* PURPOSE: Create dataset formatted to produce Figures for Type 5 report.
*
* Program inputs:
* -agg_t5_firsteps
*
* Program outputs:
* - figure123.sas7bdat
*
* PARAMETERS:
* - N/A
*
* Programming Notes:
*
*
*--------------------------------------------------------------------------------------------------
* CONTACT INFO:
* Sentinel Coordinating Center
* info@sentinelsystem.org
*
***************************************************************************************************;
%macro figure_t5_createdata();
%put =====> MACRO CALLED: figure_t5_createdata;
/*--------------------------------------------------------------------------------------------*/
/* Dataset exists */
/*--------------------------------------------------------------------------------------------*/
%isdata(dataset=agg_t5first);
%if %eval(&nobs.>0) %then %do;
/*--------------------------------------------------------------------------------------------*/
/* Determine all levelIDs, metrics and stratifications requested */
/*--------------------------------------------------------------------------------------------*/
proc sql noprint;
select distinct quote(levelid1) into :levellist separated by ','
from figurefile(where=(figure in ('F1', 'F2', 'F3')));
select distinct figuresub into :figuresublist separated by ' '
from figurefile(where=(figure in ('F1', 'F2', 'F3')));
quit;
/*define stratification variables for class statement*/
%let stratvars = &figuresublist.;
%if %index(&stratvars., agegroup)>0 %then %let stratvars = &stratvars. agegroupnum;
%if %index(&stratvars., overall)>0 %then %let stratvars = %sysfunc(tranwrd(&stratvars.,overall, %str())) ;
/*F1 = npts*/ %let npts = ;
/*F2 = adjustedcodecount*/ %let adjustedcodecount = ;
/*F3 = daysupp*/ %let daysupp = ;
%if %sysfunc(prxmatch(m/F1/i,&figurelist.)) %then %let npts = npts;
%if %sysfunc(prxmatch(m/F2/i,&figurelist.)) %then %let adjustedcodecount = adjustedcodecount;
%if %sysfunc(prxmatch(m/F3/i,&figurelist.)) %then %let daysupp = daysupp;
/*--------------------------------------------------------------------------------------------*/
/* Aggregate data across all DPs */
/*--------------------------------------------------------------------------------------------*/
proc means data=agg_t5first(where=(level in (&levellist.))) noprint nway;
var &npts. &daysupp. &adjustedcodecount.;
class group runid level mntsfromstart &stratvars. / missing;
output out=agg_t5first_all(drop=_:) sum=;
run;
/*--------------------------------------------------------------------------------------------*/
/* Loop through each FigureSub */
/*--------------------------------------------------------------------------------------------*/
%do strat = 1 %to %sysfunc(countw(&figuresublist.));
%let figuresub=%scan(&figuresublist., &strat.);
/*reset macro vars*/
%let levelid = ;
%let stratvars = ;
%if %str(&figuresub.) ne %str(overall) %then %do;
%let stratvars = &figuresub.;
%if &figuresub. = agegroup %then %let stratvars = agegroupnum;
%end;
data _null_;