BookmarkSubscribeRSS Feed
JohnSAScom
Quartz | Level 8

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;
 
3 REPLIES 3
ballardw
Super User

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

JohnSAScom
Quartz | Level 8

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

 

 

ballardw
Super User

@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.

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 1077 views
  • 0 likes
  • 2 in conversation