Table summary and operations

Solved
Frequent Contributor
Posts: 115

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
Super User
Posts: 9,853

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;```

All Replies
Solution
‎04-18-2016 08:24 AM
Super User
Posts: 9,853

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 and locked.