Tool
|
Description
|
---|---|
MEANS procedure or SUMMARY
procedure
|
|
TABULATE procedure
|
|
REPORT procedure
|
|
SQL procedure
|
|
DATA step
|
|
PROC MEANS
This PROC MEANS step
creates a report that displays the mean of the analysis variable Quantity
for each value of the class variable Order_Type.
proc means data=retail.orders (keep=order_type quantity) mean maxdec=2; class order_type; var quantity; run; |
PROC REPORT
This
PROC REPORT step creates a report that displays the mean of the analysis
variable Quantity for each value of the class variable Order_Type.
proc report data=retail.orders (keep=order_type quantity); column order_type quantity; define order_type / group width=13 'Order Type'; define quantity / mean format=5.2 'Average Quantity' width=8; run; |
PROC SORT and a DATA Step
This
program uses a PROC SORT step and a DATA step to create a report.
The PROC SORT step sorts the data by the values of the variable Order_Type,
keeps only the necessary variables, and generates the temporary output
data set Orders. The DATA step calculates the mean of the analysis
variable Quantity for each value of the BY variable Order_Type and
displays these values in a report.
proc sort data=retail.orders (keep=order_type quantity) out=orders; by order_type; run; data _null_; set orders; by order_type; format average_order 5.2; if first.order_type then do; num=0; sum=0; end; num+1; sum+quantity; if last.order_type then do; average_order=sum / num; file print; put @5 'Order Type' @20 'Average Order'; put; put @13 Order_type 1. @27 Average_order 5.2; end; run; |
PROC SQL
This
PROC SQL step creates a report that displays the mean of the analysis
variable Quantity for each value of the group variable Order_Type.
proc sql; select order_type, avg(quantity) label='Average Order' format=5.2 from retail.orders group by order_type; quit; |
PROC TABULATE
This
PROC TABULATE step creates a report that displays the mean of the
analysis variable Quantity for each value of the class variable Order_Type.
proc tabulate data=retail.orders (keep=order_type quantity) format=comma8.2; class order_type; var quantity; table order_type, quantity*mean; run; |
Combinations of Class
Variables
|
Technique
|
Example
|
---|---|---|
all possible combinations:
a
b
c
a
* b
a
* c
b
* c
a
* b * c
|
basic PROC MEANS step
|
proc means data=lib.dataset mean;
class a b c;
var salary;
output out=summary1
mean=average;
run; |
specific combinations:
a
* b and a * c
|
TYPES statement in PROC
MEANS
|
proc means data=lib.dataset mean; class a b c; var salary; types a*b a*c; output out=summary2 mean=average; run; |
specific combinations:
a
* b and a * c
|
NWAY option in multiple
PROC MEANS steps
|
proc means data=lib.dataset nway; class a b; var salary; output out=summary3a mean=average; run; proc means data=lib.dataset nway; class a c; var salary; output out=summary3b mean=average; run; |
specific combinations:
a
* b and a * c
|
WHERE= option in the
OUTPUT statement in PROC MEANS
|
proc means data=lib.dataset; class a b c; var salary; output out=summary4 (where=(_type_ in (5,3))) n=employees mean=average; run; |
proc means data=company.organization_dim mean; class employee_country department employee_gender; var salary; output out=summary mean=average; run;
proc means data=lib.dataset mean;
class a b c;
var salary;
output out=summary1
mean=average;
run;
Variable Combined
|
Dimension
|
---|---|
a
|
1-way
|
b
|
1-way
|
c
|
1-way
|
b * c
|
2-way
|
a * b
|
2-way
|
a * c
|
2-way
|
a * b * c
|
3-way
|
_TYPE_ Value
|
Description of Combination
|
Variables Combined
|
Dimension
|
---|---|---|---|
1
|
rightmost variable only
|
c |
1-way
|
2
|
b |
1-way
|
|
3
|
rightmost variable and
middle variable
|
b * c |
2-way
|
4
|
leftmost variable
|
a |
1-way
|
5
|
leftmost variable and
rightmost variable
|
a * c |
2-way
|
6
|
leftmost variable and
middle variable
|
a * b |
2-way
|
7
|
rightmost variable and
middle variable and leftmost variable
|
a * b * c |
3-way
|
General form, TYPES
statement:
TYPES request(s);
request(s)
specifies the desired
combination or combinations of class variables. A request includes
one of the following:
|
proc means data=company.organization_dim mean; class employee_country department employee_gender; var salary; types employee_country*department employee_country*employee_gender; output out=summary mean=average; run;
General form, NWAY option
in the PROC MEANS statement:
PROC MEANS NWAY;
NWAY
specifies
that the output data set contains statistics for the combination of
all specified class variables (only observations with the highest
_TYPE_ value).
|
proc means data=company.organization_dim nway; class employee_country department; var salary; output out=summary1 n=employees mean=average; run; proc means data=company.organization_dim nway; class employee_country employee_gender; var salary; output out=summary2 n=employees mean=average; run;
General form, WHERE=
output data set option in a basic OUTPUT statement:
OUTPUT <OUT=SAS-data-set> (WHERE=
(where-expression-1 <logical-operator
where-expression-n>));
SAS-data-set
specifies the output
data set as a 1-level or 2-level name.
where-expression
is an arithmetic or
logical expression that consists of a sequence of operators, operands,
and SAS functions. The expression must be enclosed in parentheses.
logical-operator
can be AND, AND NOT,
OR, or OR NOT.
|
_TYPE_ Value
|
Variables Combined
|
Dimension
|
---|---|---|
1
|
Employee_Gender
|
1-way
|
2
|
Department
|
1-way
|
3
|
Department * Employee_Gender
|
2-way
|
4
|
Employee_Country
|
1-way
|
5 |
Employee_Country * Employee_Gender
|
2-way |
6 |
Employee_Country * Department
|
2-way |
7 |
Employee_Country * Department
* Employee_Gender
|
3-way |
proc means data=company.organization_dim;
class employee_country department
employee_gender;
var salary;
output out=summary
(where=(_type_ in (5,6)))
n=employees
mean=average;
run;
TYPES Statement in PROC MEANS
This program calculates
the average employee salary for two 3-way combinations of the class
variables Employee_Country, Department, Employee_Gender, and Section.
The TYPES statement requests the two combinations. The program generates
a report data set and an output data set named Summary.
proc means data=retail.organization mean; class employee_country department employee_gender section; var salary; types employee_country*department*employee_gender department*section*employee_gender; output out=summary n=employees mean=average; run; |
NWAY Option in Two PROC MEANS Steps
Each of the two PROC
MEANS steps in this program calculates the average employee salary
for a combination of three of the four class variables Employee_Country,
Department, Employee_Gender, and Section. In each step, the NWAY option
specifies that all three variables that are specified in the CLASS
statement should be combined. The program generates two reports and
two output data sets named Summary1 and Summary2.
proc means data=retail.organization nway; class employee_country department employee_gender; var salary; output out=summary1 n=employees mean=average; run; proc means data=retail.organization nway; class department section employee_gender; var salary; output out=summary2 n=employees mean=average; run; |
WHERE= Option in PROC MEANS
This program calculates
the average employee salary for two 3-way combinations of the class
variables Employee_Country, Department, Employee_Gender, and Section.
The WHERE= data set option in the OUTPUT statement specifies the two
combinations by their _TYPE_ values. The program generates a report
and an output data set named Summary3.
proc means data=retail.organization; class employee_country department employee_gender section; var salary; output out=summary3 (where=(_type_ in (7,14))) n=employees mean=average; run; |
proc means data=company.organization mean; class employee_country department employee_gender; var salary; ways 1 2; output out=summary mean=average; run;