the following simple script is supposed to output loannum, but it output state, I can not find where the logic is wrong.
%let loan_level_data_flag=1;
data _NULL_ ;
if &loan_level_data_flag. = 1 then
do;
%let by_option=loannum;
end;
else if &loan_level_data_flag. ^= 1 then
do;
%let by_option=state;
end;
run;
%put &by_option.;
I'm afraid macro language %let is a compile time operation and so it executes before datastep execution begins, therefore What you need is an execution time operation, or in other words an interface to the macro facility to function at execution and create a macro variable during data step execution and the store the variable in a symbol table. CALL SYMPUTX does that.
%let loan_level_data_flag=1;
data _NULL_ ;
if &loan_level_data_flag. = 1 then
do;
call symputx( 'by_option','loannum');
end;
else if &loan_level_data_flag. ^= 1 then
do;
call symputx( 'by_option','state');
end;
run;
%put &by_option.;
Thanks, your code works. what happened to my original code? I am curious.
I'm afraid macro language %let is a compile time operation and so it executes before datastep execution begins, therefore What you need is an execution time operation, or in other words an interface to the macro facility to function at execution and create a macro variable during data step execution and the store the variable in a symbol table. CALL SYMPUTX does that.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.