BookmarkSubscribeRSS Feed
finans_sas
Quartz | Level 8

Hi Everybody,

I have the following program that runs a macro for two different periods and two different models. The issue is that each time the loop runs through the macro, a new RTF output gets generated. I was wondering if there was a way to generate a single RTF document with titles for each output (for each per and m pairs). I was suggested earlier that I put "ods rtf close" after the second %end, but SAS got stuck (runs forever) after this change. I was also suggested to add "ODS RTF startpage=now" where I identify the location of the RFT output. When I do that, SAS keeps crashing.

I attached the sample sas dataset to this inquiry. Thank you for your time and help in advance.

%macro twostep;

    %do per=1 %to 2;

        %do m=1 %to 2;

%let model1= vret_msa mktrf100;    *model specification;

%let model2= vret_msa mktrf100 ind_ret;

data perret&per; set a14_samplesas; if period=&per;

proc sort data=perret&per; by permno myear; run;

ods listing close;

ods output parameterestimates=pe&per&m;

proc reg data=perret&per;

by permno;

    model ereturn_i =&&model&m;

run;

quit;

ods listing;

ods rtf file="C:\SAS\twostep\period&per model&m.rtf" style=journal;

proc means data=pe&per&m mean std t probt;

var estimate; class variable;

run;

*By variable by variable, it calculates the mean, standard deviation, t-statistics and p-value of the

coefficient estimates;

proc sort data=pe&per&m; by variable; run;

ods rtf close;

%end;

    %end;

%mend;

%twostep;

5 REPLIES 5
ballardw
Super User

You just need to add the appropriate TITLE statements in the code body. For example just before the Proc Reg or Means something like:

title "This is the title for PER= &Per M= &m";

To create a single RTF or other ODS output file type put all of the output generating code within a single ODS "sandwich".

Since you are running multiple nested loops, probably what you want is to move ODS RTF file = to before the %do Per = loop and have the ODS RTF close after the associated %end. Since the ODS RTF precedes the macor then you'd likely want a fixed file name.


finans_sas
Quartz | Level 8

Thank you, ballardw. I followed your suggestions, and the macro ended up generating one single output. However, in the original code that I posted, ODS output is whatever comes out of proc means statement. On the other hand, after the changes that I made, ODS output gives me a output for each permno (regression ids) in addition to the result of proc means operation, which is in hundreds of pages. I am not sure how to go from here. I would deeply appreciate your input.

ballardw
Super User

I was afraid that would happen. I generally build all datasets outside of output and then have another loop or call to create the output file..

So take the ODS RTF and the Proc means out side of the current loops you have.

Then add the ODS RTF sandwich around a second loop of similar structure that just runs the proc means part.

ods rtf file="your name here";

%do per=1 %to 2; 

        %do m=1 %to 2;

          title "Output for Per=&per and M=&m";

          proc means data=pe&per&m mean std t probt;

          var estimate; class variable;

          run;

     %end;

%end;

ods rtf close;

jakarman
Barite | Level 11

use of proc document? SAS(R) 9.3 Output Delivery System: User's Guide, Second Edition

---->-- ja karman --<-----

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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