BookmarkSubscribeRSS Feed
Rajeshganta
Calcite | Level 5
%let &num=101;
%if %sysfunc(input(&num., Bestx12.)) GE 100 %then %let &email="raj@gma.com";
Mailer code
To=(&email.)
I am using this script but getting the error as %if statement in open code
Please help me solve the issue
6 REPLIES 6
Kurt_Bremser
Super User

If you use %IF in open code (outside a macro), it has to have %DO-%END blocks for the %THEN and %ELSE branches.

Also note that the "open code %IF" is a fairly recent addition to the SAS system, so you need to have at least 9.4M5, IIRC.

And also note that you cannot use INPUT in %SYSFUNC, you need to use INPUTN or INPUTC.

Amir
PROC Star

Hi @Rajeshganta,

 

Once you have fixed the issue causing the error, you will probably also want to look at the %let statements, as you don't need an ampersand ("&") before the variable you are assigning, as you have done for num and email, you only need the ampersand in front when you want to use the value that the variable is holding.

 

 

Kind regards,

Amir.

Tom
Super User Tom
Super User

In open code you need %DO/%END blocks.

You don't need the INPUT() code.  The %EVAL() macro function that SAS uses for %IF conditions knows how to perform integer arithmetic.

%let num=101;
%if &num GE 100 %then %do;
  %let email="raj@gma.com";
%end;

If you need to perform floating point calculations or use date literals then use %SYSEVALF().

%if %sysevalf(&num GE 100) %then %do;
Rajeshganta
Calcite | Level 5
Thank you so much tom, i am able to use the code shared but i need to give else also in this condition that should solve my query for triggering an email only when numver exceed and else it should not execute
Amir
PROC Star

Hi @Rajeshganta,

 

To find out more about the special requirements / limitations of using %if in open code then you can read this SAS blog post.

 

 

Thanks & kind regards,

Amir.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1618 views
  • 1 like
  • 4 in conversation