BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
CraigKaercher
Calcite | Level 5

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;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

3 REPLIES 3
ballardw
Super User

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.

CraigKaercher
Calcite | Level 5

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

ballardw
Super User

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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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