Solved
Contributor
Posts: 41

# Summary statistics on rows, Categories in Columns

I have a dataset with characteristics of households.  I want to produce a table similar to the one in the picture below.  The relevant point is that the columns are a categorical variable, while the rows are summary statistics.  It's easy to do the opposite in TABULATE or REPORT, putting the categories on the rows and the summary statistics in the columns.  I could write the output to a dataset, transpose it, and then print it.  I could compute the statistics with PROC SUMMARY and then do something similar.  I'm hoping to find a less complicated solution.

Is there some way to produce what I want in one step?

.

Accepted Solutions
Solution
‎05-27-2016 01:48 PM
Super User
Posts: 6,629

## Re: Summary statistics on rows, Categories in Columns

Just for discussion purposes, then, how about:

proc tabulate data=have;

class household_type;

var ichil numpeople mild moderate severe;

tables (numpeople ichil) * (sum mean) (severe moderate mild) * sum='Households',

all household_type;

run;

This is just to get the structure right.  We can always worry about the labeling later.

I can't test the code right now, so you may need to debug it a little.

All Replies
Super User
Posts: 6,629

## Re: Summary statistics on rows, Categories in Columns

[ Edited ]

PROC TABULATE does that easily enough.

What are the variable names?

Contributor
Posts: 41

## Re: Summary statistics on rows, Categories in Columns

Number of persons in household is NUMPEOPLE

Number of children in household is ICHIL

The problem measures are flags.  For discussion purposes, call them SEVERE, MODERATE, and NONE.

Super User
Posts: 13,317

## Re: Summary statistics on rows, Categories in Columns

If you get what you want with tabulate but need to transpose the output then just change the order in the TABLE statement.

You likey currently have something like

Table Classvar1 Classvar2 Classvar3 ,

Var1*(n mean)  Var2*(n mean)

;

just change the order to

Table Var1*(n mean)  Var2*(n mean) ,

Classvar1 Classvar2 Classvar3

;

Solution
‎05-27-2016 01:48 PM
Super User
Posts: 6,629

## Re: Summary statistics on rows, Categories in Columns

Just for discussion purposes, then, how about:

proc tabulate data=have;

class household_type;

var ichil numpeople mild moderate severe;

tables (numpeople ichil) * (sum mean) (severe moderate mild) * sum='Households',

all household_type;

run;

This is just to get the structure right.  We can always worry about the labeling later.

I can't test the code right now, so you may need to debug it a little.

Contributor
Posts: 41

## Re: Summary statistics on rows, Categories in Columns

Thanks to everyone who replied.  I'm glad the answer was so simple.

--Dav

🔒 This topic is solved and locked.