/* Utility macro to count the number of elements in a list contained in a symbolic variable. Returns the length - i.e. the # of elements in the list. By default the elements are delimited by blanks and commas. The macro generates the numeric value representing the number of elements (variables) in the list. Does not handle SAS var lists with hyphens or double hyphens. */ %MACRO Lenlst( list, /* list to be parsed */ delim=%str(, ), ) ; /* can add or substitute other delimiters */ %LET newlist = %QUOTE(&list); %LET numitems = 0; %LET delim = %QUOTE(&delim); %LET stopscan = FALSE; %DO %WHILE (&stopscan = FALSE); %LET numitems = %EVAL(&numitems+1); %LET word = %QUOTE(%SCAN(&newlist,&numitems,&delim)); %IF &word = %STR() %THEN %DO; %LET stopscan = TRUE; %LET numitems = %EVAL(&numitems-1); %END; %END; &numitems %MEND lenlst;