BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
kaushal2040
Calcite | Level 5

Hello Forum,

Use of %unquote is not  necessary even though it is quoted with %str in code below (Automatic unquoting).  I wonder under which conditions %unquote is explicitly required to get the resolved value back.

Thanks !!!

options symbolgen;

%let macvar=%str(proc print;run;);

%put &macvar;

SYMBOLGEN:  Macro variable MACVAR resolves to proc print;run;

SYMBOLGEN:  Some characters in the above value which were subject to macro

            quoting have been unquoted for printing.

proc print;run;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Basically needed when you had to %quote (or other functions) because the string you are manipulating has special characters such as % or & that are not macro function or variables (at least at that point in the program) that you do not want resolved.

From the documentation see the difference in these two data steps:

%let val = aaa;

%let testval = %str(%'&val%');

data _null_;

  val = &testval;

  put 'VAL =' val;

run;

and

data _null_;

  val = %unquote(&testval);

  put 'VAL =' val;

run;

I try to avoid macro quoting as much as practical as it often means I've complicated issues somewhere along the line.

View solution in original post

2 REPLIES 2
ballardw
Super User

Basically needed when you had to %quote (or other functions) because the string you are manipulating has special characters such as % or & that are not macro function or variables (at least at that point in the program) that you do not want resolved.

From the documentation see the difference in these two data steps:

%let val = aaa;

%let testval = %str(%'&val%');

data _null_;

  val = &testval;

  put 'VAL =' val;

run;

and

data _null_;

  val = %unquote(&testval);

  put 'VAL =' val;

run;

I try to avoid macro quoting as much as practical as it often means I've complicated issues somewhere along the line.

kaushal2040
Calcite | Level 5

Thanks, ballardw.

This example explains a lot.  I understand when there are macro triggers masked in macro variable then %unquote is required to get resolved value.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

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
  • 2 replies
  • 921 views
  • 0 likes
  • 2 in conversation