HI All,
I am facing issue with ODS RTF when I write with in a Loop. please check below details and help me.
I want to write list of lets take 50 subjects Output into a single RTF file and for each subject we have some 10 PROC Reports(1 for each Panel) and all should come in a single Output file.
But the code below , is giving Output only for last Subject, (Ex: if I have 10 subjects as Count, the output file is getting generated only for 10th Subject). I am not sure what is going wrong in this. please provide your suggestions. Thanks in advance.
Sample code:
%di I=1 %to &cnt;
ods RTF startpage=never;
ods rtf file = 'xxxxxxx.rtf';
%calldomains; /*(in this macro we have written Proc report code for each panel and roughly we have 10 Proc reports, so here for each subject we should get 10 tables frome ach panel and next subject output should come in same RTF file).*/
ods RTF startpage=Now;
%end;
ods rtf close;
ods listing;
The glaringly obvious mistake is the
ods rtf file = 'xxxxxxx.rtf';
statement in the %do loop.
This means that the rtf file is reopened (and therefore overwritten) in every iteration of the %do loop.
Just as the ods rtf close comes after the %end, the ods rtf file= has to come before the %do.
And how will we solve your problem from that? That is obviously just a small part of the code at maximum as %do loops can't be in open code. No idea what cnt is, not defined, a call to a macro not shown. As I can't see what your doing, its even hard to show some possibilities. This is why we ask for test data - in the form of a datastep - and some working code, and an explanation of what you want out from it. What for instance does the log say? Have you put options mlogic mprint syblogen; on and looked at the values used in each macro call?
The glaringly obvious mistake is the
ods rtf file = 'xxxxxxx.rtf';
statement in the %do loop.
This means that the rtf file is reopened (and therefore overwritten) in every iteration of the %do loop.
Just as the ods rtf close comes after the %end, the ods rtf file= has to come before the %do.
@Hari2 wrote:
@Kurt_Bremser : Thank you So much. Its giving Output for all now. It is simple issue but Wasted my time for Long time.
But just a clarification, the same code is giving Output for all subjects when I write into PDF , That's the reason I did n't try to update the code. Please help me to understand what is the difference here between PDF & RTF in this case.
It might be because pdf is one of the so-called "Printer" destinations (means it writes to a stream that can pre-exist), while rtf is file-oriented from the beginning.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.