Book contents
- Frontmatter
- Contents
- Acknowledgments
- About This Book
- How to Use This Book
- Chapter 1 Navigation
- Chapter 2 Preliminary Data Exploration
- Chapter 3 Storing and Manipulating Data
- Chapter 4 Advanced Concepts in Dataset and Variable Manipulation
- Chapter 5 Introduction to Common Procedures
- Chapter 6 Procedures for Simple Statistics
- Chapter 7 More about Common Procedures
- Chapter 8 Data Visualization
- Chapter 9 JMP as an Alternative
- Index
Chapter 5 - Introduction to Common Procedures
Published online by Cambridge University Press: 05 June 2016
- Frontmatter
- Contents
- Acknowledgments
- About This Book
- How to Use This Book
- Chapter 1 Navigation
- Chapter 2 Preliminary Data Exploration
- Chapter 3 Storing and Manipulating Data
- Chapter 4 Advanced Concepts in Dataset and Variable Manipulation
- Chapter 5 Introduction to Common Procedures
- Chapter 6 Procedures for Simple Statistics
- Chapter 7 More about Common Procedures
- Chapter 8 Data Visualization
- Chapter 9 JMP as an Alternative
- Index
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
- Data Management Essentials Using SAS and JMP , pp. 64 - 78Publisher: Cambridge University PressPrint publication year: 2016