I'm trying to generate PDF files with diferent namen in each iteration.
My code I need is:
%macro x1(i);
ODS PDF FILE='myfolders/newfile_&i';
ODS PDF CLOSE;
%mend;
%macro x2(init,end);
%do i=&init %to &end;
x1(&i)
%end
%mend;
%x2(1,2)
My problem is that I dont know how to update in the name of the new file the number i ( newfile_&i'; )
What do you want the file name to be?
As is it will be
new_file1
new_file2
Your also missing the extension which make cause issues.
Oh...and double quotes not single quotes. Macro variables don't resolve in single quotes.
And your second macro is pointless. Loop in your main macro.
And you need a period to let SAS know where the end of the macro variable is.
%macro x1(init, end);
%do I =&unit %to &bend;
ODS PDF FILE="myfolders/newfile_&i..pdf";
Title "This is report #&i.";
Proc print data = sashelp.class;
run;
ODS PDF CLOSE;
%end;
%mend;
%x1(1,2)
What do you want the file name to be?
As is it will be
new_file1
new_file2
Your also missing the extension which make cause issues.
Oh...and double quotes not single quotes. Macro variables don't resolve in single quotes.
And your second macro is pointless. Loop in your main macro.
And you need a period to let SAS know where the end of the macro variable is.
%macro x1(init, end);
%do I =&unit %to &bend;
ODS PDF FILE="myfolders/newfile_&i..pdf";
Title "This is report #&i.";
Proc print data = sashelp.class;
run;
ODS PDF CLOSE;
%end;
%mend;
%x1(1,2)
thanks it works perfect!
@mariange8282 wrote:
thanks but &i in
ODS PDF FILE="myfolders/newfile_&i..pdf";
not change the name, because the program assume that all in "....." is a string and not avaluate the variables.
This is plain wrong.
If i is present as a macro variable, and has different values, this will work.
Did you run @Reeza's code as presented, to test the principle?
@mariange8282 wrote:
thanks but &i in
ODS PDF FILE="myfolders/newfile_&i..pdf";
not change the name, because the program assume that all in "....." is a string and not avaluate the variables.
I don't understand what your saying here.
1. Does the code run as posted and generate two files?
2. How does it not meet your requirements. Not a mind reader here. Be explicit.
Your original post used single quotes, which prevent resolution of macro variables within. The sample solutions use double quotes, which allow that resolution. So that's part of the change you will need to make, switching from single to double quotes.
In addition to the issue with single quotes:
%do i=&init %to &end;
x1(&i) <you do not call the X1 macro correctly inside %x2 should be %x1
%end < No ; to complete the %end;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.