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')

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

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