I want to create a calculated variable that returns the difference between a measure and it's grand total.
The formula for the variable would be:
Calculated variable = Measure - Sum[_ForAll_]
However, SAS VA does not allow aggregate variables to be used in creating calculated variables.
Is there a way the this can be achieved?
If your expression uses aggregated values, then you have to make an aggregated measure instead of a calculated measure.
An aggregated measure like this might do what you want, when applied to a visualization or report object:
Sum [_ForAll_] ('Expenses'n) - Sum [_ByGroup_] ('Expenses'n)
Does that help?
It would be better to give an example of what you have and a small dataset that provides an example of what you are looking for. I think this is what you want, let me know if this helps:
input ID measure;
create table want as
select *,measure-sum_measure as calculated_value
select *,sum(measure) as sum_measure
group by id)
order by id;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.