Q)What
are the default statistics for means procedure?
A)n-count,
mean, standard deviation, minimum, and maximum
Q)How
to limit decimal places for variable using PROC MEANS?
A)By using
MAXDEC= option
Q)Difference
between Proc Means & Proc Summary?
A)Proc SUMMARY
and Proc MEANS are essentially the same procedure. Both procedures compute descriptive
statistics.
1)The main difference concerns the default type of
output they produce.
Proc MEANS by default produces printed output in the LISTING window.
Proc summary by default produces output in a output
dataset.
2)No statistics and No VAR
statement specified.
When all variables in the data set are character the same output: a simple
count of observations, is produced for each procedure.
when some variables in the dataset are numeric, Proc
MEANS analyses all numeric variables and produces default statistics for these
variables (N, Mean, Standard Deviation, Minimum and Maximum).
Proc Summary produces a simple count of observations
3)If we specify statistics on the PROC SUMMARY statement and the VAR statement is omitted, then PROC SUMMARY stops processing and an error message is written to the SAS log.Proc MEANS produces statistics for numeric variable
Q)what
are the differences between a Function & a Proc?
A)we use
MEAN function and PROC MEANS to explain the difference.
Functions expects argument value to be supplied across an observation(a
row) in a SAS data set and procedure expects one variable value per
observation(a column).
For example:
data average ;
set temp ;
avgtemp = mean( of T1 – T24 ) ;
run ;
Here arguments of mean function are taken across an observation.
proc sort ;
by month ;
run ;
proc means ;
by month ;
var avgtemp ;
run ;
Proc means is used to calculate average temperature by month (taking one variable value across an observation).
Q)What
is the difference between CLASS statement and BY statement in proc means?
A)Unlike
CLASS processing, BY processing requires that your data already be sorted or
indexed in the order of the BY variables.
BY group results have a layout that is different from the layout of CLASS group
results.
Q)Proc
Means work for ________ variable and Proc FREQ Work for ______ variable?
A)Numeric,
Categorical
Q)How
do I add mean values and total count of a categorical variable back to my
original data set?
For example: mean values of height for Sex (female and male).
A)
1. Sort the data by Sex.
2. Use Proc Means with BY to create a new data set to hold a mean and count
values by Sex.
3. Use a data step with MERGE statements to merge them by Sex.
proc sort data=sashelp.class
out = temp;
by sex ;
proc means data=temp;
var height;
by sex;
output out=new mean=avg_height n =n_height;
run;
data addavg;
merge temp new;
by sex;
drop _type_ _freq_;
run;
proc print data=addavg;
run;
Q) Code a PROC MEANS that shows both summed and averaged output
of the data
Raw data
|
Name |
Sex |
Height |
Weight |
1 |
Sweety |
F |
56.5 |
82 |
2 |
Tweety |
F |
62.5 |
84.5 |
3 |
Preety |
F |
63.8 |
86.7 |
4 |
Ravi |
M |
65 |
112 |
5 |
Kappi |
M |
68.2 |
114.6 |
6 |
Tavi |
M |
69.7 |
120 |
7 |
Sheena |
F |
58.4 |
81 |
8 |
Meena |
F |
61.3 |
85 |
9 |
Raj |
M |
72 |
122 |
A)
proc means data=sashelp.class;
var height weight;
output out=temp
mean= sum=/autoname;
proc print data = temp;
run;
Obs |
Sex |
_TYPE_ |
_Freq_ |
Height_Mean |
Weight_Mean |
Height_Sum |
Height_Sum |
1 |
|
0 |
9 |
64.1555 |
89.5333 |
577.4 |
887.8 |
proc means data=sashelp.class;
class sex;
var height weight;
output out=temp
mean= sum=/autoname;
proc print data = temp;
run;
Obs |
Sex |
_TYPE_ |
_Freq_ |
Height_Mean |
Weight_Mean |
Height_Sum |
Weight_Sum |
1 |
|
0 |
9 |
64.1555 |
89.5333 |
577.4 |
887.8 |
2 |
F |
1 |
5 |
60.5 |
83.4 |
302.5 |
419.2 |
3 |
M |
1 |
4 |
68.725 |
117.15 |
274.9 |
468.6 |
|
|
|
|
|
|
|
|
Q) Code the option that will allow MEANS to
include missing numeric data to be included in the report.
Raw data
|
Name |
Sex |
Height |
Weight |
1 |
Sweety |
F |
56.5 |
82 |
2 |
Tweety |
F |
62.5 |
84.5 |
3 |
Preety |
F |
63.8 |
86.7 |
4 |
Ravi |
M |
65 |
112 |
5 |
Kappi |
M |
68.2 |
114.6 |
6 |
Tavi |
M |
69.7 |
120 |
7 |
Sheena |
|
58.4 |
81 |
8 |
Meena |
|
61.3 |
85 |
9 |
Raj |
M |
72 |
122 |
A)
proc means data=sashelp.class
missing;
class sex;
var height weight;
output out=temp
mean= sum=/autoname;
proc print data = temp;
run;
Obs |
Sex |
_TYPE_ |
_Freq_ |
Height_Mean |
Weight_Mean |
Height_Sum |
Weight_Sum |
1 |
|
0 |
9 |
64.1555 |
89.5333 |
577.4 |
887.8 |
2 |
|
1 |
2 |
59.85 |
83 |
119.7 |
166 |
3 |
F |
1 |
3 |
60.933 |
84.4 |
182.8 |
253.2 |
4 |
M |
1 |
4 |
68.725 |
117.15 |
274.9 |
468.6 |