Help using Base SAS procedures

Multiple Fields As Columns

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 13
Accepted Solution

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: 11,343

Re: Multiple Fields As Columns

Posted in reply to CraigKaercher

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.

View solution in original post


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

Re: Multiple Fields As Columns

Posted in reply to CraigKaercher

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: 11,343

Re: Multiple Fields As Columns

Posted in reply to CraigKaercher

If they are questions please post them as questions, Even simple ones. Discussions can't get marked as answered. If a question has been adequately answered then the rest of us, unless curious, know that additional comment is not required and we can spend time on the items that need help.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 188 views
  • 0 likes
  • 2 in conversation