BookmarkSubscribeRSS Feed
andypandy_swe
Obsidian | Level 7

I have a table (simplified) with three columns:
id

group

value

unit

 

I'd like a barchart which shows value per group when i select 'id' from a dropdown list.

Unit can have the values '%' or 'amount'.

So I'd like the graph to show the value as a percentage (multiplied by 100 and with a percent-sign) if unit='%' and as the original value if unit='amount'.

 I created a calculated item called value_pct that takes value and multiplies by 100.
I then create another calculated item called SWITCH that checks the value of Unit and if it's '%' it returns value_pct, otherwise it returns value. Switch has the format comma12.2

I then use SWITCH in the graph.
This works but I'm not getting a percent sign of course...

If I instead define value_pct only as the variable 'value' but with a percent format. Then the SWITCH item won't work in the graph.

Presumably because The format of SWITCH overrides the percent format of value_pct...

Is there a way around this? Create switch without a format? Or is there a completely different, better way to do what I want?

4 REPLIES 4
Sam_SAS
SAS Employee

Hello,

 

It's always easier to get help if you post a screen capture and some sample data.

 

If I understand correctly, you want to graph a numeric variable where some values have a percent format and some values are just plain numerics. Is that right?

I don't know if that is possible. In something like a table you could display the numbers and percentages as character values, but I don't know if that would be helpful. What kind of graph did you want to create?

 

Possibly you could work around the issue by making a dual-axis chart.

 

Sam

andypandy_swe
Obsidian | Level 7

It's a barchart so the percent sign would be on the axis label (and possibly the tooltip). 
I've been unable to solve it so my workaround is have a textbox with a parameter holding the type of value (% or index) above the graph.
Far from perfect but I think it's the best one can do in this version of VA.

I think a dual axis would only be confusing...

FredrikE
Rhodochrosite | Level 12

Hi!

I think it only works if the two measures have the same format. When I use your method i usualy try to make it very clear what is shown in the graph. In some reports I added a textobject "on the graph" showing the parameter value 🙂

 

Another way of solving this could be to use a stacked(tabbed)-container with one tab for value and another for %.

I think data is loaded for each tab directly so it is very fast when changing tab. I use it a lot.

FredrikE_0-1737712495516.png

 

FredrikE_1-1737712521906.png

 

BR

Fredrik

 

andypandy_swe
Obsidian | Level 7

The user will have no way of knowing if it's a percent graph or an index graph so they'd have to klick the tabs to find the graph after making the selection...
This was considered but rejected.

We went with displaying the unit in the graph name using a textbox with a parameter instead. Not perfect but it's something.

Thinking about sending in a feature request to SAS so that you can allow a calculated object to inherit the format (and also sort order) of another object...

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 4 replies
  • 1350 views
  • 2 likes
  • 3 in conversation