我使用Proc Summary,因为我想使用多标签格式。我一直在尝试将格式应用于我的汇总输出,但无法在不发出警告的情况下查看如何获取此格式。
Proc Summary Data = Source CompleteTypes Missing NoPrint NWay;
Class Brand / MLF;
Var Id Total;
Output Out = Results
N(ID) = Volume
Sum(Total) = Grand_Total;
Run;
我想将我的卷格式化为Comma23。和Grand_Total为Comma23.2。如果我在输出后面添加格式声明,它会警告我变量不存在,但数据集确实应用了格式。
我原本以为格式化一个汇总变量将是一个常见的操作,但我找不到一种方法来应用它而不会收到警告。我有什么遗失的吗?
非常感谢
答案 0 :(得分:2)
Another approach is to use proc template to apply the format. The format will be carried over into the newly created data set using the ods output. Use ods trace on to find (1) the name of the template to alter (2) the name of the object to output into a data set. In your case, you want to alter the Base.Summary template and output the Summary object. Both will be found in the log when you run ods trace in front of a proc step. This can be done with other procedures as well. For instance, a proc frequency of a single table has the template Base.Freq.OneWayList
/* Create Test Data */
data test (drop = num);
do num = 1 to 100;
x = ceil(rand('NORMAL', 100, 10));
output;
end;
run;
/* Check log with ODS Trace On to find template to alter and object to output */
ods trace on;
proc summary data = test sum n mean print;
var x;
run;
ods trace off;
/* Alter the Base.Summary template */
ods path reset;
ods path (PREPEND) WORK.TEMPLATE(UPDATE);
proc template;
edit Base.Summary;
edit N;
label = 'Count';
header = varlabel;
format = Comma10.;
end;
edit Mean;
label = 'Average';
header = varlabel;
format = Comma10.;
end;
edit Sum;
label = "Sum";
header = varlabel;
format = Comma10.;
end;
end;
run;
/* Output Results (formatted) from the Proc */
ods output summary = results;
proc summary data = test sum n mean print stackodsoutput;
var x;
run;
答案 1 :(得分:1)
在proc datasets
创建后,使用proc summary
将格式应用于输出数据集:
proc datasets lib = work;
modify results;
format Volume comma23. Grand_total comma23.2;
run;
quit;
答案 2 :(得分:1)
Some statistics like SUM inherit the format of the analysis variable. N statistics does not inherit the format but you can format the new variable if you can use the : trick shown in the example, and no warning is produced.
proc summary data=sashelp.class;
class sex;
output out=test n(age)=Nage sum(weight)=sum_weight;
format nage: comma12. weight comma12.3;
run;
proc contents varnum;
run;
proc print;
run;