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
;
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.
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?
yes that works. I was using an array. thank you.
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.
Ready to level-up your skills? Choose your own adventure.