data boat;
infile cards;
input name $ 1-12 port $ move $ type $ price 6.2;
cards;
Silent Lady Maalea Sail sch 75.00
America II Maalea Sail yac 32.95
ALoha Anai Lahaina Sail cat 62.00
Ocean Spirit Maalea Power cat 22.00
Anuenue Maalea Sail sch 47.50
Hana Lei Maalea Power cat 28.99
Leilani Maalea Power yac 19.99
Kalakaua Maalea Power cat 29.50
Reef Runner Lahaina Power yac 29.95
Blue Dolhin Maalea Sail cat 42.95
;
proc tabulate data=boat;
* calss 语句告诉sas哪些变量将数据分成不同部分;
class port move type;
* table 语句可以定义一个表,可以用对歌table语句定义多个表;
* table语句可以在报告中指定三个维度:页、行、列,如果只指定一个维度
则默认是列维度,如果指定两个,则是行和列;
table port, move,type;
输出两页,行为move,列为type,N表示非缺失值个数
为了方便观察,数据按照move type排序输出
proc sort data=boat;
by move type;
proc print data=boat;
run;
format将price数字格式修改了,注意table语句,页行列,这里只有两个,所以表示move行,Max、price、type都在列中,
proc tabulate data=boat format=DOLLAR9.2;
class move type;
var price;
table move all, max*price*(type all)/BOX='Full Day Excurions' MISSTEXT='none';
title;
run;
format自定义格式化,修改顶部标语;
proc format;
value $typ 'cat' = 'catamaran'
'sch' = 'schonet'
'yac' = 'yacht';
proc tabulate data=boat format=dollar9.2;
class move type;
var price;
* 使用格式化;
format type $typ.;
* ''可以去除表格顶部变量名,'xxx'可以指定变量名为xxx;
table move all, (type='mean price by type of boat' all)*max=''*price=''
/BOX='Full Day Excurions' MISSTEXT='none';
title;
run;
使用set在boat中插入一列数据
data length;
infile cards;
input length;
cards;
64
65
60
65
52
110
45
70
50
65
;
* 使用set在boat中插入一列数据;
data newboat;
set boat;
set length;
proc print data=newboat;
run;
在table语句中精准格式化输出数字格式
proc tabulate data=newboat;
class move type;
var price;
var length;
format type $typ.;
table move all, max*(price*format=Dollar6.2 length*format=6.0)*(type all);
run;