SAS- Defining Page Breaks inside Macro

522 views Asked by At

I am wondering if there is a way of defining when and where page breaks occur when using a macro to output data. I know within the various ODS tagests the "Startpage=NOW" can be used but that does not seem to work if a macro is used inside that tagset. So basically I want the two tables, and graph for each personal ID code to be on a single and the next page contains the same summary graphs, charts for that individual, and etc. Currently I can only get every table and chart to its own individual page which makes for a lengthy report! Any help/suggestions would be appreciated!

    /*************************************************************************/
    /* Create a macro variable of all the ID codes                       */
    /*                                                                  */
    /*************************************************************************/

    proc sql noprint;
        select personal_id
        into :varlist separated by ' ' /*Each identifier code in the list is sep. by a single space*/
    from provider;
    quit;

    %let cntlist = &sqlobs; /*Store a count of the number of id codes*/
    %put &varlist; /*Print the codes to the log to be sure our list is accurate*/

    ods tagsets.rtf file="C:\USER\test.doc" style=sasdocprinter;

 /*  macro for generating the output table*/        

    %macro output(x);

    proc print data=prov_&x;
    run;


    proc print data=prov_revCD_&x;
    run;

    /*Print graph to template defined earlier*/
    ods graphics on / height=500px width=500px;
    proc sgrender data=summary_&x template=corf_graphs;
    run;
    ods graphics on / reset=all;


    %mend;

    %macro loopit(mylist);
        %let else=;
       %let n = %sysfunc(countw(&mylist)); /*let n=number of codes in the list*/
        data 
       %do I=0 %to &n;
          %let val = %scan(&mylist,&I); /*Let val= the ith code in the list*/
        %end;
    /*Run a loop for each oscar code. Each code will enter the 
       %do j=0 %to &n;
          %let val = %scan(&mylist,&j); /*Let val= the jth code in the list*/
    /*Run the macro loop to generate the required tables*/
    %runtab(&val);

    %output(&val);

       %end;
       run;


    %mend;
    %loopit(&varlist)
    /*Run the macro loop over the list of significant procedure code values*/



    ods tagsets.rtf close;
3

There are 3 answers

0
yukclam9 On

Beyond the use of macro, you can also consider the use of pagebywith proc print to split page for you.

See this link for PageBY

0
Joe On

Macros are nothing but source code generation devices. They have no impact on the effectiveness of any particular technique, except insomuch as their (mis)use may make it more difficult to see how to do it properly.

In this case, if you want the entirety of each single iteration of %output() to be on one page, then you simply need to add a startpage now before the %output(&val) call.

  %runtab(&val);

  ods tagsets.rtf startpage=now;

  %output(&val);

%end;

That will produce a startpage instruction immediately before the output. You could just as easily include it in the %output macro, if you will always want a new page before a call of it.

0
Brad On

I inserted the startpage=NOW where suggested and it inserted a blank page, after playing around with the placement and looking at what the code is doing this following snip it ended up working:

  ods tagsets.rtf startpage=NOW;

 %runtab(&val);

  %output(&val);
  ods tagsets.rtf startpage=no;

%end;