BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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.
4 REPLIES 4
David_SAS
SAS Employee
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
deleted_user
Not applicable
Does it have something to do with the operator "ne" ?

Does it work with the macrolanguage ?
deleted_user
Not applicable
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
deleted_user
Not applicable
Thank you very much. I have been waiting for an answer for so long 🙂

I am sorry.
I have learned very recently by myself how to use macrolanguage...

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 646 views
  • 0 likes
  • 2 in conversation