在SAS过程里,BY 和 CLASS 是两个完全不同的概念,即使在某些地方结果或许有巧合。BY 的本质是划分切割数据本身(SUBSET DATA)。CLASS 是对变量值做归属区分(CLASSIFY VARIABLE)。举个例子。京剧
proc means data =sashelp.class; by sex notsorted; var age; run;
proc means data =sashelp.class; class sex; var age; run;
两个过程的结果根本就不同。
关于效率:在某些过程中,如果提前对class变量排序,那么也许可以提高该过程的执行效率。如果要我指出BY的近亲,我到认为STRATA STATEMENT有些相似性,如果它存在的话。京剧
proc means data =sashelp.class; by sex notsorted; var age; run;
proc means data =sashelp.class; class sex; var age; run;
两个过程的结果根本就不同。
关于效率:在某些过程中,如果提前对class变量排序,那么也许可以提高该过程的执行效率。如果要我指出BY的近亲,我到认为STRATA STATEMENT有些相似性,如果它存在的话。京剧
Comparison of the BY and CLASS Statements
Using the BY statement is similar to using the CLASS statement and the NWAY option in that PROC MEANS summarizes each BY group as an independent subset of the input data. Therefore, no overall summarization of the input data is available. However, unlike the CLASS statement, the BY statement requires that you previously sort BY variables.
When you use the NWAY option, PROC MEANS might encounter insufficient memory for the summarization of all the class variables. You can move some class variables to the BY statement. For maximum benefit, move class variables to the BY statement that are already sorted or that have the greatest number of unique values.
You can use the CLASS and BY statements together to analyze the data by the levels of class variables within BY groups.