Fluorite | Level 6

## SAS Visual Analytics, Possibility of applying rules by category

Hi there,

I am applying colour coding based on the % of status (status has 3 categories in it - Planned, Completed, Overdue). Now the rules are applied as a whole. Is there a way to include colour coding by status.

current scenario:

If status:

 95% - 100% green 75% - <95% amber <75% red

Is it possible to apply rules based on status:

if status="Completed" and percentage ge 75% then green.

if status="Overdue" and percentage le 5% then green.

...and so on.

Thanks,

RP

1 ACCEPTED SOLUTION

Accepted Solutions
SAS Employee

## Re: SAS Visual Analytics, Possibility of applying rules by category

Hey @prsr! I believe you can achieve this by creating a calculated item that flags a 1 or 0 if the aggregated value is higher than the expected value for that specific category. Let's consider this with sashelp.cars: we have a bar chart with average horsepower by origin. If the average horsepower for Asian vehicles is > 150, we want the bar to be red. Let's create a calculation that does this:

```if( Avg(ByGroup, if(Origin = 'Asia') return Horsepower else .) ) > 150
return 1
else 0```

Now we can add this calculation as a rule to our bar chart. Based on our calculation, this can only be a 1 or 0 for Asian vehicles.

And now if we look at our bar chart, only Asia is highlighted red.

2 REPLIES 2
SAS Employee

## Re: SAS Visual Analytics, Possibility of applying rules by category

Hey @prsr! I believe you can achieve this by creating a calculated item that flags a 1 or 0 if the aggregated value is higher than the expected value for that specific category. Let's consider this with sashelp.cars: we have a bar chart with average horsepower by origin. If the average horsepower for Asian vehicles is > 150, we want the bar to be red. Let's create a calculation that does this:

```if( Avg(ByGroup, if(Origin = 'Asia') return Horsepower else .) ) > 150
return 1
else 0```

Now we can add this calculation as a rule to our bar chart. Based on our calculation, this can only be a 1 or 0 for Asian vehicles.

And now if we look at our bar chart, only Asia is highlighted red.

Fluorite | Level 6

## Re: SAS Visual Analytics, Possibility of applying rules by category

Hi @Stu_SAS, Thanks for your time assisting on this.

I have the below data structure:

1 – status , directly from SAS table

2 – count , directly from SAS table

3 – % calculated data item – aggregate measure created as below

Sum [_ByGroup_] ('count'n) / Sum [_ForAll_] ('count'n)

Format Percentage applied

4 – % calculated data item as above, but with out percentage format

In your example, both the fields already in sas table. I tried to replicate the example on on sas sample cars table and it worked. In my case (table structure above), I have to use % field (calculated data item – Aggregated measure) in conjunction with status. Is it possible to use one field that is part of the sas table (…status) and another an aggregate measure (%) together in an expression to my requirement to colour bar chart – bar (overdue) and % >0.003.

I tried below expressions using calculated item Aggregate measure %–

IF ( Sum [_ByGroup_] ((

IF ( UpCase('Status'n) = 'OVERDUE' )

RETURN '%'n

ELSE . )) > 0.001 )

RETURN 1

ELSE 0

(IF ('STATUS'n ='Overdue') return ((sum [_ByGroup_] ('%_num'n)) ELSE .) >0.002 )

return 1

else .

Thanks,

RP

Discussion stats
• 2 replies
• 363 views
• 1 like
• 2 in conversation