Data visualization with SAS programming

ODS Graphics Index Counter Resets to 1?

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 98
Accepted Solution

ODS Graphics Index Counter Resets to 1?

I am creating some figures using PROC SGPLOT using SAS 9.4, outputting the results as PNG files in a specific directory. My code might look like this, for example:

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

ods listing gpath="&outdir.";

PROC SGPLOT data=longdat noautolegend;

       series x=month y=response / group=rexid grouplc=slope lineattrs=(pattern=1);

       yaxis values=(10 to 70 by 10);

       xaxis values=(0 to 6 by 6);

run;

However, anytime this code is run, it creates a plot called 'spaghetti1.png'. And it does so even if the directory is clear of any files, and if I open SAS and run it without running any other ods graphics statements first. For some reason, it is consistently resetting the index counter for the image names to 1, instead of 0. According to the documentation, it should only append "1" (or any other index counter) to the image name if I rerun the statement using the same image name. However, it is ALWAYS adding the 1, no matter what.

Why is the ods graphics counter not resetting to 0, thus giving me the output "spaghetti.png" as it should?


Accepted Solutions
Solution
‎08-27-2015 12:50 PM
SAS Super FREQ
Posts: 862

Re: ODS Graphics Index Counter Resets to 1?

More than likely, you have two destinations open -- the default HTML destination that opens with the session and your LISTING destination. The HTML destination creates "spaghetti.png" and the LISTING destination creates "spaghetti1.png". To remedy this, add "ODS HTML CLOSE;" to the beginning of your program.

View solution in original post


All Replies
Solution
‎08-27-2015 12:50 PM
SAS Super FREQ
Posts: 862

Re: ODS Graphics Index Counter Resets to 1?

More than likely, you have two destinations open -- the default HTML destination that opens with the session and your LISTING destination. The HTML destination creates "spaghetti.png" and the LISTING destination creates "spaghetti1.png". To remedy this, add "ODS HTML CLOSE;" to the beginning of your program.

Frequent Contributor
Posts: 98

Re: ODS Graphics Index Counter Resets to 1?

So, adding ODS HTML CLOSE before this code works, but I don't understand what the problem is.

There are no other ODS calls in the code before this, so it is going from SAS's default settings. The only other code in the program before that PROC SGPLOT are DATA steps. Why is it defaulting to having two destinations open?

SAS Super FREQ
Posts: 862

Re: ODS Graphics Index Counter Resets to 1?

Starting with SAS 9.3, we open up an HTML destination by default to provide a default viewer for all output (instead of just a graph window for device-based graphics). This happens in the SAS session without any requiring any ODS statements. When you specified your LISTING destination, you just opened up one more destination. Had you opened up an HTML destination with a filename, the default HTML destination would have automatically closed.

With that said, you can disable the automatic HTML destination by going to Tools->Options->Preferences..., selecting the "Result" tab, and unchecking the HTML destination.

Hope this answers all of your questions.

Thanks!

Dan

Frequent Contributor
Posts: 98

Re: ODS Graphics Index Counter Resets to 1?

Makes sense!

Thanks a lot, Dan.

Post a Question
Discussion Stats
  • 4 replies
  • 474 views
  • 3 likes
  • 2 in conversation