As the first step in the decommissioning of sasCommunity.org the site has been converted to read-only mode.


Here are some tips for How to share your SAS knowledge with your professional network.


Beware Missing Values of Class Levels in PROC MEANS

From sasCommunity
Jump to: navigation, search

Be aware of missing values in class variables when using PROC MEANS. By default any observation with a missing value for one of the class variables is removed from the analysis even if the results for the class variable with a missing value are not requested. For example:

data test;
	input c1 c2 y;
	datalines;
0 . 11
0 0 2
0 1 3
1 . 14
1 0 5
1 1 6
;
 
run;
proc means data=test ;
	class c1 c2;
	types c1;
	var y;
run;

yields the following result:

                                     Analysis Variable : y

                      N
              c1    Obs    N            Mean         Std Dev         Minimum         Maximum

               0      2    2       2.5000000       0.7071068       2.0000000       3.0000000
               1      2    2       5.5000000       0.7071068       5.0000000       6.0000000

If you expect 3 observations for each level of c1, then either remove c2 from the class statement or add the missing option for the class statement as follows:

proc means data=test ;
	class c1 c2 / missing;
	types c1;
	var y;
run;