Hi,
I simply would like to set a new Var "Counter" thats count to 12 (in the example below to 3) by the ID. I mean within the same ID, it can be hundred of them, I would like to count the rows by 12 (equivalent to months), each time gets to 12 then reset to 1 again until 12, to the end of the rows until ID changes. So this counter repeat itself in the same way for each new ID.
I imagine is simply, my problem is I am only learning!!! Thank you a lot for your help. Bernardita
| ID | Counter |
| A | 1 |
| A | 2 |
| A | 3 |
| A | 1 |
| A | 2 |
| A | 3 |
| A | 1 |
| A | 2 |
| A | 3 |
| A | 1 |
| B | 1 |
| B | 2 |
| B | 3 |
| B | 1 |
| B | 2 |
| B | 3 |
| B | 1 |
| B | 2 |
| B | 3 |
| B | 1 |
| B | 2 |
| C | 1 |
| C | 2 |
| C | 3 |
| C | 1 |
| C | 2 |
| C | 3 |
| C | 1 |
| C | 2 |
| C | 3 |
| C | 1 |
| C | 2 |
Hi,
Yep, pretty simple - I will go by your given example below:
data want; set have; by id; retain counter; if first.id or counter > 3 then counter=0; else counter=counter+1; run;
Hi,
Yep, pretty simple - I will go by your given example below:
data want; set have; by id; retain counter; if first.id or counter > 3 then counter=0; else counter=counter+1; run;
This is great!!! Thank you a lot!
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.