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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

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
  • 3 replies
  • 419 views
  • 1 like
  • 2 in conversation