Rhodochrosite | Level 12

## Percentage calculation

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
PROC Star

## Re: Percentage calculation

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;

10 REPLIES 10
Diamond | Level 26

## Re: Percentage calculation

PROC FREQ

--
Paige Miller
Diamond | Level 26

## Re: Percentage calculation

Not tested as not typing that in:

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

## Re: Percentage calculation

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%

Diamond | Level 26

## Re: Percentage calculation

Drop the * 100 then.

PROC Star

## Re: Percentage calculation

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;

Rhodochrosite | Level 12

## Re: Percentage calculation

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

PROC Star

## Re: Percentage calculation

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.

Rhodochrosite | Level 12

## Re: Percentage calculation

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

PROC Star

## Re: Percentage calculation

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;

Super User

## Re: Percentage calculation

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.

Discussion stats
• 10 replies
• 1667 views
• 4 likes
• 5 in conversation