BookmarkSubscribeRSS Feed
Jatin_Jim
Obsidian | Level 7

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

6 REPLIES 6
Jagadishkatam
Amethyst | Level 16
Please try the lag funtion

Data want;
set have;
required=avg-lag(avg);
run;
Thanks,
Jag
Jatin_Jim
Obsidian | Level 7
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...
itchyeyeballs
Pyrite | Level 9

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

Jatin_Jim
Obsidian | Level 7
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....
Sam_SAS
SAS Employee

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

rmalcata
Quartz | Level 8

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

Tips for filtering data sources in SAS Visual Analytics

See how to use one filter for multiple data sources by mapping your data from SAS’ Alexandria McCall.

Find more tutorials on the SAS Users YouTube channel.

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