I have the following SAS code which works on its own (no macro)
ods results on;
ods rtf
body="C:\test.rtf";
ods rtf text = '~R/RTF" \pard \phmrg\posxc \qc\fs36\b " What a Great Title ~R/RTF" \par "' ;
proc print data=sashelp.class;
run;
ods rtf close;
I would like to be able to parameterize the rtf string so that a user could control alignment, bolding, fontsize, etc. In the macro I created, the string that gets created either causes an error like:
MPRINT(INSERTTEXT): ods rtf text = '~R/RTF" \pard \phmrg\posxc \qc\fs36\b " What a Great Title ~R/RTF" \par "';
ERROR 22-322: Expecting a quoted string.
ERROR 200-322: The symbol is not recognized and will be ignored.
This is especially frustrating since the resolved macro variable is exactly what I manually entered in the ods rtf text statement above. So what's the difference between executing it as SAS code and letting the macro processor resolve it into SAS and then having SAS executing it? It's the same thing right? (clearly it's not 😉
Here's a simplified version of the macro:
%macro insertText(text, justify, fontSize, bold);
ods escapechar="~";
%let startRtf = %str(%'~R/RTF%" \pard \phmrg\posxc );
%let fontConfig = %str(\q&justify.\fs&fontSize.\&bold %" );
%let endRtf = %str(~R/RTF%" \par %"%');
%let wholeString = %str(ods rtf text = &startRtf&fontConfig%str( &text )&endRtf;);
%str(&wholeString);
%mend insertText;
ods rtf
body="C:\test.rtf";
%insertText(What a Great Title, c, 36, b)
proc print data=sashelp.class;
run;
ods rtf close;
MPRINT(INSERTTEXT): ods rtf text = '~R/RTF" \pard \phmrg\posxc \qc\fs36\b " What a Great Title ~R/RTF" \par "';
ERROR 22-322: Expecting a quoted string.
ERROR 200-322: The symbol is not recognized and will be ignored.
I imagine that my problem lies somewhere in the macro quoting, but more importantly, I'd like to understand why the resolved macro string throws an error when executed in the ODS RTF while the "regular" SAS code does not.
I should have mentioned at the top, I know there are easier ways to enter a title with formatting (~S={}, justify=left, etc.), but I need the user to be able to enter this anywhere in an RTF document, not just the title.
TIA,
Dave