BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
morglum
Quartz | Level 8

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
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

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

12 REPLIES 12
Reeza
Super User

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;
Ksharp
Super User

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;

morglum
Quartz | Level 8

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

 

 

Ksharp
Super User

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.

morglum
Quartz | Level 8

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!

Ksharp
Super User

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

Reeza
Super User

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...

morglum
Quartz | Level 8

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


Ksharp
Super User

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

Ksharp
Super User

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;
morglum
Quartz | Level 8

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.

 

Reeza
Super User
Use the index and imagename option together so you'll know where it will start.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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