Search the site...

SASCRUNCH TRAINING
  • Home
  • Member's Area
  • How to Start
  • SAS Interface
  • Creating a Data Set
  • Practical SAS Training Course
  • SAS Certified Specialist Training Program
  • Proc SQL Course
  • Introduction to Time Series Analysis
  • SAS Project Training Course
  • Full Training / Membership
  • Sign up
  • About us
  • Contact us
  • Home
  • Member's Area
  • How to Start
  • SAS Interface
  • Creating a Data Set
  • Practical SAS Training Course
  • SAS Certified Specialist Training Program
  • Proc SQL Course
  • Introduction to Time Series Analysis
  • SAS Project Training Course
  • Full Training / Membership
  • Sign up
  • About us
  • Contact us
Sentry Page Protection
Please Wait...
Data Manipulation [5-18]


Flagging Extreme Values II
So how does the flagging technique work?

Let's examine the code with the EXAM data set one more time.

Example
Picture

Two Steps Flagging Extreme Values

The special technique involves two steps:

Step 1
​Sort the data set so that the exam results are in ascending order within each subject.
Picture
The exam results will be in ascending order for each subject:
Picture

Step 2
Flag the first (or last) observation within each subject.
Picture
​This will flag the first observation:
Picture

Since the results are in ascending order, the first observation happens to be the lowest result for the particular subject.
Picture

As a result, the lowest result is flagged as "1".

​
Two Important Notes

1. Flagging the last observation is just the same.

Use the (last.subject) in the IF statement:
Picture
​This will flag the last observation (i.e. highest result) instead:
Picture

2. The BY statement in the data step is needed for this technique to work.
Picture
​Without the BY statement, the flagging wouldn't work.

Exercise

Locate the CARS data set from the SASHelp library. 

Identify the most and least powerful cars (HORSEPOWER) from each car maker (MAKE).

Keep only the observations that are flagged and remove the rest of the observations.

Save the data set in the WORK library.
Next

Need some help? 


HINT:
Add an additional IF statement to subset the data set.


SOLUTION:
Proc Sort Data=SASHelp.Cars Out=Cars;
By Make Horsepower;
Run;

Data Cars2;
Set Cars;
By Make Horsepower;
if first.make then i=1;
else if last.make then i=2;
if i in (1, 2);
Run;


Fill out my online form.

Already a member? Go to member's area.