Skip to main content Accessibility help
×
Hostname: page-component-848d4c4894-hfldf Total loading time: 0 Render date: 2024-05-18T20:42:08.464Z Has data issue: false hasContentIssue false

Chapter 5 - Introduction to 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

Once a dataset has been created and stored in SAS, the choices are limitless. Most tasks are completed using SAS-defined procedures, often referred to as PROCs. Each PROC allows the user to manipulate and/or view their data in a new way. SAS offers a variety of different procedures; within each one, a number of options can be employed, allowing the user ultimate flexibility in their final product. Two common procedures are described in this chapter, the SORT procedure and the PRINT procedure, presented along with some of their most useful options.

THE SORT PROCEDURE

What It Does and How It Works

PROC SORT orders a SAS dataset according to the value of the variable that is listed in the BY statement. This procedure is a prerequisite for invoking a BY statement in any subsequent data steps or procedures. For syntax to run properly, the data must be sorted by the variables listed in the BY statement. Datasets can be sorted by multiple variables to further specify the order of observations. When a PROC SORT is performed, the variable(s) specified in the BY statement will be placed in ascending order. For example, the dataset featured on the left-hand side of Figure 5.1 is unsorted, and on the right it is sorted. The sorted view displays all observations with the smallest value of ‘id’ first, followed by all other observations in ascending numerical order.

Let's try an example. First, open the sashelp dataset ‘Class.’ Notice that there are 5 variables and 19 observations. By visually assessing the data we can see that it is sorted alphabetically by name. Let's assume that for our analysis it is more appropriate to sort this information by age. Example 5.1 provides syntax for changing the location and name of the existing sashelp dataset ‘Class’ and then sorting the new dataset ‘SortAge’ by the single variable ‘age.’ Enter the syntax in the editor window and click the running person icon.

EXAMPLE 5.1. Syntax for Sorting by One Variable Using PROC SORT.

data SortAge;

set sashelp.class;

run;

proc sort data = SortAge; by age; run;

When opened in the Viewtable, the observations in this dataset (SortAge) should now be in ascending order according to their value in the variable age.

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
×