Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Programming
- /
- SAS Procedures
- /
- Create a new dataset with average plot values calculated from individu...

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 11-04-2017 12:07 PM
(1156 views)

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

create table average as

select *, mean(score) as average_score

from sample

group by block, line

;

quit;

3 REPLIES 3

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

create table average as

select *, mean(score) as average_score

from sample

group by block, line

;

quit;

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

That did the trick. Thank you so much!!

**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.

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.