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

Countif SAS.png

1 = Yes

0 = No

 

Given that I have the data set as shown, I'd like to accomplish the following tasks

 

1.) What is the percentage of the insured with high-school education have an accident?

Ans... 3/4 = 75%

 

2.) How many married insured have an accident?

Ans... 1/3 = 33%

 

It would be relatively simple in Excel. But I'm quite new to SAS.

 

Would you please help me?

 

PS I use SAS Academics On-Demand.

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
You'd better post your data as TEXT form. No one would like to type it for you .


data have;
input index accident married highschool;
cards;
1 1 0 1
2 1 0 1
3 0 1 1
4 0 1 0
5 1 1 1
;
run;
proc sql;
select sum(accident)/count(*) as per from have where highschool=1;
select sum(accident)/count(*) as per from have where married=1;
quit;


View solution in original post

6 REPLIES 6
Reeza
Super User

Hmm...there's quite a few ways. What do you want your output to look like?

 

One quick way is proc freq.

 

 

proc freq data=have;
table accident*education; /*Question 1*/
table married*accident;/*Question 2*/
run;

You have to read the correct cell from the output. If you want something more specific you need to post more details on expected output as well as sample data. 

 

PS. Please post data samples as text, I won't type out your data to test any solution.

momeya
Calcite | Level 5
Thank you!
Ksharp
Super User
You'd better post your data as TEXT form. No one would like to type it for you .


data have;
input index accident married highschool;
cards;
1 1 0 1
2 1 0 1
3 0 1 1
4 0 1 0
5 1 1 1
;
run;
proc sql;
select sum(accident)/count(*) as per from have where highschool=1;
select sum(accident)/count(*) as per from have where married=1;
quit;


momeya
Calcite | Level 5

Thank you!

ballardw
Super User

Here's something to think about with 0/1 coded variables as shown as long as they are actually numeric:

The SUM would give you the number of answers coded 1, Mean gives the percentage (though it will require either multiplication by 100 OR , much better, use of a SAS PERCENT format for display.

 

Yet another procedure:

proc tabulate data=have;

   var accident married HSEd;

   tables accident='Have an accident' married='Married?' HSED='High School Education' ,

              sum='Count'*f=best4. Mean='Percent'*f=percent8.0;

run;

momeya
Calcite | Level 5

Thank you

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 6 replies
  • 1639 views
  • 0 likes
  • 4 in conversation