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

good night:

 

i have this table:

 

data have;
input Animal age weight;
cards;
1 11 10
1 21 10.2
1 31 10.21
1 41 10.22
1 45 10.45
1 50 10.6
2 43 11
2 45 11.3
2 49 11.35
2 60 11.3
2 65 12.2
2 70 12.5
2 76 12.65
2 80 13
2 95 14
2 105 16
3 25 10

 ;

 

and i need to obtain the mean of the observations, please note that the animal number 3 is alone, so i need to use this exac value to create a table like this:

 

Animal Weight_Avegare
1 10.28
2 12.53
3 10.00

 

Thank you very much

1 ACCEPTED SOLUTION

Accepted Solutions
jonatan_velarde
Pyrite | Level 9
the correct command is:

proc means data=have noprint;
class animal;
var weight;
output out=want1 mean(weight)=mean;
run;

proc sql;
create table want2 as
select animal, mean(weight) as mean_animal
from have
group by animal
order by animal;
quit;

Thank you very much

View solution in original post

4 REPLIES 4
Reeza
Super User
Use the CLASS or BY statement in proc means/univariate/summary or a PROC SQL.
Here's a sample of the two ways.

proc means data=have noprint;
class animal;
var weight;
output out=want1 mean(weight)=mean;
run;

proc sql;
create table want2 as
select animal, mean(animal) as mean_animal
from have
group by animal
order by animal;
quit;
jonatan_velarde
Pyrite | Level 9
Good ight and thank you for the answer, but unhappily did not work. i tested and i obtained:

Animal mean_animal
1 1
2 2
3 3
jonatan_velarde
Pyrite | Level 9
the correct command is:

proc means data=have noprint;
class animal;
var weight;
output out=want1 mean(weight)=mean;
run;

proc sql;
create table want2 as
select animal, mean(weight) as mean_animal
from have
group by animal
order by animal;
quit;

Thank you very much
Steelers_In_DC
Barite | Level 11

Here is a solution:

 

data have;
input Animal age weight;
cards;
1     11     10
1     21     10.2
1     31     10.21
1     41     10.22
1     45     10.45
1     50     10.6
2     43     11
2     45     11.3
2     49     11.35
2     60     11.3
2     65     12.2
2     70     12.5
2     76     12.65
2     80     13
2     95     14
2     105 16
3     25     10
;

proc sql;
create table want as
select animal,avg(weight) as Weight_Average
from have
group by animal;

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 724 views
  • 0 likes
  • 3 in conversation