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
Diamond | Level 26

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

Catch up on SAS Innovate 2026

Dive into keynotes, announcements and breakthroughs on demand.

Explore 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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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