BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I have the following code:

%macro groupthem(a,grpmin,grpmax);
data testr;
set test;
amt_grp&a=0;
%do i=1 %to rval;

%do %until (amt_grp&a eq 1);

%if %sysevalf((&grpmin)<=(amt_min/1000)<(&grpmax)) %then
amt_grp&a=1;
%end;
%end;

run;

%mend;

%groupthem(1,10,24.99999);

I have a couple of issues here, I want to use rval as the upper limit of iterations of the do loop. rval is defined for each obs in a prior data step, it is an integer.
I want the if statement to evaluate the value of amt_min, which is numeric. If the condition is true I want to change the value of amt_grp to 1 and exit the do loop. The amt_grp=1 will be used later to identify obs that fit into said group....

I repeatedly get an error stating the %eval function encountered a character when expecting a numeric. I cannot get macro to exit the loop properly nor can I get the rval, or upper bound to be recognized by sas. suggestions?
3 REPLIES 3
deleted_user
Not applicable
> I have the following code:
>
> %macro groupthem(a,grpmin,grpmax);
> data testr;
> set test;
> amt_grp&a=0;
> %do i=1 %to rval;
> %do %until (amt_grp&a eq 1);
>
> %if %sysevalf((&grpmin)<=(amt_min/1000)<(&grpmax))
> %then
> amt_grp&a=1;
> %end;
> %end;
>
> run;
> %mend;
>
> %groupthem(1,10,24.99999);
>
> I have a couple of issues here, I want to use rval as
> the upper limit of iterations of the do loop. rval is
> defined for each obs in a prior data step, it is an
> integer.
> I want the if statement to evaluate the value of
> amt_min, which is numeric. If the condition is true I
> want to change the value of amt_grp to 1 and exit the
> do loop. The amt_grp=1 will be used later to identify
> obs that fit into said group....
>
> I repeatedly get an error stating the %eval function
> encountered a character when expecting a numeric. I
> cannot get macro to exit the loop properly nor can I
> get the rval, or upper bound to be recognized by sas.
> suggestions?


not sure entire thread posted the first time.
deleted_user
Not applicable
I modified the code slightly and the macro is now properly reading the amtmin value...I'm getting an error wrt to if then condition for the do loop iteration. This amt_grp&a=1 is not working as it should.

%macro groupthem(a,grpmin,grpmax);
data testr;
set test;
amt_grp&a=0;
%do i=1 %to &rvalu;
%do %until (amt_grp&a eq 1);

%if %sysevalf((&grpmin)<=(&amtmin/1000)<(&grpmax)) %then
amt_grp&a=1;
%end;
%end;

run;

%mend;

%groupthem(1,10,24.99999);
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
With the statement below, you are incorrectly mixing SAS macro language code and SAS Data step code:

%do %until (amt_grp&a eq 1);


As constructured, the two will not function properly.

Suggested reading would be SAS DOC on macro language which is generated at compile time versus data step language / code.

Also, you would see the most information by adding these statements at the start of your program:

OPTIONS SOURCE SOURCE2 MACROGEN SYMBOLGEN MLOGIC NOMPRINT;


Scott Barry
SBBWorks, Inc.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3 replies
  • 611 views
  • 0 likes
  • 2 in conversation