DATA Step, Macro, Functions and more

"call symput" for a string with " ' "?

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 128
Accepted Solution

"call symput" for a string with " ' "?

Hi, everyone,

I try to use "call symput" do the following step,

I want to do:

data test;

call symput("test_name", "Kid's First Test");

run;

%put &test1;

but I don't think in my code the "call symput" can deal with a string with a " ' ".

Any help? thanks.


Accepted Solutions
Solution
‎03-05-2013 12:41 PM
PROC Star
Posts: 1,322

Re: "call symput" for a string with " ' "?

Hi,


Actually, CALL SYMPUT doesn't mind the unmatched single quote (since it is inside double quotes).  But it cause problems for the %PUT statement.

If you wrote

  %put Kid's First Test ;

That apostrophe would look to SAS like an unmatched single quote, and cause problems.

When &test_name resolves to that value, the single quote causes the same problems.

To avoid the problems, you mask the apostrophe by using macro quoting functions.

For example:

  %put %bquote(&test_name)  ;

or

  %put %superq(test_name) ;

HTH,

--Q.

View solution in original post


All Replies
Solution
‎03-05-2013 12:41 PM
PROC Star
Posts: 1,322

Re: "call symput" for a string with " ' "?

Hi,


Actually, CALL SYMPUT doesn't mind the unmatched single quote (since it is inside double quotes).  But it cause problems for the %PUT statement.

If you wrote

  %put Kid's First Test ;

That apostrophe would look to SAS like an unmatched single quote, and cause problems.

When &test_name resolves to that value, the single quote causes the same problems.

To avoid the problems, you mask the apostrophe by using macro quoting functions.

For example:

  %put %bquote(&test_name)  ;

or

  %put %superq(test_name) ;

HTH,

--Q.

Respected Advisor
Posts: 3,799

Re: "call symput" for a string with " ' "?

When the text is resolved you need to be sure that text does not cause errors.  Typically that is done with quoting functions %SUPERQ %BQUOTE etc.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 599 views
  • 0 likes
  • 3 in conversation