BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MABRINCH
Fluorite | Level 6

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: 

 

IDdatestagematchseq
101-10-201641
104-06-201942
230-09-201841
230-09-201822
301-10-201611
321-10-201632
304-06-201913
1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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;

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

So matchseq is the variable you want right?

PeterClemmensen
Tourmaline | Level 20

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;
MABRINCH
Fluorite | Level 6
"matchseq" is the variable I want.
PeterClemmensen
Tourmaline | Level 20

Ok have you tried the code above?

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 4 replies
  • 1222 views
  • 0 likes
  • 2 in conversation