I'm using #BYVAL in a footnote statement in 9.4M3. Looks like the footnote is reporting the value of the next by-group rather than the current by group. It works as expected in the title statement.
proc sort data=sashelp.class out=class;
by sex;
run;
options nobyline;
proc report data=class nowd;
by sex;
title1 "below is print out of: #BYVAL1";
footnote1 "above is print out of: #BYVAL1";;
run;
Looks like same issue as:
I tried in 9.3 and get the same result.
Does this mean that #BYVAL doesn't work well for footnotes?
According to the documentation, the #BYVAL, #BYVAR etc. are only available for the TITLE statement, but not in the FOOTNOTE statement.
See here
So works as documented.
One can argue, that one should get some sort of warning when using the #BY... in a FOOTNOTE statement.
Just to add to the merriment, when I test your program (Unix/Linux), I'm getting a footnote that includes the characters "#BYVAL1" without the value of the variable.
According to the documentation, the #BYVAL, #BYVAR etc. are only available for the TITLE statement, but not in the FOOTNOTE statement.
See here
So works as documented.
One can argue, that one should get some sort of warning when using the #BY... in a FOOTNOTE statement.
Thanks @BrunoMueller. That's an unfortunate surprise. I hadn't before thought about possible differences between TITLE statements and FOOTNOTE statements.
It interesting that in SAS/GRAPH, titles and footnotes are documented together http://support.sas.com/documentation/cdl/en/graphref/69717/HTML/default/viewer.htm#n19y35ila5aaysn1q..., and from the related thread https://communities.sas.com/t5/SAS-GRAPH-and-ODS-Graphics/SG-ODS-RTF-BODYTITLE-BYVAL-in-FOOTNOTE-sta... it looks like using #BYVAL in a SAS/GRAPH or SG plot footnote works, as long as you use GFOOTNOTE so that footnote is part of the graph. Maybe I'll put in a idea submisssion to get #BYVAL working in SAS BASE footnotes.
I haven't used #BYVAL much. But seems like often when I try, I end up backing away from it and resort to writing my own macro looping. Beause I ended up wanting to use that #BYVAL to somewhere like a footnote or a table of contents link, or a file name, or .... so &BYVAL becomes more flexible. But if I were still in the role of making statistical reports for internal users that didn't have to be pretty, I'm sure I would use #BYVAL more often.
@Quentin: If you don't mind deleting two pages, the following will produce the desired result:
proc sort data=sashelp.class out=class; by sex; run; data class; set class; by sex; x=0; if last.sex then do; output; x=1; output; end; else output; run; options nobyline; proc report data=class nowd; by sex x; title1 "below is print out of: #BYVAL1"; footnote1 "above is print out of: #BYVAL1"; run;
Art, CEO, AnalystFinder.com
Thanks @art297, but in my setting of storted process making web reports, it isn't feasible to delete the extra pages.
If you need this information in the footnote statement, then I suggest you have a look at programming pattern described by @ChrisHemedinger, see his blog entries
http://blogs.sas.com/content/sasdummy/2012/03/20/sas-program-by-processing/
and
http://blogs.sas.com/content/sasdummy/2012/03/23/improving-on-a-sas-programming-pattern/
Thanks again @BrunoMueller. Yes, that's the sort of macro looping I generally use. But I thought for this project I might be in a setting where I could use the BY statement and benefit from the efficiency, so wanted to give it a shot. For now, I just moved by footnote to a subtitle to get it working. I'm sure by the end it will be refactored into macro looping like Chris showed.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.