摘自《The Little SAS Book》
生成原始数据集——shoes,并排序:
DATA shoes;
INPUT style $ 1-15 exercisetype $ sales;
DATALINES;
Max Flight running 1930
Zip Fit Leather walking 2250
Zoom Airborne running 4150
Light Step walking 1130
Max Step Woven walking 2230
Zip Sneak c-train 1190
;
RUN;
PROC SORT data=shoes;
BY exercisetype;
RUN;
shoes数据集:
生成该数据集的汇总统计量,并写入数据集----summarydata:
PROC MEANS NOPTINT DATA=shoes;
VAR sales;
BY exercisetype;
OUTPUT OUT=summarydata SUM(sales) = total;
RUN;
summarydata数据集:
合并shoes数据集和summarydata数据集:
DATA shoesummary;
MERGE shoes summarydata;
BY exercisetype;
percent = sales/total*100;
RUN;
打印:
PROC PRINT DATA = shoesummary;
BY exercisetype;
ID exercisetype;
VAR style sales total percent;
TITLE 'sales share by type of exercise';
RUN;