SAS Macro : Count number of variables assigned in a macro variable

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);

SAS Tutorials : 100 Free SAS Tutorials

Get Free Email Updates :
*Please confirm your email address by clicking on the link sent to your Email*

Related Posts:

0 Response to "SAS Macro : Count number of variables assigned in a macro variable"

Post a Comment

Next → ← Prev