BookmarkSubscribeRSS Feed
thanikondharish
Fluorite | Level 6
%let name=jhonson;

Data ex1;
Myname=%str('&name') ;
Run;

If I am running the above program the macro variable is not resolving within single quotation
8 REPLIES 8
ScottBass
Rhodochrosite | Level 12

https://github.com/scottbass/SAS/blob/master/Macro/squote.sas

 

P.S.: Your particular example is poor - you'd just replace the single quotes with double quotes.

 

I'll run with your subject line and not your example.


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
ed_sas_member
Meteorite | Level 14

Hi @thanikondharish 

 

Does that answer your question?

%let name=jhonson;

Data ex1;
Myname = compress(catx("","'","&name","'")) ;
Run;
Jagadishkatam
Amethyst | Level 16

you cannot resolve the &name or any macro variable with single quote, we need to use the double quotes to resolve the macro variables.

 

 

Thanks,
Jag
s_lassen
Meteorite | Level 14

Macro expressions in single quotes are not resolved. There are several ways to get you the result you want, one is to use double quotes as @ScottBass suggested:

Data ex1;
Myname="&name" ;
Run;

Another is to use the SYMGET function to get the value:

Data ex1;
Myname=symget('NAME');
Run;

If you absolutely need to get the macro value in single quotes, the easiest is probably to use the QUOTE function:

Data ex1;
Myname=%sysfunc(quote(&name,%str(%'))) ;
Run;
ScottBass
Rhodochrosite | Level 12

I just borrowed (stole?) Tom's original work for my macro.

 

See https://communities.sas.com/t5/SAS-Communities-Library/Not-All-Macro-Language-Elements-Are-Supported...


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
FreelanceReinh
Jade | Level 19

If you add outer double quotes, the macro variable reference will be resolved despite the inner single quotes:

data ex1;
Myname="'&name'";
run;

This assumes that you want the single quotes to be part of the string stored in the character variable.

PaigeMiller
Diamond | Level 26

At this point, the answers have been given to the question asked; but I think the real question that needs an answer is why do you want to resolve a macro variable in single quotes in the first place? This seems like a misunderstanding and could have been easily solved if only you told us what the real goal of the program and explained where you are and where you want to go, rather than you want to resolve a macro in single quotes.

--
Paige Miller

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 2509 views
  • 8 likes
  • 8 in conversation