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

Week Wise Calculation

Reply
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

Jim.....

Super User
Posts: 980

Re: Week Wise Calculation

Please try the lag funtion

Data want;
set have;
required=avg-lag(avg);
run;
Thanks,
Jag
Occasional Contributor
Posts: 13

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...
Frequent Contributor
Posts: 75

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

Occasional Contributor
Posts: 13

Re: Week Wise Calculation

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....
SAS Super FREQ
Posts: 275

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

Contributor
Posts: 31

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

Post a Question
Discussion Stats
  • 6 replies
  • 148 views
  • 0 likes
  • 5 in conversation