小猪支持我提出的类似问题 (Summing a Column By Group In a Dataset With Macros)...
我有以下数据集:
Month Cost_Center Account Actual Annual_Budget
May 53410 Postage 23 134
May 53420 Postage 7 238
May 53430 Postage 98 743
May 53440 Postage 0 417
May 53710 Postage 102 562
May 53410 Phone 63 137
May 53420 Phone 103 909
May 53430 Phone 90 763
June 53410 Postage 13 134
June 53420 Postage 0 238
June 53430 Postage 48 743
June 53440 Postage 0 417
June 53710 Postage 92 562
June 53410 Phone 73 137
June 53420 Phone 103 909
June 53430 Phone 90 763
我想对其进行“拼接”,以便每个月都有自己的“实际”列,同时按“帐户”对数值进行求和。
因此,例如,我希望输出如下所示:
Account May_Actual_Sum June_Actual_Sum Annual_Budget
Postage 14562 37960 255251
Phone 4564 2660 32241
由其他用户提供的以下代码在不需要按月进一步细分时非常有用。但是,我不确定是否可以这样做(我累了添加“按月条款”-无效)。
proc means data=Test N SUM NWAY STACKODS;
class Account_Description;
var Actual annual_budget;
by month;
ods output summary = summary_stats1;
output out = summary_stats2 N = SUM= / AUTONAME;
data want;
set summary_stats2;
run;
答案 0 :(得分:2)
我猜您的下一个问题将是如何正确地对列进行排序,因为您的月份不会排序,以及如何动态引用它们以计算月份至今的变化。不推荐使用此数据结构的原因有哪些。
data have;
input Month $ Cost_Center $ Account $ Actual Annual_Budget;
cards;
May 53410 Postage 23 134
May 53420 Postage 7 238
May 53430 Postage 98 743
May 53440 Postage 0 417
May 53710 Postage 102 562
May 53410 Phone 63 137
May 53420 Phone 103 909
May 53430 Phone 90 763
June 53410 Postage 13 134
June 53420 Postage 0 238
June 53430 Postage 48 743
June 53440 Postage 0 417
June 53710 Postage 92 562
June 53410 Phone 73 137
June 53420 Phone 103 909
June 53430 Phone 90 763
;
;
;;
run;
*summarize;
proc means data=have noprint nway;
class account month;
var actual annual_budget;
output out=temp sum=actual_total budget_total;
run;
*transpose;
proc transpose data=temp out=want prefix=Month_;
by account budget_total;
var actual_total;
id month;
run;
输出:
答案 1 :(得分:1)
我想不出一种仅使用一个PROC生成此报告的方法。您需要对UPDATE con SET lk = ''
WHERE LEN(lk) + PATINDEX('%[^'+CHAR(9)+CHAR(10)+CHAR(13)+']%',lk) = 0;
或PROC MEANS
结果进行一些后期处理才能达到目的:
PROC SUMMARY