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*/
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.
Would you give me a solution?
Thanks
Mike
%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*/
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))
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
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.
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')
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.