Help using Base SAS procedures

difference of nway option in proc mean procedure when use by or class statement

Accepted Solution Solved
Reply
Contributor
Posts: 35
Accepted Solution

difference of nway option in proc mean procedure when use by or class statement

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;


Accepted Solutions
Solution
‎04-11-2012 11:48 AM
Super User
Posts: 5,093

Re: difference of nway option in proc mean procedure when use by or class statement

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.

View solution in original post


All Replies
Solution
‎04-11-2012 11:48 AM
Super User
Posts: 5,093

Re: difference of nway option in proc mean procedure when use by or class statement

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.

Contributor
Posts: 35

Re: difference of nway option in proc mean procedure when use by or class statement

Thank you Astounding.

What's more,would you show me an example how the MISSING option works with Class statement?

Thanks!

Super Contributor
Posts: 1,636

Re: difference of nway option in proc mean procedure when use by or class statement

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

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 3158 views
  • 5 likes
  • 3 in conversation