2017-06-12 56 views
0

我正在使用Proc汇总,因为我想使用多标签格式。我一直在试图将格式应用于我的汇总结果,但无法看到如何在不引发警告的情况下获取此格式。从proc汇总格式化汇总变量

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; 

我想将我的卷格式化为逗号23。和Grand_Total作为Comma23.2。如果我在输出之后放置一个格式语句,它会警告我这些变量不存在,但数据集确实应用了格式。

我原以为格式化一个汇总变量是一个常见的操作,但我找不到一个方法来应用它没有得到警告。有什么我失踪?

非常感谢

回答

1

像SUM一些统计数据继承分析变量的格式。 N统计信息不会继承格式,但如果可以使用示例中显示的:trick技巧,则可以格式化新变量,并且不会生成警告。

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; 

enter image description here

+0

谢谢,这是一个有用的技巧要知道。 – Satkin2

1

使用proc datasetsproc summary后的格式应用到您的输出数据集已经创造了它:

proc datasets lib = work; 
    modify results; 
    format Volume comma23. Grand_total comma23.2; 
    run; 
quit; 
+0

谢谢。我期待着Proc Summary中会有一些东西可以让我做到这一点,但如果没有,这是一个很好的解决方案。 – Satkin2

2

另一种方法是使用PROC模板应用的格式。格式将使用ods输出结转到新创建的数据集中。使用ods trace来查找(1)要更改的模板的名称(2)要输出到数据集中的对象的名称。在你的情况下,你想改变Base.Summary模板并输出Summary对象。当您在proc步骤前运行ods trace时,两者都会在日志中找到。这也可以通过其他程序完成。例如,一个表的PROC频率具有模板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; 
+0

谢谢你。我不知道模板表,真正有用的知道。 – Satkin2