BookmarkSubscribeRSS Feed
victory
Fluorite | Level 6

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.

victory_0-1671173922245.png

Thanks all.

4 REPLIES 4
andreas_lds
Jade | Level 19

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.

victory
Fluorite | Level 6
How can i edit the code. I've never written code like this. Will it be complicated?
andreas_lds
Jade | Level 19

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.

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Discussion stats
  • 4 replies
  • 2122 views
  • 1 like
  • 3 in conversation