Hello everyone,
when I use by or class statement in proc means with nway option, the results show two1 and two2 are different,two2 has 11 obs while two2 has 9 obs,why?
the means with by statement will count missing,but means with class statement will not count missing,
while both of them use nway options,Does this means the nway option doesn't work with by statement?
Thanks!
data a;
set sashelp.class;
if age=11 then age=.;
run;
proc sort data=a out=class1;
by sex age;
run;
data class2;
set a;
run;
proc means data =class1 nway noprint;
by sex age;
var height;
output out = two1 mean=;
run;
proc means data =class2 nway noprint;
class sex age;
var height;
output out = two2 mean=;
run;
You're right about that. NWAY has no impact, unless a CLASS statement is present.
To see the impact, try removing NWAY and see what changes. Expect that the BY results will not change. The CLASS results will add observations to the output data set: a summary for the entire data set, a summary for each AGE value, and a summary for each SEX value. Look for the variable _TYPE_ to indicate the level of summarization. And as you have noted, missing values for CLASS variables are omitted unless you add the MISSING option.
You're right about that. NWAY has no impact, unless a CLASS statement is present.
To see the impact, try removing NWAY and see what changes. Expect that the BY results will not change. The CLASS results will add observations to the output data set: a summary for the entire data set, a summary for each AGE value, and a summary for each SEX value. Look for the variable _TYPE_ to indicate the level of summarization. And as you have noted, missing values for CLASS variables are omitted unless you add the MISSING option.
Thank you Astounding.
What's more,would you show me an example how the MISSING option works with Class statement?
Thanks!
Here is the example:
data a;
set sashelp.class;
if age=11 then age=.;
run;
proc sort data=a out=class1;
by sex age;
run;
data class2;
set a;
run;
proc means data =class1 nway noprint;
by sex age;
var height;
output out = two1 mean=;
run;
proc means data =class2 nway noprint missing;
class sex age;
var height;
output out = two2 mean=;
run;
proc print data=two2;run;
Obs Sex Age _TYPE_ _FREQ_ Height
1 F . 3 1 51.3000
2 F 12 3 2 58.0500
3 F 13 3 2 60.9000
4 F 14 3 2 63.5500
5 F 15 3 2 64.5000
6 M . 3 1 57.5000
7 M 12 3 3 60.3667
8 M 13 3 1 62.5000
9 M 14 3 2 66.2500
10 M 15 3 2 66.7500
11 M 16 3 1 72.0000
Linlin
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.