Solved
New Contributor
Posts: 4

Calculate percentage of 2 column

te
I have a data like as below

Name   prevrecord  currrecord

A              10               25

B               20              15

C               40               20

My outputput should look like

Name  prevrecord prevpct   currrecord currpct

A             10           14.28        25            41.6

B              20           28.57       15              25

C              40            57.14      20            33.33

Prevpct and currpct is the percentage of corresponding column.Which procedure i can use to acheive this?

Thanks,

Mani

Accepted Solutions
Solution
‎07-19-2012 09:27 PM
Super Contributor
Posts: 1,636

Re: Calculate percentage of 2 column

data have;

input Name :\$  prevrecord :  currrecord;

cards;

A              10               25

B               20              15

C               40               20

;

proc sql;

create table want as

select name

,prevrecord

,prevrecord/sum(prevrecord)*100 format=5.2 as prevpct

,currrecord

,currrecord/sum(currrecord)*100 format=5.2 as currpct

from have;

quit;

proc print;run;

Linlin

All Replies
Solution
‎07-19-2012 09:27 PM
Super Contributor
Posts: 1,636

Re: Calculate percentage of 2 column

data have;

input Name :\$  prevrecord :  currrecord;

cards;

A              10               25

B               20              15

C               40               20

;

proc sql;

create table want as

select name

,prevrecord

,prevrecord/sum(prevrecord)*100 format=5.2 as prevpct

,currrecord

,currrecord/sum(currrecord)*100 format=5.2 as currpct

from have;

quit;

proc print;run;

Linlin

New Contributor
Posts: 4

Re: Calculate percentage of 2 column

Thanks.It worked.

Super User
Posts: 10,784

Re: Calculate percentage of 2 column

proc tabulate data=have;

class name;

var  prevrecord  currrecord ;

table name,prevrecord*(sum colpctsum) currrecord*(sum colpctsum);

run;

Respected Advisor
Posts: 3,167

Re: Calculate percentage of 2 column

The more, the merrier, here is a data step approach:

data want (drop=_;

set have(in=up) have;

format prevpct currpct percent8.2;

if up then do;

_tp+prevrecord;

_tc+currrecord;

end;

else do;

prevpct=prevrecord/_tp;

currpct=currrecord/_tc;

output;

end;

run;

Haikuo

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
• 4 replies
• 235 views
• 6 likes
• 4 in conversation