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
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.