BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Babloo
Rhodochrosite | Level 12

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'.

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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;

 

View solution in original post

10 REPLIES 10
PaigeMiller
Diamond | Level 26

PROC FREQ

--
Paige Miller
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Not tested as not typing that in:

data want; 
  merge have1 have2;
  percent=(ticket_count / total_ticket_count) * 100;
  format percent percent8.2;
run;
Babloo
Rhodochrosite | Level 12

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%

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Drop the * 100 then.

Astounding
PROC Star

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;

Babloo
Rhodochrosite | Level 12

Code which mentioned above is not producing the desired percentage value.

Astounding
PROC Star

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.

Babloo
Rhodochrosite | Level 12

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.'

Astounding
PROC Star

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;

 

Reeza
Super User

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.

 

delete percent proc freq.JPG

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 10 replies
  • 2006 views
  • 4 likes
  • 5 in conversation