BookmarkSubscribeRSS Feed
xxformat_com
Barite | Level 11

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

 

1 REPLY 1
Tom
Super User Tom
Super User

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

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

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
  • 1 reply
  • 622 views
  • 0 likes
  • 2 in conversation