Hi,
I have macro that looks like this:
%macro test;
%let var = 1;
%do %while (input("&var".,8.) > 0);
blablabla
%end;
%mend;
the sas log outputs required operator not found in expression input("&var".,8.) > 0
I would love some help to debug this... thanks!
I am guessing you meant to include the period inside the double quotes?
%do %while (input("&var.", 8.) > 0);
Why are you comparing the letters inp... to the digit 0?
Don't you want the macro processor to compare the digit 1 to the digit 0?
%do %while (&var > 0);
Note that if VAR can take on non integer values in your loop then you will need to use %SYSEVALF() to allow comparison of strings that look like floating point numbers.
%do %while (%sysevalf(&var > 0));
@laiguanyu001 wrote:
Hi,
I have macro that looks like this:
%macro test;
%let var = 1;
%do %while (input("&var".,8.) > 0);
blablabla
%end;
%mend;
the sas log outputs required operator not found in expression input("&var".,8.) > 0
I would love some help to debug this... thanks!
I don't see why you say &VAR is a global variable, as it is defined inside of %MACRO TEST
But anyway, %DO %WHILE() requires a macro variable or macro function inside the parenthesis. INPUT is not a macro function, that why you are getting the operator not found error. It's not even clear why you are using INPUT here, as you can test &VAR > 0 without the INPUT function.
%do %while (&var>0);
In the macro-language everything is text, except for expressions, so you can just write
%do %while (&var. > 0);
A few basic errors need to be fixed.
Macro language does not support the INPUT function. You need to use the INPUTN function instead.
To use DATA step functions in a macro language expression, you need to call the function use %SYSFUNC.
Macro language does not use quotes to identify strings. Get rid of them.
Incorporating all the changes:
%macro test;
%let var = 1;
%do %while (%sysfunc(inputn(&var.,8.)) > 0);
blablabla
%end;
%mend;
Finally, once you make those changes to correct the syntax, your loop will be an infinite loop. There better be some logic inside the loop that changes the %DO %WHILE condition from being true to being false.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.