I've a datasets like this.
Have 1:
ticket_count Resolved_by
16 L2
5 L3
Have 2:
total_ticket_count
21
I want the output as follows:
ticket_count Resolved_by Total_ticket_count Percentage_of _tickets_resolved
16 L2 21 76.16%
5 L3 21 23.80%
Appreciate if someone of you help me calculating 'Percentage_of _tickets_resolved'.
Here's code: tested and producing the proper result.
data have1;
input ticket_count resolved_by $;
cards;
16 L2
5 L3
;
data have2;
total_ticket_count=21;
run;
data want;
if _n_=1 then set have2;
set have1;
percentage_of_tickets_resolved = ticket_count / total_ticket_count;
format percentage_of_tickets_resolved percent9.2;
run;
proc print;
run;
PROC FREQ
Not tested as not typing that in:
data want; merge have1 have2; percent=(ticket_count / total_ticket_count) * 100; format percent percent8.2; run;
I've ran the similar code already and it is not producing the desired perecentage. Code below is producing the output as follows.
total_ticket_count Resolved_by total_ticket_counts percentage
16 L2 21 13125%
5 L3 21 525%
Drop the * 100 then.
To get the total ticket count to remain on all the observations coming in, try a slightly different syntax:
data want;
if _n_=1 then set have2;
set have1;
percentage_of_tickets_resolved = ticket_count / total_ticket_count;
format percentage_of_tickets_resolved percent9.2;
run;
Code which mentioned above is not producing the desired percentage value.
That's true, because your original percentages are wrong. (Did you notice that they don't add up to 100%?) But the results match up to 1 decimal place, with the correct values generated by the program I posted.
Desired percentage is close to 100 (i.e. 99.6%) and it should be 100%. But I'm not getting the desired 100% value from the program which you posted. Appreciate if could elaborate this sentence 'But the results match up to 1 decimal place, with the correct values generated by the program I posted.'
Here's code: tested and producing the proper result.
data have1;
input ticket_count resolved_by $;
cards;
16 L2
5 L3
;
data have2;
total_ticket_count=21;
run;
data want;
if _n_=1 then set have2;
set have1;
percentage_of_tickets_resolved = ticket_count / total_ticket_count;
format percentage_of_tickets_resolved percent9.2;
run;
proc print;
run;
1. Do you actually need HAVE2 here? That information can be calculated from HAVE1.
2. Did you try a 'plain jane' PROC FREQ? That works fine for me.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.