## Multiple Fields As Columns

Solved
Occasional Contributor
Posts: 13

# Multiple Fields As Columns

This has to be a really simple question but I have been looking through examples and cannot find a good one.  Here is my input:

DATA LISTINP;

infile "~/Pgm1ExtInp.txt";

INPUT ID HEIGHT WEIGHT GENDER \$ AGE;

RUN;

I want to sum HEIGHT and WEIGHT as columns in the resulting table so the result would look something like:

GENDER            HEIGHT         WEIGHT

SUM              SUM

Male                     210                 650

Female                 190                 600

I am trying to use the PROC TABULATE but it is not working.  There seem to be at least a hundred examples of how I could break up HEIGHT by GENDER across HEIGHT values and the same for WEIGHT but none where I can just get those values as columns.  If this were a SQL statement it would be:

SELECT GENDER, SUM(HEIGHT), SUM(WEIGHT)

FROM LISTINP

GROUP BY GENDER

ORDER BY GENDER;

I have to think the answer looks something like:

PROC TABULATE DATA=LISTINP;

TITLE 'Summary of Height and Weight';

class GENDER;

var HEIGHT, WEIGHT;

table GENDER , HEIGHT * WEIGHT;

But that doesn't work.  All help appreciated.  Thanks.

RUN;

Accepted Solutions
Solution
‎10-01-2014 05:42 PM
Super User
Posts: 13,498

## Re: Multiple Fields As Columns

PROC TABULATE DATA=LISTINP;

TITLE 'Summary of Height and Weight';

class GENDER;

var HEIGHT WEIGHT;

table GENDER , (HEIGHT  WEIGHT)*sum;

run;

Or: height*sum weight*sum; the statistic isn't formally needed as defaults to sum for VAR but I prefer to explicitly state the statistic so I can debug easier.

Your request with height*weight is going to attempt to nest (cross) height and weight.

Also, remove the comma from the VAR statement.

All Replies
Solution
‎10-01-2014 05:42 PM
Super User
Posts: 13,498

## Re: Multiple Fields As Columns

PROC TABULATE DATA=LISTINP;

TITLE 'Summary of Height and Weight';

class GENDER;

var HEIGHT WEIGHT;

table GENDER , (HEIGHT  WEIGHT)*sum;

run;

Or: height*sum weight*sum; the statistic isn't formally needed as defaults to sum for VAR but I prefer to explicitly state the statistic so I can debug easier.

Your request with height*weight is going to attempt to nest (cross) height and weight.

Also, remove the comma from the VAR statement.

Occasional Contributor
Posts: 13

## Re: Multiple Fields As Columns

Thank You!  That does it.  You will probably be seeing a number of simple questions from me disguised as discussions soon.  Thanks again.

Super User
Posts: 13,498