I've written a macro %xl to print an Excel file from a dataset with specific formatting. It is working fine by itself. However, the macro needs to set the title
temporarily. I can clear the title at the end of the macro, but I really want to preserve the pre-macro title and restore it as the last step of my macro.
How can I capture the current value of title
into a macro variable? Similar to %sysfunc(GetOption()) with options.
Thanks, pT
Titles and footnotes can be retrieved using the SASHELP.VTITLE view. So I would use that to save the current values, run your program, then run another step to reset the titles using call execute
, like this:
data _old_titles;
set sashelp.vtitle;
run;
/* do something */
footnote;
title;
/* reset titles and footnotes */
data _null_;
set _old_titles;
if type = 'T'
then cmd = catt('title',number," '",trim(text)," ';");
else cmd = catt('footnote',number," '",trim(text)," ';");
call execute(cmd);
run;
Notice there is an extra blank used after the text
value to prevent two consecutive apostrophes, which would translate into a single quote. Also not the use of single quotes to prevent any unwanted macro expansion.
Not perfect, but remember that you can have many titles and footnotes, so an option or SAS system function would be difficult to create. This has been a "feature request" many times but never implemented.