<<

PO05 %PUSHTITLE and %POPTITLE An Easy Way to Manage Title and Footnote Changes in SAS By Paul D. McDonald, MBA Overland Park, Kansas

titles and footnotes all we want, because when we Abstract are done, we can change them back! A simple data _NULL_ with the call execute routine will submit the This is a quick tip to manage a large number of appropriate title and footnote statements. I also title and footnote changes for reporting output in the added in some checks to make sure the input data SAS Software System®. It requires a basic is in the appropriate (not shown). knowledge of Base SAS Software. Code Trademarks and Copyright Notices %macro poptitle (data=) ; SAS®, the SAS Software System®, and its data _null_ ; components are registered trademarks of The SAS set &data ; Institute, Inc. in Cary, NC, USA. if ='T' then call execute ('title'|| trim(left(put(number, best.)))|| " '"||trim(text)||"' ;") ; Simple Concept—Needed Solution else call execute ('footnote'|| This simple concept meets a desperately needed trim(left(put(number, best.)))|| solution for those who use the SAS Macro Facility " '"||trim(text)||"' ;") ; to generate standard reports. The idea is to create run ; a SAS data set that holds all the existing titles and %mend poptitle ; footnotes so that a macro or another section of the SAS program can change the titles and footnotes, That’s It! and then change them back automatically. A very simple concept for a very needed solution! The concept gets its name from the directory commands from DOS. About the Author Paul D. McDonald, MBA, is a SAS Certified %PUSHTITLE Professional and Senior Analysis Programmer PRA International in Lenexa, Kansas. He can be Concept reached by phone at (913) 410-2109 or by e-mail at [email protected]. The concept is simple: the automatic SAS data view sashelp.vtitle into another data set. That’s essentially it! I like to sort it first, and have put some other macro-related messages into the utility (not shown) but that’s it!

Code %macro pushtitle (out=) ; proc sort data=sashelp.vtitle out=&out ; by number ; run ; %mend pushtitle ;

%POPTITLE

Concept Now that we have a data set holding the titles and footnotes, we can have the program change the Source Code

%*------* | MACRO: pushtitle.sas | | | | PURPOSE: This macro pushes the titles and footnotes to a holding SAS data set | | | | SYNTAX: %pushtitle (out = _input_dataset_, [optional] | | = _yes_or_no_) [optional] | | | | VERSION: RDS v3.2 | | Part of the SPIKEware Rapid Decision Support SAS Macro Package | | for SAS v8.x and above | | | | SEE ALSO: %PUSHPAGENO, %POPPAGENO, %PUSHOPTIONS, %POPOPTIONS, %PUSHTITLE, | | %POPTITLE, %MAKETITLE, %PUSHODS, %POPODS | | | | DATE DESCRIPTION BY | | ======| | 06/27/06 Original Program Paul McDonald | | | | Notes: | | | +------+ | LICENSE: This library is free software--you can redistribute it and/or | | modify it under the terms of the GNU Lesser General Public | | License as published by the Free Software Foundation--either | | version 2.1 of the License, or (at your option) any later version. | | | | This library is distributed in the hope that it will be useful, | | but WITHOUT ANY WARRANTY--without even the implied warranty of | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | | Lesser General Public License for details. | | | | You should have received a copy of the GNU Lesser General Public | | License along with this library--if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | | | | OSI: This software is OSI Certified Open Source Software. | | OSI Certified is a certification mark of the Open Source Initiative. | | | | CREDITS: This software program is the intellectual property of SPIKEware, Inc. | | | | SAS, the SAS Software System, and its components are property | | of the SAS Institute, Inc. in Cary, NC http://www.sas.com/ | | | | SUPPORT: Visit our website to download the most current version and our | | training and documentation for this and other SPIKEware utilities. | | | | WOOF! (c) 1997, 2005 by SPIKEware, Inc. | | http://www.SPIKEware.com/ | *------* ;

%macro pushtitle (out=, debug=n) /des='Makes title and footnote standard title data set' ;

%*------* | initialize variables and set OPTIONS NONOTES | *------* ;

%local out starttime notes mprint mlogic symbolgen source msglevel ; %let starttime = %sysfunc(datetime()) ; %let notes = %sysfunc(getoption(notes,keyword)) ; %let mprint = %sysfunc(getoption(mprint,keyword)) ; %let mlogic = %sysfunc(getoption(mlogic,keyword)) ; %let symbolgen = %sysfunc(getoption(symbolgen,keyword)) ; %let source = %sysfunc(getoption(source,keyword)) ; %let msglevel = %scan(%sysfunc(getoption(msglevel, keyword)), 2, =) ; %let out = %data(&out) ;

%*------* | set up options based on DEBUG status | *------* ;

%if %upcase(%substr(&debug, 1, 1)) = Y %then %do ; options notes mprint source msglevel=i ; %put INFO: * ; %put INFO: ********************************************************** ; %put INFO: **** ; %put INFO: *** Beginning processing of MACRO %nrstr(%PUSHTITLE) ; %put INFO: ** ; %put INFO: * %nrstr(%pushtitle) (out = &out, ; %put INFO: * debug = &debug) ; %put INFO: * ; %put INFO: * The macro %nrstr(%PUSHTITLE) creates a title and footnote ; %put INFO: * SAS data set to be recalled later by %nrstr(%POPTITLE). ; %put INFO: * ; %end ; %else %do ; options nonotes nosource ; %info (This macro creates a SAS title and footnote holding SAS data set.) ; %end ;

%*------* | PUSH the titles to the output data set | *------* ;

proc sort data=sashelp.vtitle out=&out ; by number ; run ;

%*------* | prepare the SAS session for open code | *------* ;

options ¬es &mprint &mlogic &symbolgen &source msglevel=&msglevel ; %datanote (&out) %timenote (macro=pushtitle, starttime=&starttime, debug=&debug) %put ; %if %upcase(%substr(&debug, 1, 1)) = Y %then %do ; %put INFO: * ; %put INFO: ** ; %put INFO: *** Ending processing of MACRO %nrstr(%PUSHTITLE) ; %put INFO: **** ; %put INFO: ********************************************************** ; %put INFO: * ; %end ; %mend pushtitle ;

%*------* | end of macro pushtitle.sas | | have a nice day | *------* ;

%*------* | MACRO: poptitle.sas | | | | PURPOSE: This macro creates titles and footnotes from a title and footnote | | data set | | | | SYNTAX: %poptitle (data = _input_dataset_, [optional] | | debug = _yes_or_no_) [optional] | | | | VERSION: RDS v3.2 | | Part of the SPIKEware Rapid Decision Support SAS Macro Package | | for SAS v8.x and above | | | | SEE ALSO: %PUSHPAGENO, %POPPAGENO, %PUSHOPTIONS, %POPOPTIONS, %PUSHTITLE, | | %POPTITLE, %MAKETITLE, %PUSHODS, %POPODS | | | | DATE DESCRIPTION BY | | ======| | 07/28/05 Original Program Paul McDonald | | 09/01/05 Updated DEBUG option and added INFO statement Paul McDonald | | 11/10/05 Added new DEBUG routine to include more notes Paul McDonald | | 11/15/05 Migrated to RDS v3.2 Paul McDonald | | 06/27/06 Created POPTITLE from old version MAKETITLE macro Paul McDonald | | | | Notes: | | | +------+ | LICENSE: This library is free software--you can redistribute it and/or | | modify it under the terms of the GNU Lesser General Public | | License as published by the Free Software Foundation--either | | version 2.1 of the License, or (at your option) any later version. | | | | This library is distributed in the hope that it will be useful, | | but WITHOUT ANY WARRANTY--without even the implied warranty of | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | | Lesser General Public License for more details. | | | | You should have received a copy of the GNU Lesser General Public | | License along with this library--if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | | | | OSI: This software is OSI Certified Open Source Software. | | OSI Certified is a certification mark of the Open Source Initiative. | | | | CREDITS: This software program is the intellectual property of SPIKEware, Inc. | | | | SAS, the SAS Software System, and its components are property | | of the SAS Institute, Inc. in Cary, NC http://www.sas.com/ | | | | SUPPORT: Visit our website to download the most current version and our | | training and documentation for this and other SPIKEware utilities. | | | | WOOF! (c) 1997, 2005 by SPIKEware, Inc. | | http://www.SPIKEware.com/ | *------* ;

%macro poptitle (data=, debug=n) /des='Makes titles and footnotes from a standard title data set' ;

%*------* | initialize variables and set OPTIONS NONOTES | *------* ;

%local data starttime notes mprint mlogic symbolgen source check msglevel ; %let starttime = %sysfunc(datetime()) ; %let notes = %sysfunc(getoption(notes,keyword)) ; %let mprint = %sysfunc(getoption(mprint,keyword)) ; %let mlogic = %sysfunc(getoption(mlogic,keyword)) ; %let symbolgen = %sysfunc(getoption(symbolgen,keyword)) ; %let source = %sysfunc(getoption(source,keyword)) ; %let msglevel = %scan(%sysfunc(getoption(msglevel, keyword)), 2, =) ;

%*------* | set up options based on DEBUG status | *------* ;

%if %upcase(%substr(&debug, 1, 1)) = Y %then %do ; options notes mprint source msglevel=i ; %put INFO: * ; %put INFO: ********************************************************** ; %put INFO: **** ; %put INFO: *** Beginning processing of MACRO %nrstr(%POPTITLE) ; %put INFO: ** ; %put INFO: * %nrstr(%poptitle) (data = &data, ; %put INFO: * debug = &debug) ; %put INFO: * ; %put INFO: * The macro %nrstr(%POPTITLE) creates titles and footnotes ; %put INFO: * from a title and footnote SAS data set. ; %put INFO: * ; %end ; %else %do ; options nonotes nosource ; %info (This macro creates titles and footnotes from a title and footnote SAS data set.) ; %end ;

%*------* | initialize value of DATA | *------* ;

%if &data = %str() %then %let data = %data(&syslast) ; %else %let data = %data(&data) ;

%*------* | verify that the input data set contains the | | correct variables and types of variables | | to be a standard SAS TITLE data set. | +------+------* | NAME LENGTH | | ------| | TYPE $1. Title Location (T = title, F = footnote) | | NUMBER 8. Title Number (integer, 1-10) | | TEXT $256. Title Text | *------* ;

proc contents data=&data noprint out=macro.titlects ; run ;

%*------* | check the values of the required variables | *------* ;

data _null_ ; retain check1 check2 check3 ; set macro.titlects (keep = name type length) nobs=nobs ; select (upcase(name)) ; when ('NUMBER') do ; if length = 8 and type = 1 then check1 = 1 ; end ; when ('TYPE') do ; if length = 1 and type = 2 then check2 = 1 ; end ; when ('TEXT') do ; if length = 256 and type = 2 then check3 = 1 ; end ; otherwise ; end ; if _n_ = nobs then do ; if check1 = check2 = check3 = 1 then call symput ('check', 'good') ; else call symput ('check', 'bad') ; end ; run ;

%if &check = bad %then %do ; %put WARNING: Data Set &data is not a valid SAS TITLE data set. Macro poptitle will not execute. ; %end ; %else %do ;

%*------* | ensure that the data is sorted | *------* ;

proc sort data=&data out=macro.title ; by number ; run ;

%*------* | buld new TITLE and FOOTNOTE statements | | based on the input SAS data set | *------* ;

data _null_ ; set macro.title ;

%*------* | verify that NUMBER is an integer between 1 and 10 inclusive | *------* ;

if (number ne .) then if (1 le number le 10) then if (int(number) = number) then do ;

%*------* | build the TITLE and FOOTNOTE statements conditionally | | based on the value of TYPE | *------* ;

select (type) ; when ('T') call execute ('title'||trim(left(put(number, best.)))||" '"||trim(text)||"' ;") ; when ('F') call execute ('footnote'||trim(left(put(number, best.)))||" '"||trim(text)||"' ;") ; otherwise put 'WARNING: Invalid TITLE/FOOTNOTE ' type= "found in data set &data.. Type will be ignored." ; end ; end ; else put 'WARNING: TITLE/FOOTNOTE ' number= "is out of range. Statement will be ignored." ; run ;

options ¬es ; %put NOTE: TITLES and FOOTNOTES adjusted according to data set &data.. ; %end ;

%if %upcase(%substr(&debug, 1, 1)) = Y %then %do ; options ¬es ; %datanote (macro.titlects) %datanote (macro.title) %end ; %else %do ; options nonotes ; proc datasets library=macro nolist memtype=(data view) ; delete titlects title ; run ; quit ; %end ;

options ¬es &mprint &mlogic &symbolgen &source msglevel=&msglevel ; %timenote (macro=poptitle, starttime=&starttime, debug=&debug) %put ; %if %upcase(%substr(&debug, 1, 1)) = Y %then %do ; %put INFO: * ; %put INFO: ** ; %put INFO: *** Ending processing of MACRO %nrstr(%poptitle) ; %put INFO: **** ; %put INFO: ********************************************************** ; %put INFO: * ; %end ; %mend poptitle ;

%*------* | end of macro poptitle.sas | | have a nice day | *------* ;

/** DEMO: footnote1 "footnote" ; footnote2 "second footnote" ; footnote4 "fourth footnote" ; proc contents data=sashelp.vtitle out=contents ; run ;

%pushtitle (out=title) ; title1 ; footnote1 ; proc data=sashelp.shoes ; run ;

%poptitle (data=title) ; proc print data=sashelp.shoes ; run ; */