Exploring, predicting and reporting with SAS Visual Analytics and SAS Visual Statistics

Week Wise Calculation

Occasional Contributor
Posts: 13

Week Wise Calculation

[ Edited ]

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).





Thanks in Advance


Trusted Advisor
Posts: 1,170

Re: Week Wise Calculation

Posted in reply to Jatin_Jim
Please try the lag funtion

Data want;
set have;
Occasional Contributor
Posts: 13

Re: Week Wise Calculation

Posted in reply to Jagadishkatam
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...
Frequent Contributor
Posts: 131

Re: Week Wise Calculation

Posted in reply to Jatin_Jim

Do you have dates against your data?


If so you could look at the periodic operators




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

Occasional Contributor
Posts: 13

Re: Week Wise Calculation

Posted in reply to itchyeyeballs
Thanks For the reply:
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....
Posts: 322

Re: Week Wise Calculation

Posted in reply to Jatin_Jim

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,


Posts: 47

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:


if week='week_parameter'p

return 'Purchase Price'

else 0



if week='week_parameter'p-1

return 'Purchase Price'

else 0




Ask a Question
Discussion stats
  • 6 replies
  • 5 in conversation