2013-07-26 24 views
2

我對編碼和SAS一般都很陌生。我試圖創建一系列與行數對應的KPI圖表,但下面的循環代碼不斷爲最後一行創建兩個相同的GPKI圖表。爲什麼會這樣?任何幫助將不勝感激。爲什麼SAS GKPI不斷爲最後一行創建2個GKPI圖表?

感謝

%Macro scanloop (scanfile,field1,field2,field3); 
data _null_; 
if 0 then set &scanfile nobs=X; 
call symput ('Count',X); 
stop; 
run; 

%DO I=1 %To &count; 
Data _null_; 
set &scanfile (firstobs=&I); 
call symput('Client', &field1); 
call symput('LossRatio', &field2); 
call symput('Target', &field3);  
stop; 
run; 

proc gkpi mode=raised; 
speedometer actual=&LossRatio bounds=(0 .2 .4 .6 .8 1)/
target=&Target label="&field1 KPI" nolowbound format="percent8.0" 
afont=(f="Albany AMT" height=.5cm) 
bfont=(f="Albany AMT" height=.4cm) ; 
Run; 
%end; 
%MEND SCANLOOP; 

%scanloop (work.Test, Client,LossRatio,Target);run; 
+0

這真的是使這些圖表的方式?也許他們不能通過使用BY語句來創建?這種宏觀循環非常低效,容易出錯。 – Joe

回答

0

這是額外的run;

我不知道爲什麼SAS這樣做,但我在自己的代碼中看到它。有時候,如果在程序結尾有額外的運行,圖表會打印第二個副本。

因爲它不是宏語言函數,所以在宏之後不需要run;,宏將繼續工作而沒有它。最終的結果是,通過循環最後一趟會是這樣的(注意在年底額外的運行)

proc gkpi mode=raised; 
speedometer actual=&LossRatio bounds=(0 .2 .4 .6 .8 1)/
target=&Target label="&field1 KPI" nolowbound format="percent8.0" 
afont=(f="Albany AMT" height=.5cm) 
bfont=(f="Albany AMT" height=.4cm) ; 
Run; 
run; 

由於上述錯誤(功能?),這可能是什麼原因造成的重複圖。我不認爲所有輸出模式都會發生這種情況,但是如果您使用ods輸出爲pdf,我確信這是您的問題。

喬是對的,儘管如此,你應該儘量避免用宏來做這件事。

+0

你是絕對正確的。對不起,很晚回覆。 – user2624318

相關問題