BookmarkSubscribeRSS Feed
sbopster
Calcite | Level 5

How can I determine the first encounter of the condition and flag it? I need to flag that 'M' had occurred on 06/02/2020 so I can not count cond 'M' as the first encounter on 06/12/2020.

data wide ; 
input id $ date MMDDYY10. cond1 $ cond2 $;
format date date9.;
datalines ;
1 06/02/2020 M Z
1 06/12/2020 B M
2 06/22/2020 M B

;

 

3 REPLIES 3
ballardw
Super User

So if we can't take the first occurrence what is the rule that says we can use the second?

 

Is it that must occur in a specific variable? Only as the second mention regardless of variable? Something else?

 

If the rule is a bit complicated you may need to provide more examples of the types of combinations occur and then indicate which are counted.

 

It will also help if show what the output should look like.

smantha
Lapis Lazuli | Level 10
data wide ; 
  input id $ date MMDDYY10. cond1 $ cond2 $; 
  format date date9.;
datalines ; 
1 06/02/2020 M Z
1 06/12/2020 B M  
2 06/22/2020 M B
   
; 
run;
proc transpose data=wide out=tall;
by id date;
var cond:;
run;

proc sort; by id col1 date;
run;

data tall;
set tall;
by id col1 date;
if first.col1;
run;

By using the above code you get first encounter for each of the conditions. Is this what you want?

sbopster
Calcite | Level 5

yes that works. I was using an array. thank you.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 3 replies
  • 809 views
  • 0 likes
  • 3 in conversation