Hi!
I am editing a macro with the following line:
ods pdf text='^S={preimage="/home/image.jpg"}';
This works as is, but I need to replace the hard-coded string "/home/image.jpg" with a macro variable.
I can get the following to work:
%let cstr = %str('^S={preimage="/home/image.jpg"}');
ods pdf text=&cstr.;
but if I try:
%let cstr = %str(^S={preimage="/home/image.jpg"});
ods pdf text=%str(%')&cstr.%str(%');
I get an error message:
355 ods pdf text='&cstr.';
_
22
_
76
ERROR 22-322: Expecting a quoted string.
ERROR 76-322: Syntax error, statement will be ignored.
How can I get this to resolve properly inside a macro?
Thanks!
OK, here's another workaround that you can play with, finding the right spot(s) to use it:
ods pdf text=%unquote(%str(%')&cstr.%str(%'));
Use single quotes on the inside, and double quotes on the outside:
%let cstr = %str(^S={preimage='/home/image.jpg'});
ods pdf text="&cstr.";
Single quotes suppress all macro activity.
Thank you, Astounding Super User, that's a useful work around. It's not exactly what I wanted, because I have to pass the string that takes the place of '/home/image.jpg' all inside single quotes, which means I may have to pass it twice, both in and out of the single quotes. But it keeps me going until I find a way to get the macro variable between the single quotes inside the macro code.
@Top_Katz wrote:
Thank you, Astounding Super User, that's a useful work around. It's not exactly what I wanted, because I have to pass the string that takes the place of '/home/image.jpg' all inside single quotes, which means I may have to pass it twice, both in and out of the single quotes. But it keeps me going until I find a way to get the macro variable between the single quotes inside the macro code.
I may not completely understand all the issues but I like to let SAS do then quoting when that are quotes within quotes.
457 %let cstr = %str(^S={preimage="/home/image.jpg"});
458 %put NOTE: CHECK: %sysfunc(quote(%superq(cstr)));
NOTE: CHECK: "^S={preimage=""/home/image.jpg""}"
459 ods pdf text=%sysfunc(quote(%superq(cstr)));
NOTE: Writing ODS PDF output to DISK destination "sasprt.pdf", printer "PDF".
OK, here's another workaround that you can play with, finding the right spot(s) to use it:
ods pdf text=%unquote(%str(%')&cstr.%str(%'));
I don't think this is a situation where you need to use single quotes instead of double quotes since you are just generating SAS code.
But when you do need single quotes (for example in pass thru SQL code) then I like to use an %SQUOTE() macro.
Here is one that will work even if you are still running older versions of SAS.
https://github.com/sasutils/macros/blob/master/squote.sas
%macro squote(value);
%if %sysevalf(&sysver < 9.3) %then
%unquote(%str(%')%qsysfunc(tranwrd(%superq(value),%str(%'),''))%str(%'))
;
%else %sysfunc(quote(%superq(value),%str(%'))) ;
%mend squote;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.