BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
NeilH
Obsidian | Level 7

Hello,

 

I'm trying to create pdf output that includes multiple runs of sgplot so that the same global header and footer appears on every page. I can get them to appear on pages with only text, but am not sure how to display them on pages with sgplot output. The sgplots themselves have titles and footers within their borders.

In the example below, the header and footnote print on the title page. I would like them to also appear in the subsequent page with the sgplot output. The actual report would have many sgplot calls.

 

I appreciate anyone's insight on this. Thanks.

 

 

/* Create test dataset */
data test1; input var $ rating1 survey $ source $ section $; datalines; f_pr_inst_mean 68 Faculty Acme U Program f_pr_national_mean 79 Faculty National Program s_pr_inst_mean 81 Student Acme U Program s_pr_national_mean 78 Student National Program f_fa_inst_mean 78 Faculty Acme U Faculty f_fa_national_mean 86 Faculty National Faculty s_fa_inst_mean 89 Student Acme U Faculty s_fa_national_mean 83 Student National Faculty f_in_inst_mean 77 Faculty Acme U Institution f_in_national_mean 69 Faculty National Institution s_in_inst_mean 66 Student Acme U Institution s_in_national_mean 76 Student National Institution f_le_inst_mean 89 Faculty Acme U Leadership f_le_national_mean 78 Faculty National Leadership f_ed_inst_mean 75 Faculty Acme U Education f_ed_national_mean 84 Faculty National Education s_ed_inst_mean 83 Student Acme U Education s_ed_national_mean 73 Student National Education ; run;

/* Output to pdf */ %let school = "Acme U"; goptions reset=all device=SASPRTC; ods _ALL_ close; %let folder = M:\Engagement Surveys - 2024\Scratch\; %let filename = %sysfunc(dequote(&school)); %let extension = .pdf; ods pdf (id=1) file="&folder&filename&extension"; options nodate;

/* Title page with header and footer */ proc odstext; ods escapechar='~'; title j=r "~S={preimage='C:\Users\nhurwitz\OneDrive - ACAPT\Documents\CoE logo.png' just=c}"; footnote justify=c height=6pt color=black "©2024: Engagement Survey from American Council of Academic Physical Therapy (ACAPT – www.acapt.org/excellence) All rights reserved – September 2024)"; p '2024 ENGAGEMENT SURVEY MEMBER REPORT:' / style = {font_weight=bold font_size=18pt just=c width=100% verticalalign=top}; p &school / style = {font_weight=bold font_size=16pt just=c width=100%};

/* Sgplot on separate page - no header or footer currently */ ods proclabel = "Section Charts"; proc sgplot data=test1 description="Faculty Survey Response by Section: Institution vs. National"; styleattrs DATACOLORS=(CX94c25b CX8e4133); title 'Faculty Survey Response by Section: Institution vs. National'; where survey = 'Faculty'; vbar section / response=rating1 datalabel=rating1 group=source groupdisplay=cluster clusterwidth=.50 name="vbars"; yaxis label='Level of Agreement' values=(0, 33, 67, 100, 110) valuesdisplay=("Disagree (0)" "Somewhat Disagree (33)" "Somewhat Agree (67)" "Agree (100)"); xaxis display=(nolabel); keylegend "vbars" / title=""; footnote height=.75 "Bar values represent the average responsive value of students or faculty members across questions in the section"; ods html(id=1) close;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

@NeilH wrote:

Thank you for your response. I do see how setting the title and footnote at the beginning will display it on each page. The issue that I still have - and seen on your output - is that the title and footnote of the sgplot should only appear as part of the chart rather than on each page as well. Is there a way to treat the title and footnote specific to the sgplot calls separately from the global header/footer that appears on every page of the output?

I don't think you can get exactly what you want just from title and footnote statements.  The SAS session only has one set of titles.  When you make a graph, you can choose whether you want the title to be part of the graph or as a header on the page. 

 

But you don't have separate titles for the graph, so you can't say "Make this a title for the page header, and then make this other thing a title for the graph".  It's a reasonable idea for a ballot submission, because that would be handy to have.

 

In the absence of that, I think you're stuck using title/footnote statements for the header/footer of your pdf.  Then for the title that is part of a graph, if you want it to make it part of the graph box you might have to use a different approach, maybe using annotate (SGANNO) to write the title text.  Something like:

%sganno;

data mytitle;
 %sgtext(label='My Title For My Graph', textsize=12,anchor="TOP",y1=100,y1space='GRAPHPERCENT',width=100,widthunit="PERCENT")
run;

title1 "My global title" ;
ods pdf file="Q:\junk\foo.pdf" nogtitle ;
proc sgplot data=sashelp.class sganno=mytitle pad=(top=5%);
  scatter x=age y=height ;
run ;
ods pdf close ;

Which generates:

Quentin_0-1726583510613.png

 

The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.

View solution in original post

6 REPLIES 6
Ksharp
Super User

Try the following code.

But PROC ODSTEXT only display text one time . if you want it display it on every page, you need include it in TITLE statement.

 

/* Create test dataset */data test1;
input var $ rating1 survey $ source $ section $;
datalines;
f_pr_inst_mean   68 Faculty Acme U  Program
f_pr_national_mean 79 Faculty National Program
s_pr_inst_mean  81 Student Acme U  Program
s_pr_national_mean 78 Student National Program
f_fa_inst_mean  78 Faculty Acme U  Faculty
f_fa_national_mean 86 Faculty National Faculty
s_fa_inst_mean  89 Student Acme U  Faculty
s_fa_national_mean 83 Student National Faculty
f_in_inst_mean  77 Faculty Acme U  Institution
f_in_national_mean 69 Faculty National Institution
s_in_inst_mean  66 Student Acme U  Institution
s_in_national_mean 76 Student National Institution
f_le_inst_mean  89 Faculty Acme U  Leadership
f_le_national_mean 78 Faculty National Leadership
f_ed_inst_mean  75 Faculty Acme U  Education
f_ed_national_mean 84 Faculty National Education
s_ed_inst_mean  83 Student Acme U  Education
s_ed_national_mean 73 Student National Education
;
run;
options nodate;
ods escapechar='~';

title j=r "~S={preimage='C:\temp\x3.png' just=c}";
title2 'Faculty Survey Response by Section: Institution vs. National'; 
footnote  "Bar values represent the average responsive value of students or faculty members across questions in the section";
footnote2 "©2024: Engagement Survey from  American Council of Academic Physical Therapy (ACAPT – www.acapt.org/excellence) All rights reserved – September 2024)"; 



/* Output to pdf */
%let school = "Acme";
*goptions reset=all device=SASPRTC;
%let folder = c:\temp\;
%let filename = %sysfunc(dequote(&school));
%let extension = .pdf;
ods _ALL_ close; 
ods proclabel = "Section Charts";
ods pdf file="&folder&filename&extension"    nogtitle nogfootnote    ;
/* Title page with header and footer */
proc odstext;
p '2024 ENGAGEMENT SURVEY MEMBER REPORT:' /style = {font_weight=bold font_size=18pt just=c width=100% verticalalign=top};
p &school /style = {font_weight=bold font_size=16pt just=c width=100%};
run;
/* Sgplot on separate page - no header or footer currently */
proc sgplot data=test1 description="Faculty Survey Response by Section: Institution vs. National";
styleattrs DATACOLORS=(CX94c25b CX8e4133);
where survey = 'Faculty';
vbar section / response=rating1 datalabel=rating1 group=source groupdisplay=cluster clusterwidth=.50 name="vbars";
yaxis label='Level of Agreement' values=(0, 33, 67, 100, 110) valuesdisplay=("Disagree (0)" "Somewhat Disagree (33)" "Somewhat Agree (67)" "Agree (100)");
xaxis display=(nolabel);
keylegend "vbars" / title="";
run;

ods pdf close;

Ksharp_0-1726541937330.png

 

NeilH
Obsidian | Level 7

Thank you for your response. I do see how setting the title and footnote at the beginning will display it on each page. The issue that I still have - and seen on your output - is that the title and footnote of the sgplot should only appear as part of the chart rather than on each page as well. Is there a way to treat the title and footnote specific to the sgplot calls separately from the global header/footer that appears on every page of the output?

 

Header on every page:

NeilH_0-1726579769141.png

Footer on every page:

©2024: Engagement Survey from American Council of Academic Physical Therapy (ACAPT – www.acapt.org/excellence) All rights reserved – September 2024)

 

And then on the pages with sgplot output, in addition to the global header/footer, display the title and footnote of the graph within its borders.

NeilH_0-1726580622519.png

 

Quentin
Super User

@NeilH wrote:

Thank you for your response. I do see how setting the title and footnote at the beginning will display it on each page. The issue that I still have - and seen on your output - is that the title and footnote of the sgplot should only appear as part of the chart rather than on each page as well. Is there a way to treat the title and footnote specific to the sgplot calls separately from the global header/footer that appears on every page of the output?

I don't think you can get exactly what you want just from title and footnote statements.  The SAS session only has one set of titles.  When you make a graph, you can choose whether you want the title to be part of the graph or as a header on the page. 

 

But you don't have separate titles for the graph, so you can't say "Make this a title for the page header, and then make this other thing a title for the graph".  It's a reasonable idea for a ballot submission, because that would be handy to have.

 

In the absence of that, I think you're stuck using title/footnote statements for the header/footer of your pdf.  Then for the title that is part of a graph, if you want it to make it part of the graph box you might have to use a different approach, maybe using annotate (SGANNO) to write the title text.  Something like:

%sganno;

data mytitle;
 %sgtext(label='My Title For My Graph', textsize=12,anchor="TOP",y1=100,y1space='GRAPHPERCENT',width=100,widthunit="PERCENT")
run;

title1 "My global title" ;
ods pdf file="Q:\junk\foo.pdf" nogtitle ;
proc sgplot data=sashelp.class sganno=mytitle pad=(top=5%);
  scatter x=age y=height ;
run ;
ods pdf close ;

Which generates:

Quentin_0-1726583510613.png

 

The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.
NeilH
Obsidian | Level 7

Definitely agree @Quentin, separating the graph title and footnote from the header/footer on a page would be a very nice add in SAS. But your solution gets me very close, so thank you for that. I just need to investigate the sganno option further to work out the placement of both the graph title and footnote on the graph. I'm seeing that there can be multiple rows of text data in the dataset that gets referenced by the option.

Quentin
Super User

You can do tons of cool stuff with SGANNO, and you don't have to use those macros, they're just helpers.

 

If you look for papers/blogs, you'll find plenty.  I stole some of the approach in my post from this paper by the great Sanjay Matange:
https://pharmasug.org/proceedings/china2014/CC/PharmaSUG-China-2014-CC01.pdf

 

The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.
NeilH
Obsidian | Level 7

Thanks, I'll check it out. I also found this paper:
https://support.sas.com/resources/papers/proceedings19/3644-2019.pdf

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 443 views
  • 4 likes
  • 3 in conversation