The SAS Output Delivery System and reporting techniques

re: #byval in header

Accepted Solution Solved
Reply
Regular Contributor
Posts: 247
Accepted Solution

re: #byval in header

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;


Accepted Solutions
Solution
‎12-28-2016 09:26 PM
SAS Super FREQ
Posts: 9,370

Re: re: #byval in header

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


All Replies
Solution
‎12-28-2016 09:26 PM
SAS Super FREQ
Posts: 9,370

Re: re: #byval in header

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;

 

Occasional Contributor
Posts: 5

Re: re: #byval in header

Posted in reply to Cynthia_sas

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

SAS Super FREQ
Posts: 9,370

Re: re: #byval in header

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.
Esteemed Advisor
Posts: 5,535

Re: re: #byval in header

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
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 1008 views
  • 0 likes
  • 4 in conversation