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

Hi, i need help in creating a new column which will be used to assign scores based on the  below bands:

if qa_score < 90 then Score = 0

if qa_score >= 90 and qa_score < 92.5 then Score = 0.04

if qa_score >= 92.5 and qa_score < 95 then Score = 0.08

if qa_score >= 95 and qa_score < 97.5 then Score = 0.12

if qa_score >= 97.5 and qa_score < 100 then Score = 0.16

if qa_score = 100 then Score = 0.20

 

data have;
input policy_no QA_score;
datalines;
1 88 
2 91 
3 94 
4 96 
5 99
6 100 
;

 data WANT

policy_no   Score

1                0

2                0.04

3                0.08

4                0.12

5                0.16

6                0.20

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Try this

 

proc format;
   invalue s
      low  -< 90   = 0
      90   -< 92.5 = 0.04
      92.5 -< 95   = 0.08
      95   -< 97.5 = 0.12
      97.5 -< 100  = 0.16
      100  - high = 0.2
   ;
run;

data have;
input policy_no QA_score;
datalines;
1 88  
2 91  
3 94  
4 96  
5 99  
6 100 
;

data want;
   set have;
   score = input(QA_score, s.);
run;

View solution in original post

5 REPLIES 5
andreas_lds
Jade | Level 19

Sorry, but i don't see the problem. You have already posted the necessary statements to create the variable "score", so: what is the problem?

 

Using a format instead of if-statements is recommended, but this is up to you.

PeterClemmensen
Tourmaline | Level 20

Try this

 

proc format;
   invalue s
      low  -< 90   = 0
      90   -< 92.5 = 0.04
      92.5 -< 95   = 0.08
      95   -< 97.5 = 0.12
      97.5 -< 100  = 0.16
      100  - high = 0.2
   ;
run;

data have;
input policy_no QA_score;
datalines;
1 88  
2 91  
3 94  
4 96  
5 99  
6 100 
;

data want;
   set have;
   score = input(QA_score, s.);
run;
Solly7
Pyrite | Level 9
Thank you, it works perfectly fine.
japelin
Rhodochrosite | Level 12

If you want to make it shorter, you can use the following code.

data want;
  set have;
  if      qa_score < 90   then Score = 0;
  else if qa_score < 92.5 then Score = 0.04;
  else if qa_score < 95   then Score = 0.08;
  else if qa_score < 97.5 then Score = 0.12;
  else if qa_score < 100  then Score = 0.16;
  else if qa_score = 100  then Score = 0.20;
  drop qa_score;
run;

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!

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
  • 5 replies
  • 853 views
  • 2 likes
  • 4 in conversation