Help using Base SAS procedures

PROC TABULATE and sub-headings

Reply
Contributor
Posts: 54

PROC TABULATE and sub-headings

This table contains headers and sub-headers. 

 

proc tabulate data=DAT1;
  class EGA;
  classlev EGA;
  var n72c n72d vg1 n1 n82 n12 n42 n72c vg2 vg3 vg4 n2 n3 n4;
  table EGA,
        sum="&header1"*(n72c="P1 %" n72d="&header5 P %" vg1="&header3" n1="&header4"*f=form1.)
        sum="&header2"*
             (
             n82="P1 %" n12="P2 %" n42="P3 %" n72c="P4 %" vg2="&header3 Range 2" vg3="&header3 Range 3" vg4="&header3 Range 4" n2="&header4 Range n2"*f=form1. n3="&header4 Range n3"*f=form1. n4="&header4 Range n4"*f=form1.
             );
run;
 
Instead of repeating Header3 3 times for Ranges 2-4, I would like to have Header3 appear once over Ranges 2-4.  Similarly, I would also like to have Header 4 appear only once over the Ranges n2 - n4.  How would I do this?  My attempt below does not work.   It tells me that it does not know the type of Header3. 
 
proc tabulate data=DAT1;
  class EGA;
  classlev EGA;
  var n72c n72d vg1 n1 n82 n12 n42 n72c vg2 vg3 vg4 n2 n3 n4;
  table EGA,
        sum="&header1"*(n72c="P1 %" n72d="&header5 P %" vg1="&header3" n1="&header4"*f=form1.)
        sum="&header2"*
             (
             n82="P1 %" n12="P2 %" n42="P3 %" n72c="P4 %"
             "&header3"*
                  (
                  vg2="Range 2" vg3="Range 3" vg4="Range 4"
                  )
                  n2="&header4 Range n2"*f=form1. n3="&header4 Range n3"*f=form1. n4="&header4 Range n4"*f=form1.
             );
run;
 
Super User
Posts: 13,583

Re: PROC TABULATE and sub-headings

Posted in reply to JohnSAScom

You really should show what your table should look like. Descriptions of moving things isn't the easiest without examples.

 

If you are attempting to create spanning headers inside the body of Proc Tabulate output I think you may be out of luck. The only thing Tabulate wants to "span" over multiple columns or rows are Class variables. Since the variables you are calling "headers" are basically the labels of analysis variables that is not going to be easy. You don't mention it but I suspect you getting an error message like:

ERROR: There are multiple analysis variables associated with a single table cell in the following
       nesting

which is the effect of having two or more VAR variables nested.

 

 

What I think you are describing may be possible if you summarize the data first then use the Report Writing Interface which allows creating interesting tables from a data step.

Or possible involves additional variables and/or steps and semi-wicked data step code prior to proc tabulate. But with out data or an actual desired appearn

Contributor
Posts: 54

Re: PROC TABULATE and sub-headings

The table headers are attached to this post, if this helps. 

 

 

Super User
Posts: 13,583

Re: PROC TABULATE and sub-headings

Posted in reply to JohnSAScom

JohnSAScom wrote:

The table headers are attached to this post, if this helps. 

 

 


Is that what you are currently getting or what you want? I have to assume is what you are currently getting.

 

If you want header3 or header4 to span then you will have to do something like create a new variable for each  to use as a class variable, have a single value of your header text for that variable and suppress the label of that variable with the classvar=' '. Then you will have to modify the table statement so that you have

  header3classvar =' '*(vg2 vg3 vg4) header4classvar=' '*(n2 n3 n4) or similar

 

The class variables used for spanning would NOT be used in the other position (most likely) that you show header3 and header4 text.

 

Ask a Question
Discussion stats
  • 3 replies
  • 163 views
  • 0 likes
  • 2 in conversation