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

Hi Experts,

 

Given the program below how do I prevent the warnings?

 

data test;
call symputx('test','&test2');
test=resolve('&test');
run;

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

Hi,

 

Is your goal to make a macro variable TEST which has the value &test2, and then use the RESOLVE function to write that value to a data step variable TEST without treating the & in the value as a macro trigger?  

 

If so, then %superq can help:

 

 

1    data test;
2    call symputx('test','&test2');
3    test=resolve('%superq(test)');
4    put test= ;
5    run;

test=&test2
NOTE: The data set WORK.TEST has 1 observations and 1 variables.

but unless this is an academic exercise, it might be worth describing more of the big picture behind your goal.

View solution in original post

6 REPLIES 6
ballardw
Super User

Which warning?

 

Macro variables do not resolve inside single quotes. If you have a macro variable named test2 and want the value treated as text you would use  "&test2"

 

You may have to share exactly what you expect as it isn't obvious from either your question or code.

Patrick
Opal | Level 21


Macro variable &test2 would need to exist when using resolve(). If you just want to retrieve the value from &test then use symget() instead.

%let test2=some value;
data test;
  call symputx('test','&test2');
  test=resolve('&test');
  test2=symget("test");
run;

Patrick_0-1634170802557.png

 

Quentin
Super User

Hi,

 

Is your goal to make a macro variable TEST which has the value &test2, and then use the RESOLVE function to write that value to a data step variable TEST without treating the & in the value as a macro trigger?  

 

If so, then %superq can help:

 

 

1    data test;
2    call symputx('test','&test2');
3    test=resolve('%superq(test)');
4    put test= ;
5    run;

test=&test2
NOTE: The data set WORK.TEST has 1 observations and 1 variables.

but unless this is an academic exercise, it might be worth describing more of the big picture behind your goal.

gyambqt
Obsidian | Level 7
Can you pls explain why is it working? I understand both %superq and resolve but what is happening when they used together?
Quentin
Super User

Without %superq, the resolve function resolves the macro variable reference &test, to the value &test2 and it sees that as a macro variable reference so tries to resolve the macro variable TEST2, which doesn't exist, so it throws the warning.

 

With %superq the resolve function resolves the macro variable reference &test, to the value  [masked &]test2 which is not a macro variable reference so there is no attempt to resolve TEST2.  The job of %SUPERQ is to resolve a macro variable, and then mask any & or % in the resolved value.

 

To be honest, I wasn't sure %SUPERQ would work here, because I don't use the RESOLVE function much.  But it looks to me like it is doing its usual job.

gyambqt
Obsidian | Level 7
thanks
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
  • 6 replies
  • 2459 views
  • 0 likes
  • 4 in conversation