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

Hello,

I have experiments with multiple plants that make up one plot, and plots are treated as experimental units within blocks. I typically use excel to calculate the mean of the plants within a plot, and then transfer those values to a new sheet to load into SAS and analyze. However, I want to use SAS to perform this step instead (SAS 9.4). For an example, this is a sample dataset with three plots (A, B, and C) each having 4 plants with a measurement (score). Then there are three blocks. 

data sample;
input block line$ plant score;
cards;
1 A 1 3
1 A 2 2
1 A 3 4
1 A 4 3
1 B 1 4
1 B 2 3
1 B 3 5
1 B 4 4
1 C 1 2
1 C 2 2
1 C 3 3
1 C 4 2
2 A 1 4
2 A 2 5
2 A 3 5
2 A 4 5
2 B 1 3
2 B 2 2
2 B 3 3
2 B 4 3
2 C 1 3
2 C 2 2
2 C 3 2
2 C 4 2
3 A 1 5
3 A 2 6
3 A 3 6
3 A 4 5
3 B 1 4
3 B 2 3
3 B 3 4
3 B 4 2
3 C 1 2
3 C 2 2
3 C 3 3
3 C 4 2
;
run;

 

So I want a dataset now with average values for each A, B, or C within each block that I can then use for analysis. I've found somewhat similar examples using proc sql or proc means, but I get errors when I try to implement. For example:

proc sql;
create table average as
select *, mean(score) as average_score
from sample
by block
where line between 'A' and 'A'
and plant between 1 and 4;
quit;

and this didn't work, the error message said ERROR 78-322: Expecting a ','. so I know I'm missing something.... this seems like such a simple thing, I know there must be an answer. Any help will be greatly appreciated!! Thank you so much!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

proc sql;
create table average as
select *, mean(score) as average_score
from sample
group by block, line
;
quit;

View solution in original post

3 REPLIES 3
Reeza
Super User

Here are two fully worked methods, see if you can incorporate one with your data.

 

The error you state versus the code you've shown don't make sense. I would suggest posting the exact code and log. 

 

https://github.com/statgeek/SAS-Tutorials/blob/master/add_average_value_to_dataset.sas

 

 

Reeza
Super User

proc sql;
create table average as
select *, mean(score) as average_score
from sample
group by block, line
;
quit;

jchitw12
Fluorite | Level 6

That did the trick. Thank you so much!! 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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