Hi experts
I have a table like this
| Id | Name | Percentage |
| 1 | Ricardo | 100 |
| 2 | Jose | 100 |
| 3 | Roberto | 50 |
| 3 | Alexander | 50 |
| 4 | Carlos | 100 |
| 5 | William | 50 |
| 5 | Juan | 50 |
| 6 | Alonso | 33 |
| 6 | Perez | 33 |
| 6 | Menjivar | 34 |
| 7 | Regina | 100 |
And i Want to add a column making a count like this
| Id | Name | Percentage | Count |
| 1 | Ricardo | 100 | 1 |
| 2 | Jose | 100 | 1 |
| 3 | Roberto | 50 | 1 |
| 3 | Alexander | 50 | 2 |
| 4 | Carlos | 100 | 1 |
| 5 | William | 50 | 1 |
| 5 | Juan | 50 | 2 |
| 6 | Alonso | 33 | 1 |
| 6 | Perez | 33 | 2 |
| 6 | Menjivar | 34 | 3 |
| 7 | Regina | 100 |
1 |
Do you have any idea how to make it ?
data want;
set have;
by id;
if first.id
then count = 1;
else count + 1;
run;
The SUM Statement in the ELSE implies an automatic RETAIN of the new variable.
data want;
set have;
by id;
if first.id
then count = 1;
else count + 1;
run;
The SUM Statement in the ELSE implies an automatic RETAIN of the new variable.
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.