Obsidian | Level 7

## Week Wise Calculation

Hello All,

I have one issue PF the Below Explanation.

Please suggest me how to do it in SASVA.

I have week wise average purchase price of Raw material.

Exp: Now I want to calculate current week Avg Purchase Price - Last week Average Purchase Price.

Week      Avg Prucase Price       Required Column

1                 180                                 .

2                 175                                -5

3                 185                                10

4                 168                               -17

5                 190                                22

6                 187                               -3

I have week and Avg Price, I want to calculate Required Column ( Current Week Avg P Price - Last Week Avg P Price).

Jim.....

6 REPLIES 6
Amethyst | Level 16

## Re: Week Wise Calculation

Data want;
set have;
required=avg-lag(avg);
run;
Thanks,
Jag
Obsidian | Level 7

## Re: Week Wise Calculation

Okay!! Thanks for the Solution...
I was wondering if this can be done in SASVA on the fly calculation only because there are some other parameters also need to include further and accordingly Avg.P Price will changes so on, With coding it will be static solution...
Pyrite | Level 9

## Re: Week Wise Calculation

Do you have dates against your data?

If so you could look at the periodic operators

http://support.sas.com/documentation/cdl/en/vaug/66720/HTML/default/viewer.htm#n1lxnqfip132can1hdzue...

You could have two aggregated measures, one for current week and another for week -1

Obsidian | Level 7

## Re: Week Wise Calculation

Actually the Periodic Operators works for month, Qtr, Year, and so on I can not do the aggregation on the basis of Weekly as the week will be in number (Measure) formate and in Periodic it will required Date format....
SAS Employee

## Re: Week Wise Calculation

Hi Jim,

I don't think this can be done in the VA expression builder, but it should be possible for you to precalculate these values as part of your data query.

I hope that helps,

Sam

Quartz | Level 8

## Re: Week Wise Calculation

Hi Jim,

If you only want to display simply one selected week at a time you can. This will require using calculated items and probably play with parameters to allow you to select the desired week. Your final list table would be something like this:

Week   PurchasePrice_currentweek   PurchasePrice_previousweek  RequiredColumn

6                          187                                         190                                          -3

the variables definitions:

PurchasePrice_currentweek

if week='week_parameter'p

return 'Purchase Price'

else 0

PurchasePrice_previousweek

if week='week_parameter'p-1

return 'Purchase Price'

else 0

RequiredColumn

PurchasePrice_currentweek-PurchasePrice_previousweek

Discussion stats
• 6 replies
• 1262 views
• 0 likes
• 5 in conversation