Dear all,
I want to calculate the average of value from 1-7 if year is in 2021/12. And if year is in 2020/12, and calculate the average of value from 8-14. Add an additional column to display the data corresponding to the average value of each period, for example, each row of 1-7 displays the average value of 1-7 at the end, each row of 8-14 displays the average value of 8-14 at the end. How can i edit the code.
Thanks all.
No need to use an if statement, just use proc summary and merge the result back to the dataset you have. Or use a dow-loop.
How complex a task is depends largely on the experience one has. Luckily you don't have to reinvent the wheel, just search for papers dealing with merge back summary statistics. Adapting the code should not be to difficult.
May I ask what you will do with this additional column that contains the average? Are you trying to find out how far above or below the average the value of variable VALUE is? Or do you have some other reason for doing this, if so, what? (Really, explain the reason why you want this; explaining the reason should always be a part of your original post, we shouldn't have to ask)
If you are trying to find out how far above or below the average the value of variable VALUE is, then use PROC STDIZE, no extra column needed.
proc stdize data=have method=mean out=want;
var value;
by year;
run;
Also, we have in the past asked you to not provide data as screen captures, but as working SAS data step code. Please do that in the future.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!