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哪些變量將數(shù)據(jù)分成不同部分;
class port move type;
* table 語句可以定義一個(gè)表,可以用對歌table語句定義多個(gè)表;
* table語句可以在報(bào)告中指定三個(gè)維度:頁畜挨、行筒繁、列噩凹,如果只指定一個(gè)維度
則默認(rèn)是列維度,如果指定兩個(gè)毡咏,則是行和列;
table port, move,type;
輸出兩頁驮宴,行為move,列為type,N表示非缺失值個(gè)數(shù)
為了方便觀察,數(shù)據(jù)按照move type排序輸出
proc sort data=boat;
by move type;
proc print data=boat;
run;
format將price數(shù)字格式修改了呕缭,注意table語句堵泽,頁行列,這里只有兩個(gè)恢总,所以表示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自定義格式化,修改頂部標(biāo)語;
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中插入一列數(shù)據(jù)
data length;
infile cards;
input length;
cards;
64
65
60
65
52
110
45
70
50
65
;
* 使用set在boat中插入一列數(shù)據(jù);
data newboat;
set boat;
set length;
proc print data=newboat;
run;
在table語句中精準(zhǔn)格式化輸出數(shù)字格式
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;