- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello. I am trying to create an enumeration variable that must take into account 3 by groups. I need to get two different variables - one restarts by patient ID and the other keeps counting. All the solutions online and on this forum are not working. Please assist. This is what I am going for:
PID RID LID RestartVariable CountVariable (trying to get the last two variables)
141 57 19 1 1
141 57 19 1 1
141 58 13 2 2
141 58 14 3 3
141 59 20 4 4
141 59 20 4 4
142 59 25 1 5
142 59 25 1 5
142 59 25 1 5
142 60 26 2 6
143 60 26 1 7
Thank you.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Like this?
EDIT: I edited my code because you changes your question. I think this is what you want. But shouldn't RestartVariable=1 at the bottom?
EDIT2: I see you changed your question again 🙂 @eabc0351 does this work for you?
data have;
input PID RID LID;
datalines;
141 57 19
141 57 19
141 58 13
141 58 14
141 59 20
141 59 20
142 59 25
142 59 25
142 59 25
142 60 26
143 60 26
;
data want;
set have;
by PID notsorted RID notsorted LID notsorted;
if first.PID | first.RID | first.LID then do;
CountVariable+1;
RestartVariable+1;
end;
if first.PID then RestartVariable=1;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Like this?
EDIT: I edited my code because you changes your question. I think this is what you want. But shouldn't RestartVariable=1 at the bottom?
EDIT2: I see you changed your question again 🙂 @eabc0351 does this work for you?
data have;
input PID RID LID;
datalines;
141 57 19
141 57 19
141 58 13
141 58 14
141 59 20
141 59 20
142 59 25
142 59 25
142 59 25
142 60 26
143 60 26
;
data want;
set have;
by PID notsorted RID notsorted LID notsorted;
if first.PID | first.RID | first.LID then do;
CountVariable+1;
RestartVariable+1;
end;
if first.PID then RestartVariable=1;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi @PeterClemmensen. Yes, I messed up the bottom number. This solution works for both variables. Thank you for your assistance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Anytime, glad to help 🙂