This week's tip comes from three authors who've made a big impact within the SAS user community. Lauren Haworth, Cynthia Zender, and Michele Burlew partnered up to write Output Delivery System: The Basics and Beyond a couple of years ago-and their book remains a bestselling go-to guide for anyone wanting to learn more about ODS. And its received strong feedback from reviewers, including these comments from Mike Rhoads of Westat: "Output Delivery System: The Basics and Beyond is a must-read for SAS users at all levels of experience. The authors certainly know their stuff, and their enthusiasm about the power and flexibility of ODS is evident throughout the book."
The default action of the PUT _ODS_ statement is to list in tabular form all the variables in the Program Data Vector (PDV). This example shows you two ways to select the variables that you want the PUT _ODS_ statement to list.
The standard DROP/KEEP statement and data set option methods allow you to select the variables to include in the output, but they do not allow you to control the order in which the variables appear. The KEEP= data set option in the SET statement in the following DATA step specifies five of the seven variables in data set TRAFFIC to list in the output. Figure 9.8 shows the HTML results.
ODS HTML file='keepvar.html' STYLE=sasweb; ODS PDF file='keepvar.pdf'; title 'Using the KEEP= Data Set Option'; data _null_; set traffic(keep=location event highway timeofday impact); file print ods; put _ods_; run; ODS _ALL_ CLOSE;
Although the KEEP= data set option specifies the variables to list in the output, it does not control the order in which to list them. The results in Figure 9.8 show that ODS lists the five variables in the order they appear in the PDV, and this is not the same order as they appear in the KEEP= option.
To include variables in the output and control the order of their appearance in the output, you need to use the VARIABLES= suboption of the ODS= option in the FILE PRINT statement. The set of variables to list and the order in which to list them is enclosed in parentheses.
ODS HTML file='varopt.html' STYLE=sasweb; ODS PDF file='varopt.pdf'; title 'Using the VARIABLES= Suboption on the ODS= Option'; data _null_; set traffic; file print ods=(variables=(location event highway timeofday impact)); put _ods_; run; ODS _ALL_ CLOSE;
Figure 9.9 presents the PDF output from this program.