Hi,
How do I calculate percentage of row or percentage of column calculation in a crosstab in SAS Viya VA 8.5? I would like to be able to do it based on frequency and another measure (for instance sales $ value). The total value (100%) is not required.
Thanks in advance.
Regards,
Kyle
Ex.
Have: | ||||
Month | ||||
Jan | Feb | Mar | ||
Product | Widget1 | 5 | 4 | 9 |
Widget2 | 7 | 1 | 4 | |
Widget3 | 11 | 13 | 8 | |
23 | 18 | 21 | ||
Want: | ||||
Month | ||||
Jan | Feb | Mar | ||
Product | Widget1 | 21.7% | 22.2% | 42.9% |
Widget2 | 30.4% | 5.6% | 19.0% | |
Widget3 | 47.8% | 72.2% | 38.1% | |
100.0% | 100.0% | 100.0% |
Hello @Kyle4 ,
Please try the AggregateTable operator that was introduced in VA 8.3. Here is code snippet which you can easily copy-paste to your editor.
Steps:
AggregateTable(_Sum_, Table(_Sum_, Fixed('Product'n, 'Month'n), 'Measure'n)) / AggregateTable(_Sum_, Table(_Sum_, Fixed('Month'n) , 'Measure'n))
And here is how my Crosstab looks like.
I hope this helps 😃
Best regards,
Petri
Hello @Kyle4 ,
Please try the AggregateTable operator that was introduced in VA 8.3. Here is code snippet which you can easily copy-paste to your editor.
Steps:
AggregateTable(_Sum_, Table(_Sum_, Fixed('Product'n, 'Month'n), 'Measure'n)) / AggregateTable(_Sum_, Table(_Sum_, Fixed('Month'n) , 'Measure'n))
And here is how my Crosstab looks like.
I hope this helps 😃
Best regards,
Petri
Thank so much, Petri. This is great.
Will go and study AggregateTable in more detail.
Kind Regards,
Kyle
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.