BookmarkSubscribeRSS Feed
hnam
Calcite | Level 5

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

3 REPLIES 3
Cynthia_sas
SAS Super FREQ

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;

hnam
Calcite | Level 5

Thanks Cynthia.

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

Hari

Cynthia_sas
SAS Super FREQ

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 823 views
  • 0 likes
  • 2 in conversation