The SAS Output Delivery System and reporting techniques

Trouble with setting calculated Column Header to reflect value of "Across" variable

Reply
Contributor
Posts: 31

Trouble with setting calculated Column Header to reflect value of "Across" variable

Have an issue that I can’t see to resolve.  I am using an across variable.  I have two columns which are sub totals of the across value.  I have a subtotal for FEMALEs and another subtotal for MALES which I call gtotal.   I want the subtotals to print the column header of “Total Female” Under the female header and the “Total Male” under Male header.  I can get the columns placed exactly where I want them.  But I don’t know how to place the descriptive title of Female or Male in the corresponding header. 

I was thinking to do with this with a compute statement and conditionally set the title in the Call define, but I have not been successful.  Do you have any suggestions??  Should I just contact Tech Support. I have attached the code as I cannot paste it for some reason! 

Attachment
SAS Super FREQ
Posts: 8,743

Re: Trouble with setting calculated Column Header to reflect value of "Across" variable


Hi, I'm having trouble visualizing what you mean when you say, "I want the subtotals to print the column header" If you have a variable that is a computed item under an ACROSS variable, you only have 1 item, possibly repeated as many times as you have ACROSS values. For example, in the code below, I have HEIGHT, WEIGHT and TOTAL "under" the SEX variable. Just as I cannot give two different labels to HEIGHT and WEIGHT, I cannot give two different labels to TOTAL. (See screenshot.)


  So, I'm not sure what exactly you are trying to accomplish. You could apply different labels to the 'F' and 'M' values for SEX with a user-defined format for the character values, but HEIGHT, WEIGHT and TOTAL, in my example will be displayed with the SAME label under each unique value of the ACROSS variable.

 

cynthia

ods html file='c:\temp\across_header.html' style=sasweb;

title;

   proc report data=sashelp.class nowd;

     column age sex,(height weight total);

     define age / group;

     define sex / across;

     define total / computed 'Computed Total';

     define height / sum;

     define weight / sum;

     compute total;

       _c4_ = _c2_ + _c3_;

       _c7_ = _c5_ + _c6_;

     endcomp;

   run;

ods html close;


across_headers_same.png
Contributor
Posts: 31

Re: Trouble with setting calculated Column Header to reflect value of "Across" variable

Sorry for not being clear!  I want the column header to state "Total Female" under the across female columns and "Total Male" under the male across columns.  I just want the verbage in the header display either Female or Male for this calculated column.

My resolution will be to pre-total female and male and feed those results to the PROC REPORT.  Then I should be able to label the header titles whatever I wish.  However, I didn't want to have to do that, since it seemed so easy to use the calculated columns.

As always, thank you so much for your quick response

Contributor
Posts: 27

Re: Trouble with setting calculated Column Header to reflect value of "Across" variable

proc format ;
value $gen "F" = "TOTAL FEMALE"
           "M" = "TOTAL MALE";
run;


proc report data=sashelp.class nowd;

     column age sex,(height weight total);

     define age / group;

     define sex / across;

     define total / computed 'Computed Total';

     define height / sum;

     define weight / sum;

     compute total;

       _c4_ = _c2_ + _c3_;

       _c7_ = _c5_ + _c6_;

     endcomp;
format sex $gen.;

   run;

Ask a Question
Discussion stats
  • 3 replies
  • 357 views
  • 3 likes
  • 3 in conversation