Write and run SAS programs in your web browser

Create file in a macro concatenate number PDF ODS

Accepted Solution Solved
Reply
Contributor
Posts: 23
Accepted Solution

Create file in a macro concatenate number PDF ODS

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'; )


Accepted Solutions
Solution
‎10-07-2016 03:40 AM
Super User
Posts: 19,157

Re: Create file in a macro concatenate number PDF ODS

[ Edited ]

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)

 








View solution in original post


All Replies
Solution
‎10-07-2016 03:40 AM
Super User
Posts: 19,157

Re: Create file in a macro concatenate number PDF ODS

[ Edited ]

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)

 








Contributor
Posts: 23

Re: Create file in a macro concatenate number PDF ODS

[ Edited ]

thanks it works perfect! 

 

Super User
Posts: 7,433

Re: Create file in a macro concatenate number PDF ODS


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?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 19,157

Re: Create file in a macro concatenate number PDF ODS


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. 

Super User
Posts: 5,366

Re: Create file in a macro concatenate number PDF ODS

[ Edited ]

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.

Super User
Posts: 11,134

Re: Create file in a macro concatenate number PDF ODS

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;

 

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 313 views
  • 0 likes
  • 5 in conversation