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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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