I have created a macro variable using CALL SYMPUT in data step... I need to use that macro variable in another macro program in IF-ELSE condition with out using SYMGET... How to get the result?
my call symput program is
Data syed;
set sashelp.class;
if age >=13 then CALL SYMPUT('status','adult');
else CALL SYMPUT('stat','minor);
RUN;
I got the value for this macro variable using SYMGET function in data step.. -- This method is working fine
DATA ibbu;
SET sashelp.class;
if Age>=13 then status=SYMGET('status');
else status =SYMGET('stat');
RUN;
i need to achieve the same result in macro program in if else statement without using SYMGET... how to achieve this?
i tried this way... it didn't work for me...
%macro ibrahim;
data ibbu;
set sashelp.class;
%If Age>=13 %then %do; status= "&status" ; %end;
%else %if Age<13 %then %do; status= "&stat"; %end;
%mend ibrahim;
%ibrahim;
As per Condition it is not working.. It set all value of status to "adult". Can someone guide me on this one?
I can't see what you are hoping to accomplish with your macro code. Remember, MACRO programs are used to write DATA steps. It's the DATA step program that processes the data. Before the DATA step can run, the MACRO must have already finished writing it. So I'm not seeing what it is your macro code is trying to accomplish. Can you describe the result you want?
Hello,
Unfortunately, the way you are using macros will not work. Can you please be specific in what you are trying to accomplish? This will help in guiding you as the code you provide is confusing.
Just curious, have you thought of taking the SAS Macro Training?
@_el_doredo wrote:
Sorry for the confusion here... I got my answer.. It's the percentage sign causing the issue for me... If i remove percentage sign in data step means it worked for me... Thanks for your response
Do you mean that you reverted you program just use normal IF/THEN statements instead of trying to use %IF/%THEN macro statements?
I would highly recommend taking the SAS Macro Language 1: Essentials course as it will explain all the concepts that are confusing you and show you how to create a data-driven program. Great course and very useful.
Carmine
Hi , this reminds me my first time to use Macro, I didn't understand the difference between %if -%then and if- then
kindly find my findings:
1. '%if-%then' can ONLY be used in the MACRO program (whether inside the DATA step, or outside) and 'if-then' is ONLY used inside the DATA step (whether MACRO or non-MACRO).
2.In the DATA step, you can use 'if alone to do logical comparison. But you can not use '%if alone. You also can not use '%else' alone without '%do; %end' pair.
3.'%if-%then' uses MACRO variables in logical expressions and can not refer to DATA step variables in logical expressions (you can not write: %if x=l %then %do; because x is not a MACRO variable), while 'if-then' can use MACRO variables or use DATA step variables in logical expressions.
4.'%if-%then' in MACRO determines what text should be copied to the input stack. When you use 'if-then' inside a MACRO (or non-MACRO), it does logical comparison to determine what DATA step statements should be executed.
Hope this helps, thanks@_el_doredo
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Follow along as SAS’ Robert Blanchard explains three aspects of autotuning in a deep learning context: globalized search, localized search and an in parallel method using SAS.
Find more tutorials on the SAS Users YouTube channel.