2017-06-12 54 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