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

I am sure this is easy, but I have been trying to figure it out and can't. I have a list of IDs, where some of them are duplicates. What I want is to number all of the ids so that they have a number next to them identifying which observation is which based on some sort criteria.

 

Data:

 

ID       Numeric_Var

1                 5

2                28

2                42

3                  2

3                  9

3                 74

 

 

And I want a new variable so that my data looks like this:

 

ID       Numeric_Var         Count

1                 5                        1

2                28                       1

2                42                       2

3                  2                       1

3                  9                       2

3                 74                      3

 

Any help would be great.

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

If you don't mind sorting the data (assuming it is not currently in order of the ID variable);

 

proc sort data=have; by id; run;

 

data want;

   set have;

   by id;

   retain count; /* I would probably use something more like sequencenumber ...*/

   if first.id then count=1;

   else count+1;

run;

 

View solution in original post

2 REPLIES 2
ballardw
Super User

If you don't mind sorting the data (assuming it is not currently in order of the ID variable);

 

proc sort data=have; by id; run;

 

data want;

   set have;

   by id;

   retain count; /* I would probably use something more like sequencenumber ...*/

   if first.id then count=1;

   else count+1;

run;

 

jacob_klimek
Obsidian | Level 7

Perfect great thanks!

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 2 replies
  • 680 views
  • 0 likes
  • 2 in conversation