BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Jose7
Obsidian | Level 7

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 ?

1 ACCEPTED SOLUTION

Accepted Solutions
2 REPLIES 2
Kurt_Bremser
Super User
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.

Jose7
Obsidian | Level 7
Thks! it works !

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.

Explore Now →
How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 3169 views
  • 1 like
  • 2 in conversation