Hello:
I would like to calculate the counts in Column 'A' where the number is '1' or '0' separately? And the percentage where '1' over '0', and '1' over _all_.
DATA TEST;
INPUT id agree;
datalines;
1 1
2 1
3 0
4 1
5 0
6 1
7 0
8 0
9 0
10 0
;
run;
The result I am looking for is:
Yes: 4
Yes percentage: 40%
No: 6
No percentage:60%
And a Proc Tabulate solution
proc tabulate data=test; class agree; table agree, n colpctn; run;
if people are to read the result and a data set not needed.
DATA TEST;
INPUT id agree;
datalines;
1 1
2 1
3 0
4 1
5 0
6 1
7 0
8 0
9 0
10 0
;
run;
proc sql;
create table want as
select agree, count(agree)/(select count(*) from test)*100 as c
from test
group by agree;
quit;
With percent format
proc sql;
create table want as
select agree, count(agree)/(select count(*) from test) as c format=percent.
from test
group by agree;
quit;
And a Proc Tabulate solution
proc tabulate data=test; class agree; table agree, n colpctn; run;
if people are to read the result and a data set not needed.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.