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.
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.
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;
You expand the %IF with %ELSE:
%if <condition>
%then %do;
....
%end;
%else %do;
....
%end;
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.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.