Using proc gchart, I'm outputting 6 graphs per page, and will have a total of 60 pages. Unfortunatly, only the final page is being output to the PDF file. I tried using "gsfmode=append" in the goptions statement, but no luck. Appreciate any help! Thank you.
GOPTIONS RESET=ALL ftext="Albany AMT";
ods pdf file="\\vmware-host\Shared Folders\Documents\My Documents\PreDict\Hospital Reports\macro.pdf" startpage=never ;
goptions htitle=11pt;
options nodate nonumber;
options leftmargin=0.5in rightmargin=0.5in;
proc gslide;
title1 "Q&i. &title" lspace=.5in f="bold";
run;quit;
goptions horigin=0 vorigin=6.75 hsize=3 vsize=3 htext=7pt htitle=9pt
axis1 label=(a=90 f="Albany AMT" "Frequency") order=(0 to 140 by 20) minor=none;
axis2 label=none value=none;
axis3 label=none ;
legend1
label=("Response" h=2 pt position=left j=c)
position=(top inside left) mode=share
value=(h=5 pt 'Yes' 'No');
proc gchart data=pd.griffin_collapsed_values;
vbar &var/DISCRETE
INSIDE=PERCENT
G100
GROUP=gender
SUBGROUP=&var
RAXIS=axis1
maxis=axis2
gaxis=axis3
legend=legend1
space=0
width=6
coutline=white;
where &var ne . and gender le 2;
format gender genderf. &var yesno.;
title1 "Gender" f="bold" ;
run;
quit;
*Bar chart #2;
goptions horigin=4.5 vorigin=6.75 hsize=3 vsize=3 htext=7pt htitle=9pt
axis1 label=(a=90 f="Albany AMT" "Frequency") order=(0 to 160 by 20) minor=none;
axis2 label=none value=none;
axis3 label=none ;
legend1
label=("Response" h=2 pt position=left j=c)
position=(top inside left) mode=share
value=(h=5 pt 'Yes' 'No');
proc gchart data=pd.griffin_collapsed_values;
vbar &var/DISCRETE
OUTSIDE=PERCENT
G100
GROUP=agecat_coll
SUBGROUP=&var
RAXIS=axis1
maxis=axis2
gaxis=axis3
legend=legend1
space=0
width=5
coutline=white;
where &var ne .;
format agecat_coll agec. &var yesno.;
title1 "Age Categories" f=bold;
run;
quit;
*Bar chart #3;
goptions horigin=0 vorigin=3.5 hsize=3 vsize=3 htext=7pt htitle=9pt
axis1 label=(a=90 f="Albany AMT" "Frequency") order=(0 to 220 by 20) minor=none;
axis2 label=none value=none;
axis3 label=none ;
legend1
label=("Response" h=2 pt position=left j=c)
position=(top inside left) mode=share
value=(h=5 pt 'Yes' 'No');
proc gchart data=pd.griffin_collapsed_values;
vbar &var/DISCRETE
OUTSIDE=PERCENT
G100
GROUP=race_coll
SUBGROUP=&var
RAXIS=axis1
maxis=axis2
gaxis=axis3
legend=legend1
space=0
width=6
coutline=white;
where &var ne .;
format race_coll racec. &var yesno.;
title1 "Race" f=bold;
run;
quit;
*Bar chart #4;
goptions horigin=4.5 vorigin=3.5 hsize=3 vsize=3 htext=7pt htitle=9pt
axis1 label=(a=90 f="Albany AMT" "Frequency") order=(0 to 140 by 20) minor=none;
axis2 label=none value=none;
axis3 label=none ;
legend1
label=("Response" h=2 pt position=left j=c)
position=(top inside left) mode=share
value=(h=5 pt 'Yes' 'No');
proc gchart data=pd.griffin_collapsed_values;
vbar &var/DISCRETE
OUTSIDE=PERCENT
G100
GROUP=edu_coll2
SUBGROUP=&var
RAXIS=axis1
maxis=axis2
gaxis=axis3
legend=legend1
space=0
width=6
coutline=white;
where &var ne .;
format edu_coll2 educc. &var yesno.;
title1 "Education" f=bold;
run;
quit;
*Bar chart #5;
goptions horigin=0 vorigin=0 hsize=3 vsize=3 htext=7pt htitle=9pt
axis1 label=(a=90 f="Albany AMT" "Frequency") order=(0 to 220 by 20) minor=none;
axis2 label=none value=none;
axis3 label=none ;
legend1
label=("Response" h=2 pt position=left j=c)
position=(top inside left) mode=share
value=(h=5 pt 'Yes' 'No');
proc gchart data=pd.griffin_collapsed_values;
vbar &var/DISCRETE
OUTSIDE=PERCENT
G100
GROUP=income_coll2
SUBGROUP=&var
RAXIS=axis1
maxis=axis2
gaxis=axis3
legend=legend1
space=0
width=6
coutline=white;
where discuss_pay ne .;
format income_coll2 incc. &var yesno.;
title1 "Income" f=bold;
run;
quit;
*Bar chart #6;
goptions horigin=4.5 vorigin=0 hsize=3 vsize=3 htext=7pt htitle=9pt
axis1 label=(a=90 f="Albany AMT" "Frequency") order=(0 to 140 by 20) minor=none;
axis2 label=none value=none;
axis3 label=none ;
legend1
label=("Response" h=2 pt position=left j=c)
position=(top inside left) mode=share
value=(h=5 pt 'Yes' 'No');
proc gchart data=pd.griffin_collapsed_values;
vbar &var/DISCRETE
OUTSIDE=PERCENT
G100
GROUP=employ_coll2
SUBGROUP=&var
RAXIS=axis1
maxis=axis2
gaxis=axis3
legend=legend1
space=0
width=5
coutline=white;
where &var ne .;
format employ_coll2 empc. &var yesno.;
title1 "Employment" f=bold;
run;
quit;
ods pdf close;
title;
footnote;
%mend;
If you want to stick with Gchart I suggest looking into Proc Greplay.
The general approach is that you send the output of each graph procedure to a specified graphics catalog (it helps to use a name that makes sense) with the GOUT option and using the NAME= option on each chart.
Use a TDEF statement to define a display template and save it.
Then use Treplay to point to the graphs created and tell the procedure which graph to place in which panel.
SASHELP.TEMPLT should have a number of example templates but they basically do 2 or 3 graphs stacked vertically or horizontal or 2 by 2.
If you use this approach the text in each graph gets shrunk so is a bit of a guessing game with your specific graphs.
The SG graphic procedures really are much better for attempting to place multiples on a page.
You might consider summarizing all of your data that use similar subgroups and add additional categorical variables to indicate the variable source and then look into SGPANEL.
You show a %mend without the corresponding %macro or the macro call, so we may be missing something. Also, what does the log look like? And warnings about no observations matching the where conditions? Any errors?
ODS LAYOUT may be easier to deal with than maintaining the offset and such and the SG procedures, SGPLOT or SGPANEL may be more appropriate.
I think you may be overwriting the graphics area as traditional SAS graphs aren't intended to stack on top of each other. Proc GREPLAY is designed to take graphs created (and saved in catalogs) and combine them into a display area specified by percent of display area. If you go this route make ALL of the graphs as you want and then use the Greplay with a "template" to do 2 by 3 or 3 by 2 displays.
I didn't include all the code so as to save space, but I will now. I don't get any errors (other than warnings regarding the size of the legend).
I can't seem to find any documentation on creating multiple graphs per page and multiple PDS pages.
Below is the full code.
Thanks so much!
*Output chisquare stats datsets for each demographic variable;
%macro proc_code(var,i,title); *Macro each predict item;
ods output chisq=chia&i;
proc freq data=pd.griffin_collapsed_values;
tables &var*gender/chisq;
where &var ne . and gender=1 or gender=2;
run;
quit;
ods output chisq=chib&i;
proc freq data=pd.griffin_collapsed_values;
tables &var*agecat_coll/chisq;
where &var ne .;
run;
quit;
ods output chisq=chic&i;
proc freq data=pd.griffin_collapsed_values;
tables &var*race_coll/chisq;
where &var ne .;
run;
quit;
ods output chisq=chid&i;
proc freq data=pd.griffin_collapsed_values;
tables &var*edu_coll2/chisq;
where &var ne .;
run;
quit;
ods output chisq=chie&i;
proc freq data=pd.griffin_collapsed_values;
tables &var*income_coll2/chisq;
where &var ne .;
run;
quit;
ods output chisq=chif&i;
proc freq data=pd.griffin_collapsed_values;
tables &var*employ_coll2/chisq;
where &var ne .;
run;
quit;
*Create macro variable containing Chi-Square Results for each demographic variable;
data _null_;set chia&i;
format tmp $40.;
if Statistic="Chi-Square" then do;
tmp=put(prob,6.4);
if prob <.001 then do;
tmp= "<.001";
end;
if prob <.0001 then do;
tmp= "<.001";
end;
if prob gt .001 then do;
tmp=trim(catt(round(prob,.001)));
end;
tmp=catt("Chi-Square Results CHISQ","(",DF,")=",round(value,.01)," p",tmp);
%let chia&i=tmp;
end;
RUN;
data _null_;
set chib&i;
format tmp $40.;
if Statistic="Chi-Square" then do;
tmp=put(prob,6.4);
if prob <.001 then do;
tmp= "<.001";
end;
if prob <.0001 then do;
tmp= "<.001";
end;
if prob gt .001 then do;
tmp=trim(catt(round(prob,.001)));
end;
tmp=catt("Chi-Square Results CHISQ","(",DF,")=",round(value,.01)," p",tmp);
%let chib&i=tmp;
end;
RUN;
data _null_;
set chic&i;
format tmp $40.;
if Statistic="Chi-Square" then do;
tmp=put(prob,6.4);
if prob <.001 then do;
tmp= "<.001";
end;
if prob <.0001 then do;
tmp= "<.001";
end;
if prob gt .001 then do;
tmp=trim(catt(round(prob,.001)));
end;
tmp=catt("Chi-Square Results CHISQ","(",DF,")=",round(value,.01)," p",tmp);
%let chic&i=tmp;
end;
RUN;
data _null_;
set chid&i;
format tmp $40.;
if Statistic="Chi-Square" then do;
tmp=put(prob,6.4);
if prob <.001 then do;
tmp= "<.001";
end;
if prob <.0001 then do;
tmp= "<.001";
end;
if prob gt .001 then do;
tmp=trim(catt(round(prob,.001)));
end;
tmp=catt("Chi-Square Results CHISQ","(",DF,")=",round(value,.01)," p",tmp);
%let chid&i=tmp;
end;
RUN;
data _null_;
set chie&i;
format tmp $40.;
if Statistic="Chi-Square" then do;
tmp=put(prob,6.4);
if prob <.001 then do;
tmp= "<.001";
end;
if prob <.0001 then do;
tmp= "<.001";
end;
if prob gt .001 then do;
tmp=trim(catt(round(prob,.001)));
end;
tmp=catt("Chi-Square Results CHISQ","(",DF,")=",round(value,.01)," p",tmp);
%let chie&i=tmp;
end;
RUN;
data _null_;
set chif&i;
format tmp $40.;
if Statistic="Chi-Square" then do;
tmp=put(prob,6.4);
if prob <.001 then do;
tmp= "<.001";
end;
if prob <.0001 then do;
tmp= "<.001";
end;
if prob gt .001 then do;
tmp=trim(catt(round(prob,.001)));
end;
tmp=catt("Chi-Square Results CHISQ","(",DF,")=",round(value,.01)," p",tmp);
%let chif&i=tmp;
end;
RUN;
***************************************************************************;
GOPTIONS RESET=ALL ftext="Albany AMT";
ods pdf file="\\vmware-host\Shared Folders\Documents\My Documents\PreDict\Hospital Reports\macro.pdf" startpage=never ;
goptions htitle=11pt;
options nodate nonumber;
options leftmargin=0.5in rightmargin=0.5in;
proc gslide;
title1 "Q&i. &title" lspace=.5in f="bold";
run;quit;
goptions horigin=0 vorigin=6.75 hsize=3 vsize=3 htext=7pt htitle=9pt ftitle="bold" gsfmode=append;
axis1 label=(a=90 f="Albany AMT" "Frequency") order=(0 to 140 by 20) minor=none;
axis2 label=none value=none;
axis3 label=none ;
legend1
label=("Response" h=2 pt position=left j=c)
position=(top inside left) mode=share
value=(h=5 pt 'Yes' 'No');
pattern1 v=solid color=CX93BFBF;
pattern2 v=solid color=CX4791ED;
proc gchart data=pd.griffin_collapsed_values;
vbar &var/DISCRETE
INSIDE=PERCENT
G100
GROUP=gender
SUBGROUP=&var
RAXIS=axis1
maxis=axis2
gaxis=axis3
legend=legend1
space=0
width=6
coutline=white;
where &var ne . and gender le 2;
format gender genderf. &var yesno.;
title1 "Gender" f="bold" ;
*footnote1 j=c h=.75 f=Albany "Figure a&i. &chia&i";
run;
quit;
*Bar chart #2;
goptions horigin=4.5 vorigin=6.75 hsize=3 vsize=3 htext=7pt htitle=9pt ftitle="bold" gsfmode=append;
axis1 label=(a=90 f="Albany AMT" "Frequency") order=(0 to 160 by 20) minor=none;
axis2 label=none value=none;
axis3 label=none ;
legend1
label=("Response" h=2 pt position=left j=c)
position=(top inside left) mode=share
value=(h=5 pt 'Yes' 'No');
pattern1 v=solid color=CX93BFBF;
pattern2 v=solid color=CX4791ED;
proc gchart data=pd.griffin_collapsed_values;
vbar &var/DISCRETE
OUTSIDE=PERCENT
G100
GROUP=agecat_coll
SUBGROUP=&var
RAXIS=axis1
maxis=axis2
gaxis=axis3
legend=legend1
space=0
width=5
coutline=white;
where &var ne .;
format agecat_coll agec. &var yesno.;
title1 "Age Categories" f=bold;
*footnote1 j=c h=.75 f=Albany "Figure b&i. &chib&i";
run;
quit;
*Bar chart #3;
goptions horigin=0 vorigin=3.5 hsize=3 vsize=3 htext=7pt htitle=9pt ftitle="bold" gsfmode=append;
axis1 label=(a=90 f="Albany AMT" "Frequency") order=(0 to 220 by 20) minor=none;
axis2 label=none value=none;
axis3 label=none ;
legend1
label=("Response" h=2 pt position=left j=c)
position=(top inside left) mode=share
value=(h=5 pt 'Yes' 'No');
pattern1 v=solid color=CX93BFBF;
pattern2 v=solid color=CX4791ED;
proc gchart data=pd.griffin_collapsed_values;
vbar &var/DISCRETE
OUTSIDE=PERCENT
G100
GROUP=race_coll
SUBGROUP=&var
RAXIS=axis1
maxis=axis2
gaxis=axis3
legend=legend1
space=0
width=6
coutline=white;
where &var ne .;
format race_coll racec. &var yesno.;
title1 "Race" f=bold;
*footnote1 j=c h=.75 f=Albany "Figure c&i. &chic&i";
run;
quit;
*Bar chart #4;
goptions horigin=4.5 vorigin=3.5 hsize=3 vsize=3 htext=7pt htitle=9pt ftitle="bold" gsfmode=append;
axis1 label=(a=90 f="Albany AMT" "Frequency") order=(0 to 140 by 20) minor=none;
axis2 label=none value=none;
axis3 label=none ;
legend1
label=("Response" h=2 pt position=left j=c)
position=(top inside left) mode=share
value=(h=5 pt 'Yes' 'No');
pattern1 v=solid color=CX93BFBF;
pattern2 v=solid color=CX4791ED;
proc gchart data=pd.griffin_collapsed_values;
vbar &var/DISCRETE
OUTSIDE=PERCENT
G100
GROUP=edu_coll2
SUBGROUP=&var
RAXIS=axis1
maxis=axis2
gaxis=axis3
legend=legend1
space=0
width=6
coutline=white;
where &var ne .;
format edu_coll2 educc. &var yesno.;
title1 "Education" f=bold;
*footnote1 j=c h=.75 f=Albany "Figure d&i. &chid&i";
run;
quit;
*Bar chart #5;
goptions horigin=0 vorigin=0 hsize=3 vsize=3 htext=7pt htitle=9pt ftitle="bold" gsfmode=append;
axis1 label=(a=90 f="Albany AMT" "Frequency") order=(0 to 220 by 20) minor=none;
axis2 label=none value=none;
axis3 label=none ;
legend1
label=("Response" h=2 pt position=left j=c)
position=(top inside left) mode=share
value=(h=5 pt 'Yes' 'No');
pattern1 v=solid color=CX93BFBF;
pattern2 v=solid color=CX4791ED;
proc gchart data=pd.griffin_collapsed_values;
vbar &var/DISCRETE
OUTSIDE=PERCENT
G100
GROUP=income_coll2
SUBGROUP=&var
RAXIS=axis1
maxis=axis2
gaxis=axis3
legend=legend1
space=0
width=6
coutline=white;
where discuss_pay ne .;
format income_coll2 incc. &var yesno.;
title1 "Income" f=bold;
*footnote1 j=c h=.75 f=Albany "Figure e&i. &chie&i";
run;
quit;
*Bar chart #6;
goptions horigin=4.5 vorigin=0 hsize=3 vsize=3 htext=7pt htitle=9pt ftitle="bold" gsfmode=append;
axis1 label=(a=90 f="Albany AMT" "Frequency") order=(0 to 140 by 20) minor=none;
axis2 label=none value=none;
axis3 label=none ;
legend1
label=("Response" h=2 pt position=left j=c)
position=(top inside left) mode=share
value=(h=5 pt 'Yes' 'No');
pattern1 v=solid color=CX93BFBF;
pattern2 v=solid color=CX4791ED;
proc gchart data=pd.griffin_collapsed_values;
vbar &var/DISCRETE
OUTSIDE=PERCENT
G100
GROUP=employ_coll2
SUBGROUP=&var
RAXIS=axis1
maxis=axis2
gaxis=axis3
legend=legend1
space=0
width=5
coutline=white;
where &var ne .;
format employ_coll2 empc. &var yesno.;
title1 "Employment" f=bold;
*footnote1 j=c h=.75 f=Albany "Figure f&i. &chif&i";
run;
quit;
ods pdf close;
title;
footnote;
%mend;
%proc_code( discuss_pay,1,Hospital personnel came to my room to discuss payment );
%proc_code( doc_language,2,All hospital documents were available in the language I prefer to read );
%proc_code( undstd_docs,3,I understood all the documents I was asked to sign );
%proc_code( undstd_role,4,I understood the role of all hospital personnel entering my room );
%proc_code( questions_hosp,5, Someone explained what I should do if I had questions after leaving the hospital);
%proc_code( comf_read_write,6,Someone asked me how comfortable I am reading and writing in English );
%proc_code( mt_affordmeds,7,A doctor asked me if I could afford my discharge medication );
%proc_code( mt_DNR,8,A doctor and I talked about whether I would want them to try to save me if my heart stopped );
%proc_code( mt_responsib,9,A doctor asked me if I had any responsibilities that would make me need to leave the hospital as soon as possible (for example, child care, work) );
%proc_code( mt_negcom,10, I heard the doctors make negative comments about me);
%proc_code( nt_negcom,11, I heard the nurses make negative comments about me);
%proc_code( ss_negcom,12,I heard the support staff make negative comments about me );
%proc_code( mt_follow_dcins,13,The doctors asked if my day-to-day routine would prevent me from following their discharge care instructions );
%proc_code( mt_takemed,14, The doctors asked if I was taking my medication regularly before coming to the hospital);
%proc_code( mt_fakesymp,15,The doctors told me I was exaggerating or faking my symptoms );
%proc_code( hosp_rules,16,My friends and family had trouble seeing me because of hospital rules );
%proc_code( ss_unattended,17,I was left unattended for a long time when I was taken to have a test );
%proc_code( mt_seniorphys,18,The senior/attending doctor came to see me every day );
If you want to stick with Gchart I suggest looking into Proc Greplay.
The general approach is that you send the output of each graph procedure to a specified graphics catalog (it helps to use a name that makes sense) with the GOUT option and using the NAME= option on each chart.
Use a TDEF statement to define a display template and save it.
Then use Treplay to point to the graphs created and tell the procedure which graph to place in which panel.
SASHELP.TEMPLT should have a number of example templates but they basically do 2 or 3 graphs stacked vertically or horizontal or 2 by 2.
If you use this approach the text in each graph gets shrunk so is a bit of a guessing game with your specific graphs.
The SG graphic procedures really are much better for attempting to place multiples on a page.
You might consider summarizing all of your data that use similar subgroups and add additional categorical variables to indicate the variable source and then look into SGPANEL.
Do you have any examples on using proc sgplot for outputting multiple pages in PDF? I can't seem to find any... Thank you!
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 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: