0
votes

I have an issue where by the do loop creates my reports however the title page where the macro is listed doesn't reflect the correct naming convention each time. It works for each of the bookmarks in PDF as well as the proc report itself. However the titles don't reflect correctly.

%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`
1
What titles do you get, and how are they wrong?Quentin
I end up getting usually the last one of the loop instead of the correct one for time period= t1. So for T1 the &&BH_TYPE or &&REGION would indicate t2 and so on. Its as if the Title doesn't clear itself before resubmitting the loop.Tinkinc
Make sure to add a RUN; statement at the end of the PROC REPORT step. Otherwise the report will not start until it sees the next step boundary. Which will usually be the PROC REPORT step of the next time through the loop. By then the titles will already be changed to the values for the next instance of the loop.Tom
Good call @Tom. I think you nailed it. Maybe make that an answer.Quentin

1 Answers

1
votes

I would try making sure that you are using %local macro variables. If you have global macro variables floating around that could cause some surprising results.

I would also turn on MPRINT and look at the log to see what code is being generated. It will show the TITLE statements that the macro is generating.

Titles do not clear themselves, but every time your TITLE statement executes it will clear any existing titles.

I modified your code a bit to work on sashelp.prdsale, and it seems fine:

%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()