DATA Step, Macro, Functions and more

Variable not entering macro properly

Reply
N/A
Posts: 0

Variable not entering macro properly

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?
N/A
Posts: 0

Re: Variable not entering macro properly

> 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.
N/A
Posts: 0

Re: Variable not entering macro properly

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);
Super Contributor
Super Contributor
Posts: 3,174

Re: Variable not entering macro properly

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.
Ask a Question
Discussion stats
  • 3 replies
  • 109 views
  • 0 likes
  • 2 in conversation