****************************************************************************************************
****************************************************************************************************
* PROGRAM: utility_macros.sas
* Created (mm/dd/yyyy): 12/20/2015
* Last modified: 12/1/2020
*--------------------------------------------------------------------------------------------------
* PURPOSE: This program includes the following macros:
* - %isdata() macro determines whether a dataset is empty or not
* - %create_comma_charlist() macro converts space delimited list to comma delimited list with quotes
* - %alphabetizevarutil() macro alphabetizes variables in a data step
* - %tableletter() macro increments a letter suffix
* - %varexist() macro checks for the existence of a variable
* - %convert_categories() macro converts categories to mathematical expression
* - %output_datasets() macro output SAS datasets
* - %nonrep() macro removes repeated words in macro variable
*--------------------------------------------------------------------------------------------------
* Sentinel Coordinating Center
* info@sentinelsystem.org
***************************************************************************************************;
*Macro to determine whether a dataset is empty or not;
%if %sysfunc(exist(&dataset.))=1 and %LENGTH(&dataset.) ne 0 %then %do;
call symputx("NOBS",attrn(dsid,"NLOBS"));
*Macro for converting macro variable with space deliminated list to comma deliminated list with quotation around each word;
%macro create_comma_charlist(inlist=, outlist=);
%let countvars = %sysfunc(Countw(%quote(&inlist.), ' '));
%do c = 1 %to &countvars.;
%let word = %scan(%quote(&inlist),&c., ' ');
%let &outlist. = "&word.";
%let &outlist. = &&&outlist. , "&word.";
%let &outlist = %upcase(&&&outlist);
%mend create_comma_charlist;
*Macro to alphabetize variables in a data step;
%macro alphabetizevarutil(array=, in=, out=);
array &array.[10] $50 _temporary_;
call missing(of &array.[*]);
do i = 1 to dim(&array.) until(p eq 0);
&array.[i] = substrn(&in.,p,l);
call sortc(of &array.[*]);
&out. = catx(' ',of &array.[*]);
*Macro for incrementing table/figure letter suffix;
%if %eval(&tablecount = 0) %then %do;
%if %eval(%sysfunc(mod(&tablecount.,26))=0) %then %do;
%let div = %eval((&tablecount. / 26)-1); %put &div.;
%let secondplace = %eval(&tablecount - (26*&div));%put &secondplace.;