You are on page 1of 28

Working with Grouped

or Sorted Observations

Today you will learn:

❑ The concept of by-groups

❑ How to use SAS Procedure for by-group processing

❑ How to compute statistics across groups of observations


Input SAS Data Sets for Example
Working With Grouped Data
Grouping by More Than One Variable
Arranging Groups in Descending Order
Finding the First or Last observation in a Group
Finding the First or Last observation in a Group
Finding the First or Last observation in a Group
Working With Sorted Data

Understanding Sorted Data


Sorting Data
Deleting Duplicate Observations
Duplicate Obs
Deleting Duplicate Observations
Understanding Collating Sequences

ASCII Collating sequence


Understanding Collating Sequences
By group
Means Procedure: By Group
Input SAS Data Set for Examples

SAS Output
Input Data Set for Examples
Input data set for examples: Data Gains

proc means noprint data=Gains;


class name;
output out=results;
run;
proc print data=results;
run;
Identifying Observations With Maximum and Minimum Values
in Groups

Tallest &
heaviest
persons
Note: statistic “t” provides t-test for zero mean and “prt” is probability of t under null hypothesis
Recall that the variable Time
takes values in {1,2}. We are
Defining a format “timepr” using
Proc Format.

In proc means, we apply


this format as “timepr.”
Note the application
Of format timepr.

timepr. format applied to variable “time”


Input SAS Data Set for Examples
Using Two Variables to Sort a Data Set

Notice two variables on the By statement


By Group Processing with AUTONAME and WHERE options

PROC MEANS DATA=SUGI.ELEC_ANNUAL


(WHERE=(REGION IN('WESTERN','SOUTHERN')
and SUBSTR(RATE_SCHEDULE,1,2) = 'E1')) ;

VAR TOTKWH;
CLASS REGION RATE_SCHEDULE;
OUTPUT OUT=SUGI3 MEAN= SUM= MEDIAN=/AUTONAME;

Overall

Categories of E1

Regions

(Regions) x (E1 categories)

Note the variable names created by AUTONAME option on output statement


1. Do more examples of proc means with multiple by-groups

2. Do data set options: Keep=, Drop=,

3. How to initialize library

You might also like