Editing the SAS Code Generated by the One-Way Frequencies Statistics Task

1

one-way-frequencies-statsitics-task-cody-bookSuppose you are using SAS Studio and the statistical task you need to perform is not a supported option or feature in SAS.  I know that sounds almost impossible because the statistical tasks in SAS Studio are so awesome.  But, just in case you need to tweak a program or some task-generated code, let me show you how.

This example is taken from my latest book, Biostatistics by Example Using SAS Studio.

Editing the SAS Code Generated by the One-Way Frequencies Statistics Task

This is a good time to show you how to edit the SAS code produced by any of the SAS Studio tasks to customize a program. Click on the Code tab and the SAS program generated by the One-Way Frequencies request appears in the right-hand pane. It looks like this:

Figure 21: SAS Code Generated by the Request for One-Way Frequencies

proc freq data=SASHELP.HEART;
   tables Status Sex Chol_Status / nocum plots=(freqplot cumfreqplot);
run;

This program uses the FREQ (frequency) procedure to produce the frequency tables and plots for the One-Way Frequencies task. You provide a list of variables that you want to analyze on the TABLES statement. Following this list you see a forward slash. A general rule in SAS procedures is that statement options (TABLES is considered a statement) are placed following a forward slash. Thus, NOCUM and PLOTS= are options that affect how the tables and charts appear. As you probably guessed, NOCUM is the instruction to omit cumulative statistics from the frequency table. Two plots, one a simple frequency plot and the other a cumulative frequency plot are requested by the two plot request (FREQPLOT and CUMFREQPLOT).

Let's modify this program in two ways: First, you want to add a customized title to the output; second, you want to omit the cumulative frequency plot. Here's how to do it:

The first step is to click on the EDIT button at the top right of the code pane (see Figure 22 below).

Figure 22: Clicking on the EDIT Button to Edit the Program

one-way-frequencies-statistics-task

This action allows you to edit the task-produced program. To provide a customized title for the output, you use a TITLE statement. This consists of the keyword TITLE, followed by your title text, placed in single or double quotes. If any part of the title text contains a single quote, be sure to use double quotes to enclose the title.  Next, move the cursor to CUMFREQPLOT and delete it. The resulting program should now look like this:

Figure 23: The Edited Program

title "Frequencies on Data from the Health Data Set";
proc freq data=SASHELP.HEART;
   tables Status SEX Chol_Status / nocum plots=(freqplot);
run;

If you submit the program again, you will see your customized title and the bar chart showing cumulative frequencies will not be produced.

To learn more about how to use SAS Studio to run just about any statistical task, visit my SAS Press Author Page where you’ll learn more about my new Biostatistics book, as well as other titles I’ve authored.

Share

About Author

Ron Cody

Private Consultant

Dr. Ron Cody was a Professor of Biostatistics at the Rutgers Robert Wood Johnson Medical School in New Jersey for 26 years. During his tenure at the medical school, he taught biostatistics to medical students as well as students in the Rutgers School of Public Health. While on the faculty, he authored or co-authored over a hundred papers in scientific journals. His first book, Applied Statistics and the SAS Programming Language, was first published by Prentice Hall in 1985 and is now in its fifth edition. Since then, he has published over a dozen books on SAS programming and statistical analysis using SAS. His latest book, A Gentle Introduction to Statistics Using SAS Studio was published this year. Ron has presented numerous papers at SAS Global forums, regional conferences, as well as local user groups. He is presently a contract instructor for SAS Institute and continues to write books on SAS and statistical topics.

Related Posts

1 Comment

Back to Top