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: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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