BookmarkSubscribeRSS Feed
noda6003
Quartz | Level 8

I want to create 2 flags: one is if there is change of more than 5 points between recs and another flag if there is no change in score from recs to another 3 consecutive recs.

 

I am not figuring it out on how to do this and need help.

 

Required flag1 and flag2 and need something like below

PIDrecsscoreflag1flag2
121111  
121223Y 
121323 Y
121423 Y
121523 Y
122111  
122214  
122324Y 
122434Y 
122522  
122611  
5 REPLIES 5
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

in your want should this

122 2 14  

 

be this

122 2 14 Y  
PaigeMiller
Diamond | Level 26
/* UNTESTED CODE */
Data want;
    set have;
    Prev_id=lag(pid);
    Prev_id2=lag2(pid);
    prev_score=lag(score);
    prev_score2=lag2(score);
    if score-prev_score>5 and pid=prev_id then flag1='Y';
    if score=prev_score and score=prev_score2 
        and pid=prev_id and pid=prev_id2 then flag2='Y';
run;
    
--
Paige Miller
noda6003
Quartz | Level 8

 to mention is somehow should work for improving and worsening scores. so in the below for 121 it has 9 and decreased the next recs to 2 and it needs to have flag. also if it has same score 3 consecutive times than the second 2 should have flags as Y- excluding the first

PIDrecsscoreflag1flag2
12113  
12129Y 
12132Y 
12141  
12217  
12221Y 
12233  
12243 Y
12253 Y
PaigeMiller
Diamond | Level 26

to mention is somehow should work for improving and worsening scores. so in the below for 121 it has 9 and decreased the next recs to 2 and it needs to have flag.

 

This is a trivial change to the code I provided. Please see if you can make the modification to the code yourself.

 

also if it has same score 3 consecutive times than the second 2 should have flags as Y- excluding the first

 

Sort the data backwards, then if you get a Y in flag2, then add a Y to the next record.

 

 

--
Paige Miller
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
  • 1512 views
  • 0 likes
  • 3 in conversation