Here is my dataset. I want to calculate Percentage as Y/(Y+N) using Count number for both NBUS and Season. Anyone know how to get the results? Thanks a lot
Status | Tenure | Count |
N | NBUS | 543 |
N | Season | 1099 |
Y | NBUS | 276 |
Y | Season | 264 |
proc sql;
create table want1 as select
status, tenure, count, sum(count) as sum
from have
group by tenure;
quit;
proc sql;
create table want2 as select
status, tenure, count/sum*100 as percent
from want1
where status='Y';
quit;
data have;
input Status $ Tenure $ Count;
cards;
N NBUS 543
N Season 1099
Y NBUS 276
Y Season 264
run;
proc sql;
create table want as
select status, tenure, count, count/sum(count) as Pct
from have;
quit;
The Final result I want to get is 276/(276+543) for NBUS, 264/(264+1099) for Season.
proc sql;
create table want as
select status, tenure, count, count/sum(count) as Pct
from have
group by tenure;
quit;
proc sql;
create table want1 as select
status, tenure, count, sum(count) as sum
from have
group by tenure;
quit;
proc sql;
create table want2 as select
status, tenure, count/sum*100 as percent
from want1
where status='Y';
quit;
Times 100.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.