The SAS Output Delivery System and reporting techniques

SGPLOT > PNG > Proc report PREIMAGE > Ods PDF how to avoid rescaling?

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 96
Accepted Solution

SGPLOT > PNG > Proc report PREIMAGE > Ods PDF how to avoid rescaling?

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!

 


Graph2.pngGraph3.pngGraph1.png
Attachment

Accepted Solutions
Solution
‎01-18-2016 10:34 AM
Super User
Posts: 9,874

Re: SGPLOT > PNG > Proc report PREIMAGE > Ods PDF how to avoid rescaling?

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;

View solution in original post


All Replies
Super User
Posts: 19,165

Re: SGPLOT > PNG > Proc report PREIMAGE > Ods PDF how to avoid rescaling?

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;
Solution
‎01-18-2016 10:34 AM
Super User
Posts: 9,874

Re: SGPLOT > PNG > Proc report PREIMAGE > Ods PDF how to avoid rescaling?

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;

Frequent Contributor
Posts: 96

Re: SGPLOT > PNG > Proc report PREIMAGE > Ods PDF how to avoid rescaling?

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

 

 

Super User
Posts: 9,874

Re: SGPLOT > PNG > Proc report PREIMAGE > Ods PDF how to avoid rescaling?

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.

Frequent Contributor
Posts: 96

Re: SGPLOT > PNG > Proc report PREIMAGE > Ods PDF how to avoid rescaling?

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!

Super User
Posts: 9,874

Re: SGPLOT > PNG > Proc report PREIMAGE > Ods PDF how to avoid rescaling?

No. I have no any clue about it . SAS has itself naming rule .

Super User
Posts: 19,165

Re: SGPLOT > PNG > Proc report PREIMAGE > Ods PDF how to avoid rescaling?

[ Edited ]

http://support.sas.com/documentation/cdl/en/grstatproc/67909/HTML/default/viewer.htm#p0f8elds7dc3dnn...

 

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

http://support.sas.com/documentation/cdl/en/grstatproc/67909/HTML/default/viewer.htm#p0kroq43yu0lspn...

Frequent Contributor
Posts: 96

Re: SGPLOT > PNG > Proc report PREIMAGE > Ods PDF how to avoid rescaling?

[ Edited ]

Nope, i deleted everything. In the example code above from Xia, i get the
wrong file numbers.


Super User
Posts: 9,874

Re: SGPLOT > PNG > Proc report PREIMAGE > Ods PDF how to avoid rescaling?

Did you start a fresh new SAS session to run the code ?

Super User
Posts: 9,874

Re: SGPLOT > PNG > Proc report PREIMAGE > Ods PDF how to avoid rescaling?

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;
Frequent Contributor
Posts: 96

Re: SGPLOT > PNG > Proc report PREIMAGE > Ods PDF how to avoid rescaling?

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.

 

Super User
Posts: 19,165

Re: SGPLOT > PNG > Proc report PREIMAGE > Ods PDF how to avoid rescaling?

Use the index and imagename option together so you'll know where it will start.
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 12 replies
  • 1125 views
  • 0 likes
  • 3 in conversation