BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ybz12003
Rhodochrosite | Level 12

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%

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

 

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20

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;

novinosrin
Tourmaline | Level 20

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;
ballardw
Super User

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.

 

SAS Innovate 2025: Register Now

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!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 3042 views
  • 3 likes
  • 3 in conversation