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