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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.