BookmarkSubscribeRSS Feed
Mike_Davis
Fluorite | Level 6

Hello everyone,

In the SAS code below,the third one has a problem ,please advise.

Thanks

Mike

%macro test(a);
%put a: &a;
%mend test;

%test(a=aa);


%test(a=njhl5IJK44t95y7u45n64);


%test(a=njhl5u#$%^&*(IJK44t95y7u45n64);/*This one has a problem*/

7 REPLIES 7
ballardw
Super User

Special characters such as % & as a minimum get involved with the macro resolver. Depending on what you are actually trying to do you need to either mast or quote the string involving those characters. Look up %str() and the various macro quoting functions.

Mike_Davis
Fluorite | Level 6

Would you give me a solution?

Thanks

Mike

Mike_Davis
Fluorite | Level 6

%macro test(a);
%put value of a is: &a;
%mend test;

%test(a=njhl5u#$%^&*IJK44t95y7u45n64); /*this one works*/
%test(a=njhl5u#$%^&*(IJK44t95y7u45n64);/*this one doesn't work*/

art297
Opal | Level 21

How about:

%macro test(a);

%let a2=%nrbquote(&a);

%put a: &a2;

%mend test;

%test(a=aa)

%test(a=njhl5IJK44t95y7u45n64)

%test(a=%str(njhl5u#$%^&*%(IJK44t95y7u45n64))

Mike_Davis
Fluorite | Level 6

Thank you Art,

This works!

But do we must use a %str( ) function in the parameter list?

could we move the %str( ) in the code part?

Thanks!

Mike

 


art297
Opal | Level 21

Mike: I don't think it can be moved as ( had to be replaced with %( in calling the macro.  However, I am definitely NOT an expert in macro quoting.  You can find some good reading if you do a search for macro papers by either Ian Whitlock and/or Art Carpenter.

Tom
Super User Tom
Super User

You have to do something.

Why not just use single quotes around the value?  You can remove them when you need to.

%macro test(a);

   %let y=%qsysfunc(dequote(&a));

   %put a=%superq(a);

   %put y=%superq(y);

%mend test;

Of course you still need watch out for strings that contain single quotes.

%test(a='Don''t forget to double the single quotes')

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

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 7 replies
  • 1698 views
  • 3 likes
  • 4 in conversation