BookmarkSubscribeRSS Feed
careypafford
Calcite | Level 5

I have a data set that has a total score from an assessment and gender. I need to create a new category of, 'risk level' that will use gender and a total score range to give me a risk level. How would I set this up?

 

Example: if 'gender' = M (options here are M or F) and 'total score' = 8 (I need this to be able to use a range, i.e. 0-7, 8-10,11-15, 16+) then 'risk level' (the newly created category) = Med-Low (options here are Low, Med-Low, Med-High, High)

 

Any help is appreciated. 

4 REPLIES 4
PaigeMiller
Diamond | Level 26

@careypafford wrote:

I have a data set that has a total score from an assessment and gender. I need to create a new category of, 'risk level' that will use gender and a total score range to give me a risk level. How would I set this up?

 

Example: if 'gender' = M (options here are M or F) and 'total score' = 8 (I need this to be able to use a range, i.e. 0-7, 8-10,11-15, 16+) then 'risk level' (the newly created category) = Med-Low (options here are Low, Med-Low, Med-High, High)

 

Any help is appreciated. 


You have given us one possible outcome, but there are many other possibilities and you haven't told us what risk score would result. You haven't told us what would happen if gender='F', and you haven't told us what would happen if total_score=9, and so on. We need to see the full set of possibilities in order to provide code to compute the risk level for you.

--
Paige Miller
Sajid01
Meteorite | Level 14

Hello @careypafford 
While there are multiple approaches to solving your problem, with the information you have given I have the following sample code. Modify it to suit your needs

proc sql;
select Name, Sex, age,
case
when Sex="M" and Age between 0 and 7 then 'LOW'
when Sex="M" and Age between 8 and 10 then 'MID-LOW'
when Sex="M" and Age between 10 and 15 then 'MID-HIGH'
when Sex="M" and Age> 16 then 'MID-HIGH'
 else 'NONE'
end as risk_level
from sashelp.class;
quit;
careypafford
Calcite | Level 5

The assessment breaks down as follows:

Low: Male: 0-7; Female: 0-10

Med-Low: Male: 8-10; Female: 11-13

Med-High: Male: 11-15; Female: 14-18

High: Male: 16+; Female: 19+ 

PaigeMiller
Diamond | Level 26

Partial example:

    

data want;
    set have;
    length category $ 8;
    if gender='M' and total_score<=7 then category='Low';
    else if gender='M' and 8<=total_score<=10 then category='Med-Low';
    /* You type the rest */
run;
--
Paige Miller

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 611 views
  • 0 likes
  • 3 in conversation