Sentry Page Protection
Data Analysis [3-15]
Analyzing Multiple Segments
(Proc Univariate)
Data is often segmented into multiple groups (e.g. Male vs. Female, Treatment vs. Placebo).
Simply add the CLASS statement to Proc Univariate when having to analyze the data by segments.
Example
Simply add the CLASS statement to Proc Univariate when having to analyze the data by segments.
Example
Note: there are 30 observations in this data set. Not all of them are shown in the image above.
The SCHOOL data set contains a list of students along with the subjects and results.
A teacher wants to look at the distribution of the exam results for each subject.
Example
Proc Univariate Data=School;
Class Subject;
Var Results;
Run;
The CLASS statement specifies the variable Subject as the classification variable.
This allows the analysis to be done for the 3 subjects separately.
This allows the analysis to be done for the 3 subjects separately.
Is it the same as using the BY statement?
Yes, when running Proc Univariate, the CLASS statement and BY statement generate very similar results.
Both method allows you to separate the analysis across multiple segments.
Example
Proc Sort Data=School;
By Subject;
Run;
Proc Univariate Data=School;
By Subject;
Var Results;
Run;
This generates very similar results as using the CLASS option.
(try it!)
Note:
1. When using the BY statement, the data set must be sorted prior to the procedure (Proc Univariate).
The CLASS statement, however, requires no such requirement.
2. There are situations where the CLASS statement performs completely different tasks than the BY statement.
This will be explained in later sessions.
1. When using the BY statement, the data set must be sorted prior to the procedure (Proc Univariate).
The CLASS statement, however, requires no such requirement.
2. There are situations where the CLASS statement performs completely different tasks than the BY statement.
This will be explained in later sessions.
Exercise
Locate the CARS data set from the SASHelp library.
Compute the Median Horsepower of Audi and BMW.
Which car maker has a higher median horsepower?
Locate the CARS data set from the SASHelp library.
Compute the Median Horsepower of Audi and BMW.
Which car maker has a higher median horsepower?
Need some help?
HINT:
You might need to subset the data set when computing the median horsepower.
SOLUTION:
Proc Univariate Data=SASHelp.cars;
Class Make;
Var Horsepower;
Where Make in ("Audi" "BMW");
Run;
The median horsepowers are 220 and 225 for Audi and BMW, respectively. The cars from BMW have a slightly higher median horsepower.
Fill out my online form.