SAS author's tip: selecting variables to include in output


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."

If you like this week's tip, you can view a previous one by the authors on TAGSETS.RTF and table of contents, read additional reviews, or buy the book.
The following excerpt is from SAS Press authors  Lauren Haworth, Cynthia Zender, and Michele Burlew and their book "Output Delivery System: The Basics and Beyond" Copyright © 2009, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. (please note that results may vary depending on your version of SAS software)
Selecting Variables to Include in the Output

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_;

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_;

Figure 9.9 presents the PDF output from this program.


About Author

Shelly Goodin

Social Media Specialist, SAS Publications

Shelly Goodin is SAS Publications' social media marketer and the editor of "SAS Publishing News". She’s worked in the publishing industry for over thirteen years, including seven years at SAS, and enjoys creating opportunities for fans of SAS and JMP software to get to know SAS Publications' many offerings and authors.

Related Posts

Back to Top