BookmarkSubscribeRSS Feed
ilasadar
Calcite | Level 5

Hello,

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?

Thank you.

3 REPLIES 3
Sam_SAS
SAS Employee

Hi ilasadar,

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?

Thanks,

Sam

Steelers_In_DC
Barite | Level 11

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:

data have;

infile cards;

input ID measure;

cards;

1 1

1 2

1 3

1 4

1 5

2 2

2 4

2 6

2 8

2 10

;

proc sql;

create table want as

select *,measure-sum_measure as calculated_value

from(

select *,sum(measure) as sum_measure

from have

group by id)

order by id;

Steelers_In_DC
Barite | Level 11

I just looked at the output and it helps to complete the order by line:

proc sql;

create table want as

select *,measure-sum_measure as calculated_value

from(

select *,sum(measure) as sum_measure

from have

group by id)

order by id,measure;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 3 replies
  • 3441 views
  • 0 likes
  • 3 in conversation