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
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
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
Thanks.It worked.
proc tabulate data=have;
class name;
var prevrecord currrecord ;
table name,prevrecord*(sum colpctsum) currrecord*(sum colpctsum);
run;
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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.