Hi,
If someone what to use an apostrophe in a macro parameter, he has at least 3 ways to specify it in the macro call
%macro demo (text1);
%put text1= &text1.;
%mend demo;
%demo(%str(I don%'t know));or
%macro demo (text1);
%let text1=%qsysfunc(dequote(&text1.));
%put text1= &text1.;
%mend demo;
%demo("I don't know");
%demo('I don''t know');Now, assuming that we want to use two apostrophes (which resolve to one) in the macro parameter, what should be done to display the macro parameter value?
Expected result:
text1= I don't know
I could think of this solution. Would you have any other suggestion?
%macro demo (text1);
data _null_;
call symputx('text1',tranwrd(dequote("&text1."),"''","'"),'L');
run;
%put text1= %bquote(&text1.);
%mend demo;
%demo(I don''t know);Cheers
I don't understand what you are asking for.
If you could potentially have unbalanced quotes (or other potentially special characters) in a macro variable and you want to display it then add some macro quoting. %superq() is good for this.
%put The value of TEXT1 is : %superq(text1) ;
If users have passed in unbalanced quotes by adding actual quotes around the value use %Qsysfunc(dequote()) to remove them and return a macro quoted value.
201 %macro test(parm1);
202 %local var1;
203 %let var1=%qsysfunc(dequote(&parm1));
204 %put PARM1=%superq(parm1);
205 %put VAR1=%superq(var1);
206 %mend test;
207
208 %test("I don't know");
PARM1="I don't know"
VAR1=I don't know
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.