BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

Hello

I would like to get the following summary table which calculate percent from total for each category of each field.

May anyone show the code that can create it?

Cherers 

Ronein_0-1615320897823.png

 

 

Data Rawtbl;
input ID field $  category  year ;
cards;
1 x 1 2020 
1 w 2 2020
1 z 2 2020
2 x 2 2020
2 w 3 2020
2 z 2 2020
3 x 2 2020
3 w 2 2020
3 z 2 2020
4 x 1 2020
4 w 2 2020
4 z 1 2020
5 x 3 2020
5 w 2 2020
5 z 2 2020
6 x 2 2021 
6 w 3 2021
6 z 1 2021
2 x 1 2021
2 w 1 2021
2 z 1 2021
3 x 2 2021
3 w 2 2021
3 z 3 2021
4 x 3 2021
4 w 2 2021
4 z 1 2021
;
run;
2 REPLIES 2
Ksharp
Super User
Data Rawtbl;
input ID field $  category  year ;
cards;
1 x 1 2020 
1 w 2 2020
1 z 2 2020
2 x 2 2020
2 w 3 2020
2 z 2 2020
3 x 2 2020
3 w 2 2020
3 z 2 2020
4 x 1 2020
4 w 2 2020
4 z 1 2020
5 x 3 2020
5 w 2 2020
5 z 2 2020
6 x 2 2021 
6 w 3 2021
6 z 1 2021
2 x 1 2021
2 w 1 2021
2 z 1 2021
3 x 2 2021
3 w 2 2021
3 z 3 2021
4 x 3 2021
4 w 2 2021
4 z 1 2021
;
run;

proc format ;
picture fmt
low-high='009.99%';
run;
proc tabulate data=rawtbl;
class category field year;
table field*(category all),year*pctn<category all >='PCT'*f=fmt8.2 /printmiss;
run;

屏幕截图 2021-03-10 200247.jpg

Cynthia_sas
Diamond | Level 26
Hi:
Is this a new requirement for THIS same question and data? https://communities.sas.com/t5/SAS-Programming/proc-tabulate-percent-from-total-column-per-each-grou...

Cynthia

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 777 views
  • 0 likes
  • 3 in conversation