BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Hari2
Quartz | Level 8

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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?

Hari2
Quartz | Level 8
Thanks RW9.

I completely agree with what you said, I just wrote in Urgency. Going forward, I will definitely post all details .

Thanks for your support.
Kurt_Bremser
Super User

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
Quartz | Level 8
@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.
Kurt_Bremser
Super User

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

See https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.4&docsetId=odsug&docsetTarget=p1n357...

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
  • 5 replies
  • 1014 views
  • 3 likes
  • 3 in conversation