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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.