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

I would like to assign ascending count for observations above certain value by id and start with the first observation of the id by 1 regardless of the value and continue the count if value is above 5 the output would be like:

iddaysevent_count
A11
A50
A20
A40
A72
A50
A83
A20
A10
A164
B11
B50
B20
B40
B72
B50
B83
B20
B10
B164
B40
B50
B30
B40
B75
B86
B87

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
data want;
    set have;
    by id;
    if first.id then count=1;
    if days>5 then count+1;
    if days>5 or first.id then event_count=count;
    else event_count=0;
    drop count;
run;
--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26
data want;
    set have;
    by id;
    if first.id then count=1;
    if days>5 then count+1;
    if days>5 or first.id then event_count=count;
    else event_count=0;
    drop count;
run;
--
Paige Miller
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
  • 2 replies
  • 1061 views
  • 0 likes
  • 2 in conversation