PROC TABULATE的一般形式:(主语与FREQ过程不同,这里是table 语句,不是tables)
1 PROC TABULATE FORMAT=options;/*FORMAT=选项改变table中所有cell的格式*/ 2 VAR analysis-variable-list; 3 CLASS classification-variable-list;/*在下面table语句中出现的变量必须预先在VAR语句或CLASS出现过*/ 4 TABLE page-dimension, row-dimension, column-dimension/BOX=option MISSTEXT=option; 5 /*BOX=选项指定输出的tabulate报表的左上角的空格内的句子;MISSTEXT=选项赋特定的值给空的data cells*/ 6 RUN;
特别要注意的是:
- VAR语句:在VAR语句中除了列出变量名之外,还可以包含统计量,如:ALL(在该维度求和),MAX,MIN,MEAN,MEDIAN,MODE,N,NMISS,PCTN,PCTSUM,STDDEV,SUM.
- TABLE语句同纬度变量的Concateting,crossing, and grouping:
1 concatenating: simply list them separated by a space; 2 crossing: list variables或keywords separated by an *; 3 grouping:将变量或关键字列表在括号内
1.keyword ALL is generally concatenated; 2. To request other statistics, cross the keyword with the variable name.
例子:
1 DATA boats; 2 INFILE ‘C:\Myrawdata\boat.dat‘; 3 INPUT Name $ 1-12 port $ 14-20 Locomotion $ 22-26 Type $ 28-30 price 32-36; 4 RUN; 5 *Changing headers; 6 PROC FORMAT;/*若想改变CLASS变量的值做的标题,step1:通过此FORMAT语句定义新格式*/ 7 VALUE $typ ‘cat‘=‘Catamaran‘ 8 ‘sch‘=‘schooner’ 9 ‘yac‘=‘yacht‘; 10 RUN; 11 12 PROC TABULATE DATA=boats FORMAT=DOLLAR9.2; 13 CLASS Locomotion Type; 14 VAR Price; 15 Format Type $ typ.; 16 TABLE Locomotion=‘‘ ALL, /*改变变量的标题*/ 17 MEAN=‘‘*Price=‘Mean price by type of boat‘*(Type=‘‘ ALL)/BOX=’Full day Excursions ‘ MISSTEXT=‘none‘;/*改变关键词的标题*/ 18 TITLE; 19 RUN;
备注:
- 改变PROC TABULATE输出表格的标题
- 改变CLASS变量的分类值形成的标题:通过此FORMAT定义一个新的格式,然后通过FORMAT语句赋值给此分类变量;
- 改变变量或keyword的标题:将此变量或keyword与用单引号括起来的新标题等号相连即可,特别的,若令变量=’’,则标题被消去。
- 为每个Cells指定不同的结果:在PROC FORMAT后加上FORMAT=选项,使得表中所有单元的格式一样,若需要不同单元有不同的格式,则需要在TABLE语句后加上FORMAT=选项才能实现(TO apply a format to an individual variable, cross it with the variable name).例如:
1 TABLE Region, Mean*(Sales*FORMAT=COMMA 8.0 2 Profit*FORMAT=DOLLAR10.2);
【SAS BASE】PROC TABULATE(输出更加精美的tabulate报告),布布扣,bubuko.com
时间: 2024-10-08 12:00:45