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

Hi,

 

I am trying to use ODS combining with macro to save png plots. The first time I submit the following codes:

%Let param1=Intercept;
%Let param2=x;
/* Save png */
%macro m_hist;
	%Do para=1 %to 2;
	Ods graphics / imagename="&&param&para" imagefmt=png;
	Proc univariate data=combination;
		Title "Histogram of &&param&para";
		Where Variable="&&param&para";
		Var Estimate;
		Histogram Estimate/ odstitle="Histogram of &&param&para";
	Run;
	%End;
%mend;
%m_hist;

I get two files Intercept1.png and x1.png.

 

This is unusual since I set the names without number 1 at the end.

 

I submit the macro program again, %m_hist;, this time I get Intercept3.png and x3.png. The third time I submit I get Intercept5.png and x5.png.

 

That is not what I expect. Do you have any idea?

Thanks for reading!

 

Kind regards,

Trung Dung.

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

The numbers at te end if file names have nothing to do with your macro. They are added by the ODS to avoid overwriting existing files as explained here:

 

https://documentation.sas.com/?docsetId=statug&docsetTarget=statug_odsgraph_sect036.htm&docsetVersio...

 

Change your statement to

 

Ods graphics / imagename="&&param&para" imagefmt=png reset=index;

 

to force overwriting.

PG

View solution in original post

5 REPLIES 5
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

that is because of this statement:

%Do para=1 %to 2;

so you are getting the results that are specified.

 

trungdungtran
Obsidian | Level 7

Hi @VDD,

 

I think the file names are fixed as &&param&para is resolved as "Intercept" when i=1 and "x" when i=2. Could you explain more?

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

the do loop is setting &para.

PGStats
Opal | Level 21

The numbers at te end if file names have nothing to do with your macro. They are added by the ODS to avoid overwriting existing files as explained here:

 

https://documentation.sas.com/?docsetId=statug&docsetTarget=statug_odsgraph_sect036.htm&docsetVersio...

 

Change your statement to

 

Ods graphics / imagename="&&param&para" imagefmt=png reset=index;

 

to force overwriting.

PG
trungdungtran
Obsidian | Level 7

Yes, the option "reset=index" solves the problem!

 

Thank you @PGStats.

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 881 views
  • 1 like
  • 3 in conversation