新浪博客

PROC Tabulate 制表总结(转)

2014-02-11 10:44阅读:
PROC Tabulate 制表总结
1、 最基本的表格
data boats;
infile 'c:\users\lichao\desktop\sas\data\boats.dat';
input Name $12. +1 Port $ Locomotion $ Type $ Price;

run;
proc print data=boats;
run;
proc tabulate data=boats;
class type port locomotion;
table type,port,locomotion;
run;
(程序绘制的是port
为行、locomotion为列的表,表的个数由type的类型数决定)
注意:Tabulateclasstable是必须的,而且table依次表示页数的、行的、列的维度,别忘了table中的逗号。
2、 在表格中加入var
var的变量必须是数值型,不能有字符型,输出为统计的和,不是个数
class的变量可以有数值型和字符型,数值型输出和字符型一样,是个数
PROC <wbr>Tabulate <wbr>制表总结(转)
PROC <wbr>Tabulate <wbr>制表总结(转)



3、三种形式的对比
table port locomotion;
table port , locomotion;
table port * locomotion;
(混合型也行,如:table locomotion,price * type; var price)

PROC <wbr>Tabulate <wbr>制表总结(转)
PROC <wbr>Tabulate <wbr>制表总结(转)
PROC <wbr>Tabulate <wbr>制表总结(转)



第一种形式,三个变量分别统计
第二种形式,第二个变量为行,第三个变量为列做表,表格个数由第一个变量的类型数决定
第三种形式,把第二种形式综合在一张表格中,即第二种形式的综合

PROC <wbr>Tabulate <wbr>制表总结(转)
4、 table中使用统计量
table后面每个变量都可使用,可选择的有:mean max min sum pctn(百分比)、all
数值型:mean*price
all特例:type all
5、控制tabulate的输出格式
(1) 最基本的控制
PROC tabulate format=options;(设置输出数据的格式)
class ......
table / box=’ (给左上方空白格加字) misstext= ’(没有值的加字) ;
注意:formatboxmisstext的格式

PROC <wbr>Tabulate <wbr>制表总结(转)
未设定格式之前

PROC <wbr>Tabulate <wbr>制表总结(转)
设定格式之后
proc tabulate data=boats format=dollar9.2; 所有类型的数据格式都一样,与(4)不同
class type;
var price;
table type , price / box='Statistics' misstext='none';
run;
(2) 更改输出变量的命名、变量类型的命名
table type=’ price=’ ,即可以在table后面直接改或者干脆删除
proc format (以更改type的类型为例)
value $ typ(自己命名) cat=
sch=
yac= ;
run;
.
.
.
format type $typ.;
注意:第一个typ后面没有小数点,而表示替换的时候有;
替换时只有最后一个有分号,其他的没有。
程序实例:
proc format;
value $tidai 'cat'='1'
'sch'='2'
'yac'='3'; (只有最后一个后面有分号)
run;

proc tabulate data=boats format=dollar9.2;

我的更多文章

下载客户端阅读体验更佳

APP专享