Sentry Page Protection
Data Manipulation [2-18]
Creating Output Data Set
(Proc Sort)
You can also create an output data set for the sorted data.
Again, let's take a look at the DRINKS data set.
Again, let's take a look at the DRINKS data set.
OUT option
The OUT option allows you to specify the "output" data set.
Example
Proc Sort Data=Drinks Out=SortedDrinks;
By Calories;
Run;
The OUT option creates a new data set called SORTEDDRINKS.
The SORTEDDRINKS data set contains the sorted data from the DRINKS data set.
(try it!)
Note:
When using the OUT option, only the output data set is sorted.
The original (input) data set remains unchanged.
The DRINKS data set remains unsorted.
WHERE Statement
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:
Example
Proc Sort Data=Drinks Out=HotDrinks;
By Calories;
Where Type = "Hot";
Run;
The OUT option creates a new output data set called HOTDRINKS:
The HOTDRINKS data set is created:
The WHERE statement tells SAS to keep only the hot drinks in the data set (Type = "Hot").
The HOTDRINKS data set contains only the "Hot" drinks.
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?
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?
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.