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 [2-18]


Creating Output Data Set
(Proc Sort)
Picture
You can also create an output data set for the sorted data.

Again, let's take a look at the DRINKS data set. 
Picture
 
OUT option

The OUT option allows you to specify the "output" data set.

Example

Proc Sort Data=Drinks Out=SortedDrinks;
By Calories;
Run;
Picture

The OUT option creates a new data set called SORTEDDRINKS. 
Picture

The SORTEDDRINKS data set contains the sorted data from the DRINKS data set. 
Picture
Data Set: SORTEDDRINKS

(try it!)
​
Note:

When using the OUT option, only the output data set is sorted.

The original (input) data set remains unchanged.
Picture
The DRINKS data set remains unsorted. ​
Picture
Data Set: DRINKS

WHERE Statement
Picture
You can also subset the output data set by using the WHERE statement. 

Example

Proc Sort Data=Drinks Out=HotDrinks;
By Calories;
Where Type = "Hot";
Run;

The OUT option creates a new output data set called HOTDRINKS:
Picture
The HOTDRINKS data set is created:
Picture

The WHERE statement tells SAS to keep only the hot drinks in the data set (Type = "Hot").
Picture

The HOTDRINKS data set contains only the "Hot" drinks. ​
Picture

​The "Cold" drinks are all removed.

​(try it!)

Exercise

Locate the CARS data set from the SASHelp library.

Sort the CARS data set by MSRP in descending order. Keep only BMW, Audi, Lexus, Mercedes-Benz and Porsche in the output data set and save the data set in the WORK library. 

Which car maker sells the most expensive car among the five?
Next

Need some help? 


HINT:
Make sure the order is sorted in descending order.


SOLUTION:
Proc Sort Data=SASHelp.Cars Out=Cars;
By descending MSRP;
Where Make in ("BMW" "Audi" "Lexus" "Mercedes-Benz" "Porsche");
Run;

Porsche.


Fill out my online form.

Already a member? Go to member's area.