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

Hi....is it possible to use the #byval feature in the header when creating an rtf file? The following code works but instead of having a title I would like the title as a header on each table....Thanks.

 

ods listing close;

 

options nodate;

title;

options nobyline;

ods rtf FILE="%sysfunc(pathname(project))\report.rtf";

 

title "#byval(monthnum) &year";

proc report data=summary center nowd

        style(report)=[font=(Arial, 8pt)]

        style(column)=[font=(Arial, 8pt) cellheight=1in cellwidth=1in]

        style(header)=[font=(Arial, 10pt) font_weight=bold]

        split='*';

   by monthnum;

   format monthnum nlstrmon.;

   column ((weeknum Sun Mon Tue Wed Thu Fri Sat));

   define weeknum / group order=internal noprint;

   compute Sun;

           call define(_col_, "style","style={background=lightgrey}");

           endcomp;

     compute Sat;

           call define(_col_, "style","style={background=lightgrey}");

           endcomp;

run;

ods rtf close;

options byline;

title;

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Hi:

  You can get something like this, using PROC REPORT and the PAGE option -- use it with or without BY variables -- if you don't want the title, then take out the BY statement and take out the TITLE.

 

  But you will need to understand the COMPUTE BEFORE and using GROUP or ORDER variables as "page" variables.

 

cynthia

use_compute_before.png

 

with this code using SASHELP.PRDSALE (you'll have to adapt the code to your data):


proc means data=sashelp.prdsale nway n sum;
  class year quarter country region;
  var actual;
  output out=work.mnout n=cnt sum=actsum mean=actmean;
run;

proc print data=mnout;
run;
ods _all_ close;

proc sort data=mnout;
by year quarter country region;
run;
  
options nobyline;
    
ods rtf FILE="c:\temp\use_page_report.rtf";

title "Title: #byval1 and Qtr #byval2";

proc report data=mnout center nowd
        style(report)=[font=(Arial, 8pt)]
        style(column)=[font=(Arial, 8pt)]
		style(lines)=Header{font=(Arial, 10pt) font_weight=bold}
        style(header)=[font=(Arial, 10pt) font_weight=bold]
        split='*';
   by year quarter;
   column (year quarter country region cnt actsum actmean);
   define year / group page noprint;
   define quarter / group page noprint;
   define country / order;
   define region / order;
   define cnt / 'Count';
   define actsum / sum;
   define actmean / 'Mean';
   break before year / page;
   compute before _page_;
     pgstr = catx(' ','Year:',year,'--', 'Quarter',quarter);
	 line pgstr $varying100.;
   endcomp;
run;

ods rtf close;
options byline;
title;

 

View solution in original post

4 REPLIES 4
Cynthia_sas
SAS Super FREQ

Hi:

  You can get something like this, using PROC REPORT and the PAGE option -- use it with or without BY variables -- if you don't want the title, then take out the BY statement and take out the TITLE.

 

  But you will need to understand the COMPUTE BEFORE and using GROUP or ORDER variables as "page" variables.

 

cynthia

use_compute_before.png

 

with this code using SASHELP.PRDSALE (you'll have to adapt the code to your data):


proc means data=sashelp.prdsale nway n sum;
  class year quarter country region;
  var actual;
  output out=work.mnout n=cnt sum=actsum mean=actmean;
run;

proc print data=mnout;
run;
ods _all_ close;

proc sort data=mnout;
by year quarter country region;
run;
  
options nobyline;
    
ods rtf FILE="c:\temp\use_page_report.rtf";

title "Title: #byval1 and Qtr #byval2";

proc report data=mnout center nowd
        style(report)=[font=(Arial, 8pt)]
        style(column)=[font=(Arial, 8pt)]
		style(lines)=Header{font=(Arial, 10pt) font_weight=bold}
        style(header)=[font=(Arial, 10pt) font_weight=bold]
        split='*';
   by year quarter;
   column (year quarter country region cnt actsum actmean);
   define year / group page noprint;
   define quarter / group page noprint;
   define country / order;
   define region / order;
   define cnt / 'Count';
   define actsum / sum;
   define actmean / 'Mean';
   break before year / page;
   compute before _page_;
     pgstr = catx(' ','Year:',year,'--', 'Quarter',quarter);
	 line pgstr $varying100.;
   endcomp;
run;

ods rtf close;
options byline;
title;

 

abcrandy
Fluorite | Level 6

How would you do this if you wanted to see the month name?

Cynthia_sas
SAS Super FREQ
Hi:
Well, this example did not have MONTH, since it used YEAR and QUARTER. But I'd probably use a date with a SAS format or a format like MONNAME if all I had was a month value of 1-12.
Cynthia

ps...next time, start a new post and refer back to this 2 year old posting. Nobody can see the older tracks.
PGStats
Opal | Level 21

It should be easier than this. Please support the Ballot idea:

 

https://communities.sas.com/t5/SASware-Ballot-Ideas/Support-BYVARn-and-BYVALn-in-more-places/idi-p/2...

PG

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 7312 views
  • 0 likes
  • 4 in conversation