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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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(%'));

 

 

View solution in original post

7 REPLIES 7
Astounding
PROC Star

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.

Top_Katz
Quartz | Level 8

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.

data_null__
Jade | Level 19

@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".
Top_Katz
Quartz | Level 8
Thank you, Respected Advisor data_null__, that worked!
Astounding
PROC Star

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(%'));

 

 

Top_Katz
Quartz | Level 8
Thank you, Astounding Super User, that worked!
Tom
Super User Tom
Super User

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 7 replies
  • 1936 views
  • 6 likes
  • 4 in conversation