BookmarkSubscribeRSS Feed
craig159753
Quartz | Level 8

Hi,

 

I am using the PROC REPORT procedure with the #BYVAL dynamic function. The #BYVAL function works flawlessly in a TITLE statement, be in the output window in SAS or the PDF, RTF or HTML output. However, the #BYVAL function when used within a column header only works within the SAS output window and not the PDF, RFT or HTML output.

 

Below is same sample code which you should be able to copy and paste into your own SAS session:

data input_data;
    do byvariable1 = 1 to 2 by 1;
        col1 = "XX (XX.X)";
        col2 = "XX (XX.X)";
        if byvariable1=1 then byvariable2 = "Female";
        else if byvariable1=2 then byvariable2 = "Male";

        if byvariable1=1 then do;
            header1 = "Some Text 1";
            header2 = "Some Other Text 1";
        end;
        else if byvariable1=2 then do;
            header1 = "Some Text 2";
            header2 = "Some Other Text 2";
        end;
        output;
    end;
run;


ods listing close;
ods pdf file="%sysfunc(getoption(work))\test.pdf" nogtitle nogfootnote;

    proc report data = input_data split="|" nowd missing;
        column col1 col2;
        by byvariable1 byvariable2 header1 header2;

        define col1 / display "Header 1 #byval3";
        define col2 / display "Header 2 #byval4";
        
        title1 "#byval2";
    run;

ods pdf close;
ods listing;

Notice the COL1 and COL2 variables within the DEFINE statement within the PROC REPORT. I have included #BYVAL3 and #BYVAL4 in the column headers. Now, these do resolve to the correct values within the SAS output window. however, when I open the PDF document they simply say #BYVAL3 and #BYVAL4. Oddly though the #BYVAL2 line within the TITLE statement does appear correctly in both the SAS output window and the PDF output.

 

I am running SAS EG guide 7.15 on Windows 10.

1 REPLY 1
craig159753
Quartz | Level 8

I could not get the #BYVAL function to work. But I did find a solution using a different method, the ACROSS statement, see the code below.

 

proc report data = input_data split="|" nowd missing;
        column blank col1,header1 col2,header2;
        by byvariable1 byvariable2;

        define blank / display "Statistics";

        define header1 / across " ";
        define col1 / display " ";

        define header2 / across " ";
        define col2 / display " ";
        
        title1 "#byval2";
    run;

This code ensures the values in the HEADER1 and HEADER2 variables appear as the column headers for the COL1 and COL2 variables respectively.

If you require multiple columns, e.g. COL3, COL4 to share the same header text, this method also works, however the syntax does change slightly, see the code below.

proc report data = input_data split="|" nowd missing;
        column blank header1,(col1 col2) header2,(col3 col4);
        by byvariable1 byvariable2;

        define blank / display "Statistics";

        define header1 / across " ";
        define col1 / display " ";
        define col2 / display " ";

        define header2 / across " ";
        define col3 / display " ";
        define col4 / display " ";
        
        title1 "#byval2";
    run;

I am still unsure why the #BYVAL does not work, and will leave this post unresolved until I figure out why.

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
  • 1 reply
  • 1655 views
  • 0 likes
  • 1 in conversation