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

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!

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