Hi...I can't seem to get the #byval() to work as part of the header. I am trying to put the name of the month as part of the header. If I include the variable "Month" as a column variable then the name of the month appears inside each table as ouput. I have included the code below as well as the log out put.Thanks.
ODS OUTPUT;
ODS GRAPHICS ON;
ODS LISTING CLOSE;
OPTIONS NODATE;
TITLE;
options nobyline;
ODS rtf FILE="%sysfunc(pathname(project))\&year Calendar.rtf";
title "&year";
proc report data=notes_calendar_&year center nowd
style(report)=[font=(Arial, 7pt)]
style(column)=[font=(Arial, 7pt) cellheight=1in cellwidth=1in]
style(header)=[font=(Arial, 8pt) font_weight=bold]
split='*';
by month notsorted;
column ("#byval(month)"(weeknum Sun Mon Tue Wed Thu Fri Sat _dummy));
define weeknum / order order=internal noprint;
define month / display across '' center order=data;
define _dummy / computed noprint;
compute _dummy / char length=32;
array sugus{*} Mon Tue Wed Thu Fri;
do i = 1 to dim(sugus);
if length( strip(sugus{i}) ) > 3 then do;
call define(vname(sugus{i}), "style", "style={background=cx52cc62}");
end;
end;
endcomp;
compute Sun;
call define(_col_, "style", "style={background=graycc}");
endcomp;
compute Sat;
call define(_col_, "style", "style={background=graycc}");
endcomp;
run;
ODS rtf close;
options byline;
title;
LOG OUT:
455 ODS OUTPUT;
456 ODS GRAPHICS ON;
457 ODS LISTING CLOSE;
458
459 OPTIONS NODATE;
460 TITLE;
461 options nobyline;
462 ODS rtf FILE="%sysfunc(pathname(project))\&year Calendar.rtf";
NOTE: Writing RTF Body file: U:\Data Output\2016 Calendar.rtf
463
464 title "&year";
NOTE: PROCEDURE DATASETS used (Total process time):
real time 0.25 seconds
cpu time 0.07 seconds
465 proc report data=notes_calendar_&year center nowd
466 style(report)=[font=(Arial, 7pt)]
467 style(column)=[font=(Arial, 7pt) cellheight=1in cellwidth=1in]
468 style(header)=[font=(Arial, 8pt) font_weight=bold]
469 split='*';
470 by month notsorted;
471 column ("#byval(month)"(weeknum Sun Mon Tue Wed Thu Fri Sat _dummy));
472 define weeknum / order order=internal noprint;
473 define month / display across '' center order=data;
474 define _dummy / computed noprint;
475 compute _dummy / char length=32;
476 array sugus{*} Mon Tue Wed Thu Fri;
477
478 do i = 1 to dim(sugus);
14 The SAS System
479 if length( strip(sugus{i}) ) > 3 then do;
480 call define(vname(sugus{i}), "style", "style={background=cx52cc62}");
481 end;
482 end;
483 endcomp;
484 compute Sun;
485 call define(_col_, "style", "style={background=graycc}");
486 endcomp;
487 compute Sat;
488 call define(_col_, "style", "style={background=graycc}");
489 endcomp;
490 run;
WARNING: month is not in the report definition.
NOTE: There were 63 observations read from the data set WORK.NOTES_CALENDAR_2016.
NOTE: PROCEDURE REPORT used (Total process time):
real time 0.39 seconds
cpu time 0.32 seconds
491 ODS rtf close;
492 options byline;
493 title;
494
495 GOPTIONS NOACCESSIBLE;
496 %LET _CLIENTTASKLABEL=;
497 %LET _CLIENTPROCESSFLOWNAME=;
498 %LET _CLIENTPROJECTPATH=;
499 %LET _CLIENTPROJECTNAME=;
500 %LET _SASPROGRAMFILE=;
501
502 ;*';*";*/;quit;run;
503 ODS _ALL_ CLOSE;
504
505
506 QUIT; RUN;
By group variable information is put in to titles and footnotes not into variable labels, i.e.:
by month notsorted;
title '#byval1';
If you need month as an overiding column heading then you would need to do it differently:
proc sort data=have out=loop nodupkey; by year month; run; data _null_; set loop; call execute('title "'||strip(year)||'"; proc report data=have...; where year="'||strip(year)||'" and month="'||strip(month)||'"; column ("''||strip(month)||'" weeknum sun mon...); run;); run;
This will generate a proc report for each year/month with the relevant text in title/month.
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.