BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi

I am trying to create a macro that will allow me to produce a box plot and save it as a (.rtf) file using ODS. I want to define the directory to which the file will be saved as a macro parameter. But I am having problems with this step.

I have created the SAS program first (below) and it works

ods listing close;
ods rtf file='c:\data\Boxplot.rtf';
proc sort data = register;
by type;
proc boxplot data=register;
plot sbp*type;
run;
ods rtf close;
ods listing;


However when I create the macro I am having problems defining the directory path as a macro parameter. I have tried different formats to define the ODS directory path in the marco using the parameter (one example below) . However I keep receiving log error that the directory does not exist.


%macro graphics(parm1);
ods listing close;
ods rtf file= &parm1 'Boxplot.rtf';
proc sort data = register;
by type;
proc boxplot data=register;
plot sbp*type;
run;
ods rtf close;
ods listing;
%mend graphics;

%graphics(c:\data\);


I assume I am not using the macro parameter correctly. Any suggestions would be appreciated.

cheers, Alistair Message was edited by: Alby
2 REPLIES 2
ArtC
Rhodochrosite | Level 12
You are very close. Just a couple of things:
1) Double quotes must be used to surround macro variables that appear inside of quoted strings.
2) The &PARM1 is part of the path and as such must be quoted.
The ODS statement becomes:
[pre]
ods rtf file= "&parm1\Boxplot.rtf";
[/pre]
Art
deleted_user
Not applicable
Thanks Art. That worked.

Cheers, Alistair

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2 replies
  • 1521 views
  • 0 likes
  • 2 in conversation