BookmarkSubscribeRSS Feed
laiguanyu001
Fluorite | Level 6

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!

5 REPLIES 5
aaronh
Quartz | Level 8

I am guessing you meant to include the period inside the double quotes?

 

%do %while (input("&var.", 8.) > 0);
Tom
Super User Tom
Super User

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));
PaigeMiller
Diamond | Level 26

@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);

 

--
Paige Miller
andreas_lds
Jade | Level 19

In the macro-language everything is text, except for expressions, so you can just write

%do %while (&var. > 0);
Astounding
PROC Star

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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 5 replies
  • 1369 views
  • 1 like
  • 6 in conversation