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?
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.