DATA Step, Macro, Functions and more

Counting observations by ID

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 18
Accepted Solution

Counting observations by ID

Hi All,

 

I have data set as below where I have client_id. I would like to count them as below. I would like to get the count variable as follows

CLIENT_IDCount
1000241
1000401
1000402
1000403
8950608791
8950608792
8950608793
8950608794
8950608795
8950608796
8950608797
8950608798

Accepted Solutions
Solution
‎01-25-2018 01:31 PM
Super User
Posts: 13,046

Re: Counting observations by ID

If the data is sorted by your id variable you could use:

 

data want;

    set have;

    by client_id;

    if first.client_id then count=1;

    else count+1;

run;

View solution in original post


All Replies
Solution
‎01-25-2018 01:31 PM
Super User
Posts: 13,046

Re: Counting observations by ID

If the data is sorted by your id variable you could use:

 

data want;

    set have;

    by client_id;

    if first.client_id then count=1;

    else count+1;

run;

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 176 views
  • 0 likes
  • 2 in conversation