Fluorite | Level 6

## if condition

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.

4 REPLIES 4
Jade | Level 19

## Re: if condition

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.

Fluorite | Level 6

## Re: if condition

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

## Re: if condition

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.

Diamond | Level 26

## Re: if condition

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
Discussion stats
• 4 replies
• 2125 views
• 1 like
• 3 in conversation