## Percent difference from "fixed" previous period

Solved
Occasional Contributor
Posts: 5

# Percent difference from "fixed" previous period

HI -

I'm new to SAS VA and this community and would like to see if anyone here can help me to solve a problem I have when designing a report. I want to create a graph showing percent difference from a fixed previous period (the first date in my data). I do not really understand how I can achieve this from the optional settings in the aggregated measure editor. Does anyone have any kind of solution for this?

Kind regards,

Mats

P.S It doesnt have to be solved within the editor - any solution woud be greatly appreciated.

Accepted Solutions
Solution
‎05-03-2017 10:56 AM
SAS Super FREQ
Posts: 322

## Re: Percent difference from "fixed" previous period

If the reference date can be hardcoded, then you could use the PeriodWithDate operator.

For example, you might use an expression like this to compare the values of Sales for each month to the value from JAN2015:

Period(_Sum_, 'Sales'n, 'Date'n, _ByMonth_) - PeriodWithDate(_Sum_, 'Sales'n, 'Date'n, _ByMonth_, '01JAN2015'd)

Documentation for Period() and PeriodWithDate() can be found here:

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

Hope that helps.

If the first date in the data set needs to be determined dynamically, I don't think that can be done easily in the expression editor. You will need to use SAS code in your data query to evaluate it.

Sam

All Replies
Super User
Posts: 9,866

## Re: Percent difference from "fixed" previous period

Well, I don't use VA so my answer here is going to be general SAS code.  What I would do, and its per the models in my field, is to extract the baseline value, then merge that back to the original data.  So (and you have not posted and test data in the form of a datastep so this is just example):

Some examplpe data:

Id     Period      Result

1      1             123

1      2             345

1      3              456

```data base (rename=(result=base));
set have;  where period=1;run;data want;  merge have base;  by id;run;```

Now in this case, all records in the original dataset have a column base from the fixed period, and you can calculate across.

Solution
‎05-03-2017 10:56 AM
SAS Super FREQ
Posts: 322

## Re: Percent difference from "fixed" previous period

If the reference date can be hardcoded, then you could use the PeriodWithDate operator.

For example, you might use an expression like this to compare the values of Sales for each month to the value from JAN2015:

Period(_Sum_, 'Sales'n, 'Date'n, _ByMonth_) - PeriodWithDate(_Sum_, 'Sales'n, 'Date'n, _ByMonth_, '01JAN2015'd)

Documentation for Period() and PeriodWithDate() can be found here:

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

Hope that helps.

If the first date in the data set needs to be determined dynamically, I don't think that can be done easily in the expression editor. You will need to use SAS code in your data query to evaluate it.

Sam

Occasional Contributor
Posts: 5

## Re: Percent difference from "fixed" previous period

Thanks - both of you!

🔒 This topic is solved and locked.