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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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