- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi All,
I need to take an average of samples1 to 10 for respective treatment and replication and then would like to create a new variable of a treatment average (I have already sorted the data for replications and treatments). How can I achieve this by SAS coding, please?. It looks straight forward in excel but I am new to SAS and would like to learn it. Thank you in advance.
Replication (1-3) | Treatment (1-18) | Sample1-10 |
1 | 1 | values |
2 | 2 | |
3 | 3 |
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Assuming your sample variables are named SAMPLE1, SAMPLE2, .... SAMPLE9 SAMPLE10, then
data want;
set have;
sample_average=mean(of sample1-sample10);
run;
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set
Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets
--------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Do you have ten variables, Sample1-Sample10 that you need an average for each line? Or are you calculating the average using data from multiple rows?
If 10 variables
http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000245914.htm
If multiple rows
http://support.sas.com/training/tutorial/studio/summary-statistics.html
It also depends on what you want for output, which you haven't specified.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Assuming your sample variables are named SAMPLE1, SAMPLE2, .... SAMPLE9 SAMPLE10, then
data want;
set have;
sample_average=mean(of sample1-sample10);
run;
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set
Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets
--------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I used the codes you suggested. It is not working. Here is the error I get:
ERROR 180-322: Statement is not valid or it is used out of proper order.
My program code is:
data yield; set farmsys.exp38;
proc sort data=yield; by Rep Trt YLD_P1 - YLD_P10;
Avg = mean(OF YLD_P1 - YLD_P10);
proc print data=yield;
run;
that is how the data is tabulated:
Rep
Plot
Trt
YLD_P1
YLD_P2
YLD_P3
YLD_P4
YLD_P5
YLD_P6
YLD_P7
YLD_P8
YLD_P9
YLD_P10
R1
101
15
197.3
53.3
202.3
171.6
202.8
200.5
122.4
190.8
190.1
180.9
R1
102
10
131.4
99.5
135.5
191.5
.
151.4
177.4
194.3
187.9
94.5
Thank you very much for your input on this.
fridge
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Data transfomations can generally only be done in a DATA step or PROC SQL. DefinitelyNOT in a proc sort.
SAS is a procedure-oriented tool (some call it a language).
So ...
- Move the "avg=" statement after the SET statement.
- And termnate the data step (and the proc sort step) with a "run;" statement.
Not required, but good practice
Then read something like "The Little SAS Book" to get the basics. (and run some SAS tutorials.).
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set
Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets
--------------------------