08-17-2012 02:48 PM
I am trying to use a %do loop in a macro, but it does not appear that I can increment by fractions. I am trying to increment by 0.25, but I get the following errors:
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition
ERROR: The %BY value of the %DO K loop is invalid.
Here is an example of a macro that works:
%do k=1 %to 10 %by 2;
Here is an example of a macro that does not work when I change the %by value to a fraction:
%do k=1 %to 10 %by 0.25;
This is not an example of what I am doing. I am just trying to illustrate that the loop doesn't increment on fraction. Is it possible to use a %do loop while incrementing by a fraction?
08-17-2012 03:06 PM
But you can produce the needed K values like this:
%let inc = %sysfunc(ceil(1/&f));
%do Kinc= &inc to 10*&inc;
%put Kinc=&kinc K=&k;
08-20-2012 12:14 AM
PG is smart and sharp. Here is another way.
%macro agree; data test; %let k=1; %do %while(%sysevalf(&k le 10)) ; result=&k. ; output; %let k=%sysevalf(&k+ 0.25); %end; run; %mend agree; options mprint; %agree
08-20-2012 08:30 AM
My example was simplified just for illustration purposes. I would not normally use a macro if my example was all I was doing. I just needed some general help. But thank you for taking a look at my question!
Need further help from the community? Please ask a new question.