Help using Base SAS procedures

Proc Tabulate output control

Reply
Occasional Contributor
Posts: 7

Proc Tabulate output control

This may be easy, but I could not find a solution for this.  This may be very easy, but I am trying to find a solution to generate a table like

LabelNMeanStd Dev

No of Cigars Smoked

No of Years Smoked

No of Drinks per week

I used a code as below:

title 'Table 3. Analysis of Smoking History and Alcohol Consumption';
proc tabulate data=tab3v1;
var smkyncig smkyyears alcyndpw;
table smkyncig='No of Cigars Smoked'*(n mean stddev)
smkyyears='No of Years Smoked'*(n mean stddev)
alcyndpw='No of Drinks Per Week'*(n mean stddev) ;
run;

But I am getting a horizontal output. I wanted to get a vertical one.

Thanks in advance

Hari

SAS Super FREQ
Posts: 8,743

Re: Proc Tabulate output control

Hi:

  PROC TABULATE uses the TABLE operator of a comma (,) to create more than one dimension. in addition the space operator says to stack tables together. And the asterisk operator says to nest or cross items together. So you need to ask for your 3 analysis variables to be in the ROW dimension and your statistics to be in the COLUMN dimension without using an asterisk operator.

  This type of TABLE statement would be something like:

TABLE var1 var2 var3,

      stat1 stat2 stat3 /box='Label';

  In the above example, VAR1, VAR2 and VAR3 would each get a separate ROW on the final TABLE (such as you show). And then each statistic would be arranged in a separate COLUMN (such as you show). The * operator tells TABULATE to cross or NEST items and statistics, so, without any commas in the TABLE statement, everything should have appeared in the COLUMN dimension, which probably looked like 1 horizontal row with a bunch of columns, so that you'd see N MEAN and STDDEV under each of your labels. (which is not what you want)

  An alternate TABULATE program that does NOT use the asterisk operator is shown below. I think it will come closer to what you want.

cynthia

ods html file='c:\temp\tab3v1_alt.html';

title 'Table 3. Analysis of Smoking History and Alcohol Consumption';

proc tabulate data=tab3v1;

  var smkyncig smkyyears alcyndpw;

  table smkyncig='No of Cigars Smoked' smkyyears='No of Years Smoked' alcyndpw='No of Drinks Per Week',

       (n mean stddev) /box="Label";

run;

ods html close;

Occasional Contributor
Posts: 7

Re: Proc Tabulate output control

Thanks Cynthia.

It seems that stat1 stat2 stat3 is not recognized by sas. Do I write n mean stddev instead?

Hari

SAS Super FREQ
Posts: 8,743

Proc Tabulate output control

Yes, just as you would write your variable names instead of VAR1, VAR2 and VAR3, you would put your statistics in place of STAT1, STAT2 and STAT3. The names I used were just placeholders. The actual code I pasted into the answer (under my name) should be what you follow/use.

cynthia

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