Data visualization with SAS programming

Saving PROC GPLOT graph to folder

Reply
New Contributor
Posts: 2

Saving PROC GPLOT graph to folder

Hi,

I would like to save my PROC GPLOT graph in a specific folder using the filename statement but it keeps saving it to a temporary folder. Does anyone know how to debug this?

Thanks!

code:

filename grafout "H:\My Document\picture.jpeg";

goptions reset=all gsfname=grafout gsfmode=replace device=jpeg;

proc gplot data = KM_Weibull_var_0;

    plot survival*t2dss = grade_new ;

run;

quit;

filename grafout clear;

Log message shows:

NOTE:  records written to C:\Temp\SAS Temporary Files\_TD5676_PC004231_\gplot7.jpg

Grand Advisor
Posts: 16,348

Re: Saving PROC GPLOT graph to folder

Try using the jpg file extension rather than JPEG.

There's a note in the docs regarding this:

SAS/GRAPH(R) 9.2: Reference, Second Edition

If you specify the filename in the FILENAME statement, you must include the proper file extension. See About File Extensions.

filename grafout "H:\My Document\picture.jpg";

goptions reset=all gsfname=grafout gsfmode=replace device=jpeg;

proc gplot data = KM_Weibull_var_0;

    plot survival*t2dss = grade_new ;

run;

quit;

filename grafout clear;

New Contributor
Posts: 2

Re: Saving PROC GPLOT graph to folder

Thanks Reeza. I changed my filename to ".jpg" but it's still saving it to my temporary folder.

Do you have any other ideas why it's doing this?

Also, i'm using SAS 9.3. Does the version matter?

thanks

Grand Advisor
Posts: 16,348

Re: Saving PROC GPLOT graph to folder

Works for me on SAS 9.3.

If you don't have any errors in the log I'd contact tech support.

1    filename grafout "C:\temp\picture_sample.jpg";

2    goptions reset=all gsfname=grafout gsfmode=replace device=jpeg;

3    proc gplot data = sashelp.class;

4        plot weight*height = sex ;

5    run;

NOTE:  records written to C:\temp\picture_sample.jpg

6    quit;

NOTE: There were 19 observations read from the data set SASHELP.CLASS.

NOTE: PROCEDURE GPLOT used (Total process time):

      real time           1.92 seconds

      cpu time            0.34 seconds

7    filename grafout clear;

NOTE: Fileref GRAFOUT has been deassigned.

Frequent Contributor
Posts: 98

Re: Saving PROC GPLOT graph to folder

I am having the same problem. Using this code:

 

filename graphout "C:\tmp\loadingplot.png";

goptions reset=all device=png gsfname=graphout;

axis1 label=(angle=90 "Factor 2 Loading") order=(-0.5 to 1 by 0.5) minor=none;

axis2 label=("Factor 1 Loading") order=(-0.5 to 1 by 0.5) minor=none;

PROC GPLOT data=_factors;

plot Factor2*Factor1=1 / vaxis=axis1 haxis=axis2;

format Factor1 z4.2;

format Factor2 z4.2;

run;

quit;

 

No matter what path I put into the filename (and I have checked to make sure the paths are valid), it writes the file to a folder in the SAS Temporary Files directory, without even assigning it the right name.

 

Does anybody have any idea what is going on? This behavior only manifests itself when using goptions. Saving files using ODS works perfectly fine. For example, this code saves the file with the right name in the correct directory:

 

ods graphics / reset=index imagename='scatter_example' imagefmt=png;

ods listing gpath="C:\tmp";

PROC SGPLOT data=test;

scatter x=covariate y=response / markerattrs=(symbol=CircleFilled);

run;

ods graphics off;

ods listing close;

 

So why does this happen with the goptions output? Even setting the SAS temporary directory to the one I want and then running the code doesn't change where SAS decides to write/name the file.

Frequent Contributor
Posts: 98

Re: Saving PROC GPLOT graph to folder

Well, moments after posting, I discovered the solution. Still not sure as to the source of the problem, but simply adding

 

ods listing;

 

Before the code works. Of course, it isn't clear to me why exactly this behavior is happening. Further, it still creates the problem where now SAS is actually outputting TWO image files:

 

3863 run;

NOTE: 30124 bytes written to C:\tmp\gplot31.png.

NOTE: 30134 bytes written to C:\tmp\loadingplot.png.

3864 quit;

 

 

Valued Guide
Posts: 723

Re: Saving PROC GPLOT graph to folder

Hi.  The behavior you describe relies on the RESULTS setting you have specified under the tab TOOLS/OPTIONS/PREFERENCES (see attached).  If  you have selected just HTML, you get the behavior you described.  If you have selected LISTING (as I have) you'll get ...

 

52 filename graphout 'z:\test.png';
53
54 goptions reset=all device=png gsfname=graphout;
55
56 proc gplot data=sashelp.class;
57 plot height*weight;
58 run;

NOTE: 9532 bytes written to z:\test.png.
59 quit;

 

If you have both HTLM and LISTING checked, you get ...

 

61 filename graphout 'z:\test.png';
62
63 goptions reset=all device=png gsfname=graphout;
64
65 proc gplot data=sashelp.class;
66 plot height*weight;
67 run;

NOTE: Writing HTML Body file: sashtml1.htm
NOTE: 9520 bytes written to C:\Users\Mike\AppData\Local\Temp\SAS Temporary Files\_TD1112_MIKENEW_\gplot6.png.
NOTE: 9532 bytes written to z:\test.png.
68 quit;

 

 

 

Attachment
SAS Employee
Posts: 963

Re: Saving PROC GPLOT graph to folder

[ Edited ]

You might want to try the following more modern syntax instead.

Ods html will create an extra html file that you don't really need (if you just want the graphic file), but you can just ignore or delete it.

 

I would also highly recommend using png rather than jpeg. Jpeg is better suited for things like photographs, but png will probably create a sharper looking graph.

 

filename odsout 'c:\graph_test\';
ODS LISTING CLOSE;
goptions device=png;
/* or device=jpeg */
ODS HTML path=odsout body="junk.htm";
proc gplot data=sashelp.class;
plot height*weight / name='picture';
run;
quit;
ODS HTML CLOSE;
ODS LISTING;

 

Post a Question
Discussion Stats
  • 7 replies
  • 4796 views
  • 2 likes
  • 5 in conversation