****************************************************************************************************
****************************************************************************************************
* PROGRAM: baseline_expand_parameters.sas
* Created (mm/dd/yyyy): 11/19/2020
*--------------------------------------------------------------------------------------------------
* PURPOSE: This utility macro takes a macro variable that contains a space delineated list and/or
* covariates with a dash notation in the format COVAR#-COVAR# and expands the covariate list
* to use in a data step in ("var" "var") notation
* - Macro variable containing space delineated list
* - Macro variable containing each variable in the list in double quotes and separated by a space
* - var: macro variable to expand. This should be entered as the variable name without an ampersand
*--------------------------------------------------------------------------------------------------
* Sentinel Coordinating Center
* info@sentinelsystem.org
***************************************************************************************************;
%macro baseline_expand_parameters(var =);
%put =====> MACRO CALLED: baseline_expand_parameters;
%put Expanding macro variable &var = &&&var.;
/*initialize temporary variable*/
%if %length(&&&var.) > 0 %then %do;
%let countvars = %sysfunc(countw(%quote(&&&var), %str( )));
/*loop through each word. If '-' is used, then expand to each covar*/
%do count = 1 %to &countvars.;
%let word = %scan(%quote(&&&var),&count, %str( ));
%if %index(&word.,%str(-)) = 0 %then %do;
%if &count = 1 %then %do;
%else %let tempvar = &tempvar. "&word.";
%let start = %sysfunc(substr(%scan(%quote(&word.),1,%str(-)), 6));
%let end = %sysfunc(substr(%scan(%quote(&word.),2,%str(-)), 6));
%do covar = &start. %to &end.;
%if &count = 1 and &covar = &start. %then %do;
%let tempvar = "COVAR&covar.";
%else %let tempvar = &tempvar. "COVAR&covar.";