Tuesday, June 29, 2010

Macro Statement: %DO %WHILE statement and %eval function

Syntax:
%do %while (expression);
text and macro program statements;
%end;

These examples illustrate expressions for the %DO %WHILE statement:
  • %do %while(&a<&b);

  • %do %while(%length(&name)>20);

Syntax:
%eval
(arithmetic or logical expression)
evaluates integer arithmetic (add, minus, multiple and fraction)or logical expressions.
examples:

%let d=%eval(10+20); /* Correct usage */
example for %do %while %end and %eval


%macro see(str=) ;
%local i ;
%let i = 1 ;
%do %while ( %scan(&str.,&i.) ne ) ;
%put %scan(&str.,&i.) ;
%let i = %eval ( &i + 1 ) ;
%end ;
%mend see ;

%see ( str = aa bb cc )

data need;
do i=1 by 1 while (scan("a b c",i,"") ne "");
x=scan("a b c",i,"");
output;
end;
run;

data step and macro see do the same job.

No comments:

Post a Comment