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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.