2016-02-19 49 views
0

我遇到問題,do循環創建我的報告,但是列出宏的標題頁並不反映每次正確的命名約定。 它適用於PDF中的每個書籤以及proc報告本身。然而標題沒有正確反映。SAS Proc報告標題錯誤

%macro PDF_T2(year=, age=); 

proc sql noprint; 
select distinct region, bh_type 
     into :region1 - :region14, :bh_type1 - :bh_type14 
     from table2_IP 
; 
quit; 

/*%put &region1 &region2;*/ 
/*%put &bh_type1 &bh_type2;*/ 

ods escapechar '^'; 
ods pdf file="C:\PDFS\Table2.pdf" pdftoc=2 style=Custom; 

options orientation=landscape missing=' ' 

topmargin=.25in 
bottommargin=.25in 
leftmargin=.25in rightmargin=.25in ; 

ods proclabel " Inpatient Analysis By Plan "; 


%do i=1 %to 4; 


TITLE "^{style [JUST= C ]Table 2. Inpatient Utilization By Plan,}"; 
TITLE2 "^{style [JUST= C ]&&region&i. }" ; 
Title3 "^{style [JUST= C ]Adult (21 to 64)}"; 
Title4 "^{style [JUST= C ]&&bh_type&i. Analysis}" ; 

PROC REPORT DATA = Table2_IP contents="&&bh_type&i. Table: Inpatient`enter code here` 
+0

什麼頭銜你得到的,它們是怎樣被錯? – Quentin

+0

我最終得到的通常是最後一個循環,而不是正確的時間段= t1。因此,對於T1,&& BH_TYPE或&& REGION將指示t2等。就好像標題在重新提交循環之前沒有自行清除一樣。 – Tinkinc

+1

確保在PROC REPORT步驟結束時添加一個'RUN;'語句。否則,只有在看到下一步邊界時報表纔會啓動。這通常是下一次循環中的「PROC REPORT」步驟。屆時標題已經被更改爲下一個循環實例的值。 – Tom

回答

1

我會嘗試確保您使用%本地宏變量。如果你有全局宏變量浮動,可能會導致一些令人驚訝的結果。

我還打開MPRINT並查看日誌以查看正在生成的代碼。它將顯示宏正在生成的TITLE語句。

標題不會自行清除,但每次執行TITLE語句時都會清除任何現有標題。

我修改代碼中的位來sashelp.prdsale工作,它似乎很動聽:

%macro titletest(dummy); 
%local i region1 region2; 

proc sql noprint; 
select distinct region 
     into :region1 - :region2 
     from sashelp.prdsale 
; 
quit; 

%put region1=&region1 region2=&region2; 

%do i=1 %to 2; 
    title1 "Results for &&region&i"; 
    proc print data=sashelp.prdsale; 
    where region="&&region&i"; 
    run; 
    title1; 
%end; 

%mend; 

options mprint; 
%titletest()