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_ID | Count |
100024 | 1 |
100040 | 1 |
100040 | 2 |
100040 | 3 |
895060879 | 1 |
895060879 | 2 |
895060879 | 3 |
895060879 | 4 |
895060879 | 5 |
895060879 | 6 |
895060879 | 7 |
895060879 | 8 |
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;
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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.