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 !

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register 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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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