Record Counter

Reply
Contributor
Posts: 74

Record Counter

How do I create a counter that will roll through the sorted data set and count the number of occurrences of one record and assign that value in a variable?  I have to count the number of times a record had a call in a given day.

thanks,

SAS Employee
Posts: 340

Re: Record Counter

An easy but slow way is to (re)sort your data by id (record identifier) and date-time. Then use a data step, that initializes the counter at each ID group start (and at each day start if you have more days in the data) and then simply increment that counter at each observation. Then you can (back)sort your data by date-time if needed.

Another approach, if your data is already sorted by date-time (and you don't want to re-sort), to use a hash object that holds the counter for each id.

Ask a Question
Discussion stats
  • 1 reply
  • 161 views
  • 0 likes
  • 2 in conversation