Search code examples
pdfsastableofcontentsods

ODS PDF with sgplot: How to make one TOC bookmark per page (with two graphs per page)


I am creating PDFs using ODS with two graphs per page. Both graphs have the same value for a type variable, 'month' below. I want to create a TOC bookmark for each page, which refers to the value of the highest-level variable ('year' below). There could be any number of values for 'year', but only two 'month' values per year. I don't want multiple levels of bookmarks, just one per page.

I looked at ODS document, but I don't know if it is possible to use that for this purpose if I have an indefinite number of graphs.

Here is what I have now:

data new;
do year = 1 to 5;
    do month = 1 to 2;
        do day = 1 to 10;
            emp = year*month*day;
            output;
        end;
    end;
end;
run;

ods pdf file='K:\brent\test_graphs_pages.pdf' startpage=never;
    proc sgplot data=new;
    by year month;
    series x = day y = emp;
    run;
ods pdf close;

It is giving me three levels of bookmarks, and two bookmarks per page. How can I get just one per page? Also, why does the bookmark for year 2 link to the page with year 1 on it?

Thanks


Solution

  • This definitely sounds like a PROC DOCUMENT problem. You may need to use the macro language to generate the code, as some of this I don't think is fully automatable inside proc document (primarily the setlabel piece), but the broad strokes would be:

    • ods document to generate the document
    • proc document then to move with where the month=1 and month=2 entries to a single dir
    • proc document with setlabel to use the #BYVAL(YEAR) to set the label correctly
    • proc document replay to output the document.

    This is the first part - you'd still want to customize the labels, and like I said you'd need to automate this with the macro language.

    data new;
      do year = 1 to 5;
        do month = 1 to 2;
            do day = 1 to 10;
                emp = year*month*day;
                output;
            end;
        end;
      end;
    run;
    
    
    ods document name=TOCtest(write);
    ods pdf file='h:\temp\test_graphs_pages_before.pdf' startpage=never;
        proc sgplot data=new;
        by year month;
        series x = day y = emp;
        run;
    ods pdf close;
    ods document close;
    
    
    ods listing;
    proc document name=TOCtest;
    list / levels=all; run;
    make \Year1;
    move \SGPlot#1\ByGroup1#1\SGPlot#1  to \Year1#1;
    move \SGPlot#1\ByGroup2#1\SGPlot#1  to \Year1#1;
    delete \SGPlot#1\ByGroup1#1;
    delete \SGPlot#1\ByGroup2#1;
    
    
    make \Year2;
    move \SGPlot#1\ByGroup3#1\SGPlot#1  to \Year2#1;
    move \SGPlot#1\ByGroup4#1\SGPlot#1  to \Year2#1;
    delete \SGPlot#1\ByGroup3#1;
    delete \SGPlot#1\ByGroup4#1;
    
    make \Year3;
    move \SGPlot#1\ByGroup5#1\SGPlot#1  to \Year3#1;
    move \SGPlot#1\ByGroup6#1\SGPlot#1  to \Year3#1;
    delete \SGPlot#1\ByGroup5#1;
    delete \SGPlot#1\ByGroup6#1;
    
    make \Year4;
    move \SGPlot#1\ByGroup7#1\SGPlot#1  to \Year4#1;
    move \SGPlot#1\ByGroup8#1\SGPlot#1  to \Year4#1;
    delete \SGPlot#1\ByGroup7#1;
    delete \SGPlot#1\ByGroup8#1;
    
    make \Year5;
    move \SGPlot#1\ByGroup9#1\SGPlot#1  to \Year5#1;
    move \SGPlot#1\ByGroup10#1\SGPlot#1  to \Year5#1;
    delete \SGPlot#1\ByGroup9#1;
    delete \SGPlot#1\ByGroup10#1;
    run;
    list /details levels=all; run;
    
    ods pdf file="h:\temp\test_graph_pages_after.pdf" startpage=never;
    replay ^
    run;
    ods pdf close;
    

    This still exhibits the "one off" issue you noticed before. That seems to be unavoidable with the startpage=never - I'm not sure about a workaround there, that might be worth contacting [email protected] as it might be a bug. They had a similar bug in 9.4m1/m2 that was fixed, but is not identical.