zenith1107
Technical User
Hi all,
I'm a new user of SAS and I have encountered a problem:
DATA test;
input Week $ Day Price;
CARDS;
111 1 1
111 1 2
112 1 3
112 1 4
111 2 5
111 2 6
112 2 7
112 2 8
;
I want to create a new variable MEANP that stores the mean PRICE for the observations in the same DAY but different WEEK. For example, for the 1st and 2nd row, the value of MEANP both = the mean PRICE of the rows where WEEK=112 and DAY=1 (the 3rd and 4th rows) and for the 3rd and 4th row, MEANP both = the mean PRICE of the rows where WEEK=111 and DAY=1 (the 1st and 2nd rows). And the final result would look like this:
WEEK DAY PRICE MEANP
111 1 1 3.5
111 1 2 3.5
112 1 3 1.5
112 1 4 1.5
111 2 5 7.5
111 2 6 7.5
112 2 7 5.5
112 2 8 5.5
I'm wondering if there's an easy way to do that. Any help is greatly appreciated.
Thanks!
I'm a new user of SAS and I have encountered a problem:
DATA test;
input Week $ Day Price;
CARDS;
111 1 1
111 1 2
112 1 3
112 1 4
111 2 5
111 2 6
112 2 7
112 2 8
;
I want to create a new variable MEANP that stores the mean PRICE for the observations in the same DAY but different WEEK. For example, for the 1st and 2nd row, the value of MEANP both = the mean PRICE of the rows where WEEK=112 and DAY=1 (the 3rd and 4th rows) and for the 3rd and 4th row, MEANP both = the mean PRICE of the rows where WEEK=111 and DAY=1 (the 1st and 2nd rows). And the final result would look like this:
WEEK DAY PRICE MEANP
111 1 1 3.5
111 1 2 3.5
112 1 3 1.5
112 1 4 1.5
111 2 5 7.5
111 2 6 7.5
112 2 7 5.5
112 2 8 5.5
I'm wondering if there's an easy way to do that. Any help is greatly appreciated.
Thanks!