The SAS Output Delivery System and reporting techniques

Macro %While Operator

Reply
N/A
Posts: 0

Macro %While Operator

Hello,

I've got a problem with my macro.
Here is the first part of it.

%macro castypes(table,x1=,x2=nul,x3=nul,x4=nul,x5=nul) ;
/* nombre de modalités*/
%let i=1 ;
%do %while(&&x&i NE nul) ;
%let i=&i+1;
%end ;
%mend ;
options symbolgen mlogic mprint ;
%castypes(table=estgen,x1=pauvretot,x2=typomen) ;

At the end "i" should resolve to 3.

Log tells me that he's expecting something numeric in the while condition.
Yet the following program works :

%macro castypes(table,x1=,x2=nul,x3=nul,x4=nul,x5=nul) ;
/* nombre de modalités*/
%let i=1 ;
%do %while(&&x&i=nul) ;
%let i=&i+1;
%end ;
%mend ;
options symbolgen mlogic mprint ;
%castypes(table=estgen,x1=pauvretot,x2=typomen) ;

Since x1 resolves to pauvretot, the condition is wrong the first time. But at least the program works.
What's wrong with the first program ?

Thank you.
SAS Employee
Posts: 174

Re: Macro %While Operator

Posted in reply to deleted_user
This is a good question for Technical Support. You can submit it online at http://support.sas.com/ctx/supportform/index.jsp .

-- David Kelley, SAS
N/A
Posts: 0

Re: Macro %While Operator

Posted in reply to David_SAS
Does it have something to do with the operator "ne" ?

Does it work with the macrolanguage ?
N/A
Posts: 0

Re: Macro %While Operator

Posted in reply to deleted_user
no not NE

your assumptions about +

The answer is visible in the symbolgen generated by your options

MLOGIC(CASTYPES): %LET (variable name is I)
SYMBOLGEN: Macro variable I resolves to 1
SYMBOLGEN: && resolves to &.
SYMBOLGEN: Macro variable I resolves to 1+1

Summing needs to be surrounded by %eval()

So, not

%let i=&i+1;

but

%let i= %eval( &i+1 );

good luck

PeterC
N/A
Posts: 0

Re: Macro %While Operator

Posted in reply to deleted_user
Thank you very much. I have been waiting for an answer for so long Smiley Happy

I am sorry.
I have learned very recently by myself how to use macrolanguage...
Ask a Question
Discussion stats
  • 4 replies
  • 190 views
  • 0 likes
  • 2 in conversation