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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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