****************************************************************************************************
****************************************************************************************************
* PROGRAM: collapse_vars.sas
* Created (mm/dd/yyyy): 12/7/2021
*--------------------------------------------------------------------------------------------------
* PURPOSE: This macro reclassifies rows where NPTS [1,10] in order to collapse the value in the report
* - dataset containinga group variable, race, level, and NPTS
* - dataset where all rows in a stratification are collapsed if a race category is [1,10]
* - dataset = input and output dataset.
* - dpstrat = Y/N indicator - if Y then will collapse within DP
* - sumcontinuousvars = list of variables to aggregate up prior to collapsing
* - groupvar = variable name for group variable
* - where = optional clause to restrict &dataset
* - var = collapsing variable, currently only RACE is valid value
* - list = values of &var. to evalute for collapsing
* - unknown = value to assign the collapsed row
* - sort = sort# of the dataset contains a sort variable
* - varlist = list of variables to include in a proc means var statement when re-aggregating
* - classlist = list of variables to include in a class statement when re-aggregating
*--------------------------------------------------------------------------------------------------
* Sentinel Coordinating Center
* info@sentinelsystem.org
***************************************************************************************************;
%macro collapse_vars(dataset=,
/*first determine which rows require collapsing*/;
%if %str("&sumcontinuousvars.") ne %str("") %then %do;
%let classlist1 = &classlist.;
%do c = 1 %to %sysfunc(countw(&sumcontinuousvars.));
%let classlist1 = %sysfunc(tranwrd(&classlist1., %scan(&sumcontinuousvars., &c.), ));
proc means data=&dataset.(where=(&where.)) nway noprint missing;
class &classlist1. / missing;
output out=_tempcollapse(drop=_:) sum=;