what is the SAS equivalent to SPSS's matchsequence (a sequential count of matching case in each group)?
I want to number cases with same ID by a date(ascending) and if same date then by a stage(descending).
Data want:
ID | date | stage | matchseq |
1 | 01-10-2016 | 4 | 1 |
1 | 04-06-2019 | 4 | 2 |
2 | 30-09-2018 | 4 | 1 |
2 | 30-09-2018 | 2 | 2 |
3 | 01-10-2016 | 1 | 1 |
3 | 21-10-2016 | 3 | 2 |
3 | 04-06-2019 | 1 | 3 |
I think this is what you want
data have;
input ID date :ddmmyy10. stage matchseq;
format date ddmmyy10.;
datalines;
1 01-10-2016 4 1
1 04-06-2019 4 2
2 30-09-2018 4 1
2 30-09-2018 2 2
3 01-10-2016 1 1
3 21-10-2016 3 2
3 04-06-2019 1 3
;
data want;
set have;
by ID;
if first.ID then match_seq = 0;
match_seq + 1;
run;
So matchseq is the variable you want right?
I think this is what you want
data have;
input ID date :ddmmyy10. stage matchseq;
format date ddmmyy10.;
datalines;
1 01-10-2016 4 1
1 04-06-2019 4 2
2 30-09-2018 4 1
2 30-09-2018 2 2
3 01-10-2016 1 1
3 21-10-2016 3 2
3 04-06-2019 1 3
;
data want;
set have;
by ID;
if first.ID then match_seq = 0;
match_seq + 1;
run;
Ok have you tried the code above?
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.