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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

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

View solution in original post

4 REPLIES 4
Linlin
Lapis Lazuli | Level 10

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

Arumugam
Calcite | Level 5

Thanks.It worked.


Ksharp
Super User

proc tabulate data=have;

class name;

var  prevrecord  currrecord ;

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

run;

Haikuo
Onyx | Level 15

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

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

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 1523 views
  • 6 likes
  • 4 in conversation