BookmarkSubscribeRSS Feed
ychen
Calcite | Level 5

HI all,

I was trying to make a macro do loop to create several PDF files, however, failed.

Does anyone know how to create several PDF files using a do loop?

thanks,

alice

2 REPLIES 2
ballardw
Super User

If you posted the loop code we might be able to provide a quick fix but something like this is a rough structure:

%macro pdfloop();

     %do I = 1 %to 4;

          ods pdf file="c:\path\file&I..pdf" ; /* put the pdf options on that line*/

          proc print data=sashelp.class;run;

          ods pdf close;

     %end;

%mend;

%pdfloop();

If you tried to loop through a list of character values as in %do name= Bill,John,Fred; then you will get a failure as the Macro %do loop doesn't allow text arguments as the data step do loop does.

Cynthia_sas
SAS Super FREQ

This works for me. If it doesn't work for you, then I suggest working with Tech Support by sending them your code and a sample of your data.

Cynthia

%macro dopdf;

  %do i = 1 %to 3;
     %if &i = 1 %then %let dsn=sashelp.class;
     %else %if &i = 2 %then %let dsn=sashelp.cars;
     %else %let dsn=sashelp.prdsale;

  

     ods pdf file="c:\temp\out&i..pdf";
      proc print data=&dsn (obs=5);
        title "Loop is: &i and Data is: &dsn";
      run;
     ods pdf close;
  %end;

%mend dopdf;

 

%dopdf

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1539 views
  • 0 likes
  • 3 in conversation