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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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