SAS author's tip: replaying using WHERE= clauses

0

PROC DOCUMENT by ExampleThis week's SAS tip comes from Michael Tuchman and his book PROC DOCUMENT by Example Using SAS. Michael, a senior statistician, has been using SAS since 1999. And his experience comes through in his book. It's received strong reviews including this one from SAS user Wendi Wright: "Currently, I believe PROC DOCUMENT is a highly underused procedure and after reading this book, I believe this will change. The book shows how easy and how useful the procedure really is. This manual is well written and easy to understand, and is a wonderful reference document. The SAS code in the examples is well documented, and readers will find it easy to modify the programs for their own use. This is a book that I will refer to again and again during my work."

I hope that you'll enjoy this week's free excerpt from the book.

The following excerpt is from SAS Press author Michael Tuchman's book “PROC DOCUMENT by Example Using SAS” Copyright © 2012, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. (please note that results may vary depending on your version of SAS software).

Replaying Using WHERE= Clauses

As with the LIST statement, you can use the WHERE= option when specifying document paths to subset ODS output. The syntax of the WHERE= option was discussed in Chapter 4, “Listing Documents Using the DOCUMENT Procedure.” To specify which paths are of interest, special document variables characterized by leading and trailing underscores were also listed in that chapter. You can use these WHERE= clauses to select output for the REPLAY statement. Program 5.4 shows how to combine the REPLAY and WHERE options on the pathname.

Program 5.4: Replaying Using the WHERE Option

ods html(id=serious) file='program5_4.html' style=analysis;
ods pdf file='program5_4.pdf';
ods tagsets.excelxp file='program5_4.xml';
proc document name=mylib.firstdoc(read);
replay reg / dest=tagsets.excelxp;
run;
replay univariate(where=(_name_='Moments'))
/ dest=html;
run;
replay univariate(where=(_path_ ? 'Height'))
/ dest=html;
run;
replay reg(where=(sex='F')) / dest=pdf;
run;
quit;
ods _all_ close;

Notice that there is more control over which outputs go to which destinations, compared with not having a WHERE option at all.

In Program 5.4, the output from the REG procedure is sent to the spreadsheet destination, the Moments output from the UNIVARIATE procedure is sent to the HTML destination with ID=bluish, the output for the Height variable is sent exclusively to the HTML destination with ID=serious, and the REG procedure output that is restricted to Sex=F is sent to the PDF destination. Note the use of the BY variable SEX in the WHERE option. Only a variable that is used as a BY-variable in the original analysis can be used in the WHERE option.

There is an exception to this. If the object that is being replayed is a single output object, you can use any of the variables in that output object as a variable in the WHERE= option. Program 5.8 later in this chapter demonstrates this.

Share

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.

Leave A Reply

Back to Top