Skip to main content Accessibility help
×
Hostname: page-component-8448b6f56d-42gr6 Total loading time: 0 Render date: 2024-04-23T20:31:11.674Z Has data issue: false hasContentIssue false

Chapter 7 - More about Common Procedures

Published online by Cambridge University Press:  05 June 2016

Julie Kezik
Affiliation:
Yale School of Public Health
Melissa Hill
Affiliation:
Cd3 Inc., Austin, Texas
Get access

Summary

In this chapter, we delve deeper into the simple statistics procedures introduced in Chapter 6 and discuss how these procedures can be employed to accomplish even more tasks. Using BY and CLASS statements, output can be stratified by groups of interest. Various options for reporting missing values (MISSPRINT, MISSING, NMISS) are appropriate and useful depending on the purpose of the output. Simple statistical tests can be performed and results featured in the output while new datasets can be created containing the information provided by this output.

STRATIFIED OUTPUT USING THE BY AND CLASS STATEMENTS

Frequently, data needs to be reviewed in a stratified format. Variables like height and weight typically need to be reviewed separately for males and females, and in a clinical trial, patient outcomes must often be reviewed separately for each treatment group. Using a BY or CLASS statement allows the programmer to access the full functionality of a procedure in a stratified setting. A BY statement can be used in the MEANS, FREQ, UNIVARIATE, and CORR procedures. Before a BY statement can be invoked, the dataset must first be sorted according to the variable to be specified in that statement. The CLASS statement can only be used in the MEANS and UNIVARIATE procedure and does not require that the dataset be presorted.

Let's continue with the sashelp dataset ‘cars.’ Suppose we are curious about any differences in the distribution of ‘msrp’ based on ‘origin.’ Since we will be using a BY statement, we must first sort the dataset according to the variable we will use in that statement. SAS does not allow us to sort a dataset in the permanent sashelp library, so first we will create a work dataset and then sort it. Finally, we use the MEANS procedure with a BY statement (Example 7.1).

EXAMPLE 7.1. MEANS Procedure Syntax with BY Statement.

data cars; set sashelp.cars; run;

proc sort data = cars; by origin; run;

proc means data = cars;

var msrp ;

by origin;

run;

Figure 7.1 shows the resulting output. It is exactly like the output that would result from executing a PROC MEANS without a BY statement, but the output is stratified by the variable ‘origin.’

Type
Chapter
Information
Publisher: Cambridge University Press
Print publication year: 2016

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

Save book to Kindle

To save this book to your Kindle, first ensure coreplatform@cambridge.org is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.

Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

Find out more about the Kindle Personal Document Service.

Available formats
×

Save book to Dropbox

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.

Available formats
×

Save book to Google Drive

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.

Available formats
×