Suppose you need to identify the number of variables user input in a macro variable.
Option I
%macro nvars (ivars);
%let n=%sysfunc(countw(&ivars));
%put &n;
%mend;
%nvars (X1 X2 X3 X4);
Option II
%macro nvars (ivars);
%let n=1;
%do %until ( %scan(&ivars,&n)= );
%let n=%EVAL(&n + 1);
%end;
%let n=%eval(&n-1);
%put &n;
%mend;
%nvars ( X1 X2 X3 X4);
Share Share Tweet