BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
fsuzhang
Fluorite | Level 6

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.;

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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.

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20
%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.;
fsuzhang
Fluorite | Level 6

Thanks, your code works. what happened to my original code? I am curious.

novinosrin
Tourmaline | Level 20

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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 962 views
  • 1 like
  • 2 in conversation