Hi Everyone,
I'm generating png's using Proc SGPLOT insert them inside a proc report through "preimage".
However, the image quality is reduced inside the produced PDF. How can I avoid this loss of quality?
Attached, the SAS program used to generate the three PNG and the report.
thanks!
Make dpi of picture and PDF bigger .
ODS listing GPATH = '/folders/myfolders/' image_dpi=1000;
title;
footnote;
data temp;
do x =1 to 20;
y1= 2*(x+ranuni(1));
y2= 2*(x+ranuni(2))-x;
y3= 2*(x+ranuni(3))-x;
output;
end;
run;
ods graphics on / reset=all width=2in height=1in imagename="Graph1";
proc sgplot data=temp noautolegend ;
series x=x y=y1 /lineattrs=(thickness=2.5) ;
xaxis label="time" values=(1 to 20 by 1) ;
yaxis label="($)" min=0 ;
title "Graph 1";
run;
ods graphics on / reset=all width=2in height=1in imagename="Graph2";
proc sgplot data=temp noautolegend ;
series x=x y=y2 /lineattrs=(thickness=2.5) ;
xaxis label="time" values=(1 to 20 by 1) ;
yaxis label="($)" min=0 ;
title "Graph 2";
run;
ods graphics on / reset=all width=2in height=1in imagename="Graph3";
proc sgplot data=temp noautolegend ;
series x=x y=y3 /lineattrs=(thickness=2.5) ;
xaxis label="time" values=(1 to 20 by 1) ;
yaxis label="($)" min=0 ;
title "Graph 3";
run;
data images;
image1="/folders/myfolders/graph1.png";
image2="/folders/myfolders/graph2.png";
image3="/folders/myfolders/graph3.png";
run;
ods pdf file= "/folders/myfolders/report.pdf" dpi=1000;
title "3 graphs";
proc report data=images nofs nowd ;
column image1 image2 image3;
define image1 / "" display style={cellwidth=2.5in};
define image2 / "" display style={cellwidth=2.5in};
define image3 / "" display style={cellwidth=2.5in};
compute image1;
call define(_col_,"Style","Style=[PREimage='"!!image1!!"']");
image1=""; *<<< Avoid image location being printed;
endcomp;
compute image2;
call define(_col_,"Style","Style=[PREimage='"!!image2!!"']");
image2=""; *<<< Avoid image location being printed;
endcomp;
compute image3;
call define(_col_,"Style","Style=[PREimage='"!!image3!!"']");
image3=""; *<<< Avoid image location being printed;
endcomp;
run;
ods pdf close;
Justing the code inline to make it easier for others to help debug.
ODS HTML GPATH = 'c:\temp\' style=styles.custom ;
title;
footnote;
data temp;
do x =1 to 20;
y1= 2*(x+ranuni(1));
y2= 2*(x+ranuni(2))-x;
y3= 2*(x+ranuni(3))-x;
output;
end;
run;
ods graphics on / reset=all width=2in height=1in imagename="Graph1";
proc sgplot data=temp noautolegend ;
series x=x y=y1 /lineattrs=(thickness=2.5) ;
xaxis label="time" values=(1 to 20 by 1) ;
yaxis label="($)" min=0 ;
title "Graph 1";
run;
ods graphics on / reset=all width=2in height=1in imagename="Graph2";
proc sgplot data=temp noautolegend ;
series x=x y=y2 /lineattrs=(thickness=2.5) ;
xaxis label="time" values=(1 to 20 by 1) ;
yaxis label="($)" min=0 ;
title "Graph 2";
run;
ods graphics on / reset=all width=2in height=1in imagename="Graph3";
proc sgplot data=temp noautolegend ;
series x=x y=y3 /lineattrs=(thickness=2.5) ;
xaxis label="time" values=(1 to 20 by 1) ;
yaxis label="($)" min=0 ;
title "Graph 3";
run;
data images;
image1="c:\temp\graph1.png";
image2="c:\temp\graph2.png";
image3="c:\temp\graph3.png";
run;
ods pdf file= "c:\temp\report.pdf";
title "3 graphs";
proc report data=images nofs ;
column image1 image2 image3;
define image1 / "" display style={cellwidth=2.5in};
define image2 / "" display style={cellwidth=2.5in};
define image3 / "" display style={cellwidth=2.5in};
compute image1;
call define(_col_,"Style","Style=[PREimage='"!!image1!!"']");
image1=""; *<<< Avoid image location being printed;
endcomp;
compute image2;
call define(_col_,"Style","Style=[PREimage='"!!image2!!"']");
image2=""; *<<< Avoid image location being printed;
endcomp;
compute image3;
call define(_col_,"Style","Style=[PREimage='"!!image3!!"']");
image3=""; *<<< Avoid image location being printed;
endcomp;
run;
ods pdf close;
Make dpi of picture and PDF bigger .
ODS listing GPATH = '/folders/myfolders/' image_dpi=1000;
title;
footnote;
data temp;
do x =1 to 20;
y1= 2*(x+ranuni(1));
y2= 2*(x+ranuni(2))-x;
y3= 2*(x+ranuni(3))-x;
output;
end;
run;
ods graphics on / reset=all width=2in height=1in imagename="Graph1";
proc sgplot data=temp noautolegend ;
series x=x y=y1 /lineattrs=(thickness=2.5) ;
xaxis label="time" values=(1 to 20 by 1) ;
yaxis label="($)" min=0 ;
title "Graph 1";
run;
ods graphics on / reset=all width=2in height=1in imagename="Graph2";
proc sgplot data=temp noautolegend ;
series x=x y=y2 /lineattrs=(thickness=2.5) ;
xaxis label="time" values=(1 to 20 by 1) ;
yaxis label="($)" min=0 ;
title "Graph 2";
run;
ods graphics on / reset=all width=2in height=1in imagename="Graph3";
proc sgplot data=temp noautolegend ;
series x=x y=y3 /lineattrs=(thickness=2.5) ;
xaxis label="time" values=(1 to 20 by 1) ;
yaxis label="($)" min=0 ;
title "Graph 3";
run;
data images;
image1="/folders/myfolders/graph1.png";
image2="/folders/myfolders/graph2.png";
image3="/folders/myfolders/graph3.png";
run;
ods pdf file= "/folders/myfolders/report.pdf" dpi=1000;
title "3 graphs";
proc report data=images nofs nowd ;
column image1 image2 image3;
define image1 / "" display style={cellwidth=2.5in};
define image2 / "" display style={cellwidth=2.5in};
define image3 / "" display style={cellwidth=2.5in};
compute image1;
call define(_col_,"Style","Style=[PREimage='"!!image1!!"']");
image1=""; *<<< Avoid image location being printed;
endcomp;
compute image2;
call define(_col_,"Style","Style=[PREimage='"!!image2!!"']");
image2=""; *<<< Avoid image location being printed;
endcomp;
compute image3;
call define(_col_,"Style","Style=[PREimage='"!!image3!!"']");
image3=""; *<<< Avoid image location being printed;
endcomp;
run;
ods pdf close;
Hi Xia,
Thanks for replying! It worked.
For some reason, the naming scheme changed over the weekend..
I now get graph11.png graph21.png and graph31.png.
(The index starts at "1" instead of "no number") any idea what might be going on?
thanks!
Simon
I would make a macro to make it happen if I were you . decide the naming rule of graph and assign it to a macro variable.
Hi Xia,
Thanks for replying! I dont think my issue requires a macro. What I mean is that the file created after I do a "reset=all" is named
"name1.png" instead of "name.png".
That's an unrelated issue, but I was wondering if you might know what is going on.
cheers!
No. I have no any clue about it . SAS has itself naming rule .
Most likely it's starting with 1 because the other file already exists?
EDIT: you can specify where the index starts in the latest SAS releases, though I think a similar option existed in SAS 9.2
Nope, i deleted everything. In the example code above from Xia, i get the
wrong file numbers.
Did you start a fresh new SAS session to run the code ?
Why not use ODS LAYOUT, that would not need to consider about file name ?
data temp;
do x =1 to 20;
y1= 2*(x+ranuni(1));
y2= 2*(x+ranuni(2))-x;
y3= 2*(x+ranuni(3))-x;
output;
end;
run;
ods pdf file='/folders/myfolders/xx.pdf' ;
ods layout gridded advance=table COLUMNS=3;
ods graphics on / reset=all width=2in height=1in imagename="Graph1";
proc sgplot data=temp noautolegend ;
series x=x y=y1 /lineattrs=(thickness=2.5) ;
xaxis label="time" values=(1 to 20 by 1) ;
yaxis label="($)" min=0 ;
title "Graph 1";
run;
ods graphics on / reset=all width=2in height=1in imagename="Graph2";
proc sgplot data=temp noautolegend ;
series x=x y=y2 /lineattrs=(thickness=2.5) ;
xaxis label="time" values=(1 to 20 by 1) ;
yaxis label="($)" min=0 ;
title "Graph 2";
run;
ods graphics on / reset=all width=2in height=1in imagename="Graph3";
proc sgplot data=temp noautolegend ;
series x=x y=y3 /lineattrs=(thickness=2.5) ;
xaxis label="time" values=(1 to 20 by 1) ;
yaxis label="($)" min=0 ;
title "Graph 3";
run;
ods pdf close;
Thanks Xia!
That's a good tip and I didnt know about it, but I need to know the exact filename of the png to attach it to an email generated using "filename email"
cheers!
S.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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: