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

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 622 views
  • 0 likes
  • 2 in conversation