Table summary and operations

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 103
Accepted Solution

Table summary and operations

Hi SAS friends:

 

i have this tabla:

 

HORSE RUN WEIGHT PILLS URINE
23 1 23 1 0.3
23 2 22 2 0.4
23 2 25 1 0.1
23 1 34 1 0.6
23 3 23 2 0.3

 

I need to calculate:

 

a) Total RUNs for HORSE

b) Mean weight by run (TOTAL RUN / MEAN WEIGHT)

c) Urine production for pill taked (TOTAL URINE / TOTAL PILLS)

d) mean of urine produced by run (mean of run / mean of urine).

 

Thank you very much


Accepted Solutions
Solution
‎04-18-2016 08:24 AM
Esteemed Advisor
Esteemed Advisor
Posts: 7,203

Re: Table summary and operations

Well, am not typing the test data in so this is untested (post data as a datastep if you like tested code):

proc sql;
  create table WANT as
  select   HORSE,
           sum(RUN) as TOTAL_RUN,
           mean(WEIGHT) / sum(RUN) as MEAN_WEIGHT,
           sum(URINE) / sum(PILLS) as URINE_PROD,
           CALCULATED MEAN_WEIGHT / CALCULATED URINE_PROD
  from     HAVE
  group by HORSE;
quit;

View solution in original post


All Replies
Solution
‎04-18-2016 08:24 AM
Esteemed Advisor
Esteemed Advisor
Posts: 7,203

Re: Table summary and operations

Well, am not typing the test data in so this is untested (post data as a datastep if you like tested code):

proc sql;
  create table WANT as
  select   HORSE,
           sum(RUN) as TOTAL_RUN,
           mean(WEIGHT) / sum(RUN) as MEAN_WEIGHT,
           sum(URINE) / sum(PILLS) as URINE_PROD,
           CALCULATED MEAN_WEIGHT / CALCULATED URINE_PROD
  from     HAVE
  group by HORSE;
quit;
☑ This topic is SOLVED.

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

Discussion stats
  • 1 reply
  • 236 views
  • 0 likes
  • 2 in conversation