I want graph per page in PNG file. I have tried many ways but didn't get. I am using below code but from this code i am getting 2 separate output instead of two graph in one PNG file (One per page).
%let __date = %sysfunc(putn( %sysfunc(date()) ,date9.));
%put &__date. ;
%LET outputno = 1 ;
%inc gtitles;
ods listing image_dpi=300 gpath="&mrgpath";
options nobyline;
ods graphics on / reset=index imagename="&mrimgnm" imagefmt=png width=3.5in height=3in byline=title
border=off antialiasmax=10000;
%macro temp(lb=,mn=,mx=,grp=);
proc template;
define statgraph example3_template_v2;
dynamic _title1 _title2 _footnotel _footnoter _disp;
begingraph ;*/designwidth=1000px designheight=1000px;
entrytitle halign=left textattrs=(size=5pt weight=normal) "ABC";
entryfootnote halign=left textattrs=(size=5pt) "XYZ";
entryfootnote halign=right textattrs=(size=5pt) "&progname &SYSDATE9";
layout lattice/ columns=1 rows=1 rowgutter=0pt columnweights=(0.300)
columngutter=0 rowdatarange=union;
layout overlay /WALLDISPLAY=NONE
yaxisopts=(label="Maximum decrease from baseline [%]" labelattrs=(size=5)
labelfitpolicy=split tickvalueattrs=(size=5pt)
linearopts=(viewmin=-100 viewmax=80 tickvaluesequence = (start=-100 end=80 increment=20)))
xaxisopts=(label="Patient index sorted by maximum % decrease" labelattrs=(size=5)
discreteopts=(tickvaluefitpolicy=ROTATE tickdisplaylist=(&&subj&grp)
tickvaluelist=(&&n&grp)) labelfitpolicy=split
tickvalueattrs=(size=1pt) linearopts=(viewmin=&mn viewmax=&mx));
barchartparm x=eval(ifn(trtpn=&grp,input(n,8.),.)) y=eval(ifn(trtpn=&grp,pchg,.)) / orient=vertical
group=pchgcat1 BARWIDTH=1 name="A";
discretelegend "A"/valueattrs=(size=1pt) halign=right valign=top border=false;
referenceline y=20 /LINEATTRS=(color=black thickness=1 pattern=shortdash);
referenceline y=-30/LINEATTRS=(color=black thickness=1 pattern=shortdash);
referenceline y=-50/LINEATTRS=(color=black thickness=1 pattern=shortdash);
endlayout;
endlayout;
endgraph;
end;
run;
quit;
proc sgrender data=adtr1 template = example3_template_v2;
dynamic
_disp = "all"
_title1 = "&mrds2 &mrdx"
_title2 = "&mrds2"
_footnotel = "&mrsrc"
_footnoter = "%trim(&progname) &__date";
run;
%mend;
%temp(lb=TRT1,mn=&ord0,mx=&ord1,grp=8);
%temp(lb=TRT2,mn=&ord2,mx=&ord3,grp=9);
Can you describe what you want the final result to look like? It looks like your template defines a vertical bar chart and then renders it by using PROC SGRENDER. Thus each call to your macro will produce one graph.
If you want a panel of graphs, you can use PROC SGPANEL if the data are in "long form." You can also define template that uses LAYOUT LATTICE / COLUMNS=2;
to create a panel.
Final result I want is 2 graph but it will be in two pages like each graph per page. If i use panel procedure than both the graph will come in one page that i dont want. I want both graph in separate page in PNG file.
In this case, your best option is to do what @Rick_SAS suggested and use a LAYOUT LATTICE with COLUMNS=2 in your template. This means you will will need to pass the dynamics for both plots using one call of your macro.
Do you have any example that use both lattice and Dynamics?
Not two different png. One graph per page I want
I have attached file for reference. I want two graph like mentioned in attachment with enough space between two graph
You can do that within a single PROC, not quite sure how you'd macrotize this, unless you do it for each layout statement. In that case you may want to look into the DATALATTICE statement which can make it data driven.
Set the # of rows to 2, which is one for each graph as well as specifying the ROWGUTTER setting to 1 inch, which adds the spacing between the graphs. This will create a single PNG file.
proc template; define statgraph lattice; begingraph; entrytitle "Car Performance Profile"; layout lattice / border=true pad=10 opaque=true rows=2 columns=1 columngutter=3 rowgutter=1IN; layout overlay; scatterplot x=horsepower y=mpg_city / group=origin name="cars"; regressionPlot x=horsepower y=mpg_city / degree=2; endlayout; layout overlay; endlayout; layout overlay; barchart category=type response=mpg_highway / stat=mean orient=horizontal; endlayout; endlayout; endgraph; end; run; ods html file = '/folders/myfolders/demo.html' gpath = '/folders/myfolders/Temp/'; ods graphics on / imagefmt= png imagename="carGraph"; proc sgrender template=lattice data=sashelp.cars; run; ods graphics off;
> Not two different png. One graph per page I want
From @Reeza : I don't believe PNG files have the concept of 'pages'
@SanjayAhir Can you see why you haven't explained your needs properly? There are no pages in PNG files.
Here's one way to do it, using SAS/Graph Proc Greplay:
data my_data; set sashelp.stocks (where=(date>='01jan2005'd));
format date monname3.;
quarter=put(date,yyq.);
run;
axis1 label=none;
goptions nodisplay;
goptions xpixels=500 ypixels=400;
title ls=3.0 "IBM Graph";
footnote h=5pct " ";
proc gchart data=my_data (where=(stock='IBM'));
vbar date / discrete type=sum sumvar=close subgroup=quarter
maxis=axis1 raxis=axis1 name='graph1';
run;
goptions xpixels=500 ypixels=400;
title ls=3.0 "Intel Graph";
footnote h=5pct " ";
proc gchart data=my_data (where=(stock='Intel'));
vbar date / discrete type=sum sumvar=close subgroup=quarter
maxis=axis1 raxis=axis1 name='graph2';
run;
goptions display;
goptions xpixels=500 ypixels=800;
proc greplay igout=work.gseg tc=sashelp.templt template=v2s nofs;
treplay 1:graph1 2:graph2;
run;
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!
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.