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

Hi there, I have the following data:

 

1 1

2 1

3 1

4 1

5 1

6 2 

7 2

8 1 

9 1

10 3

11 3

12 3 

13 4

14 4

15 4

16 4

 

etc

where column 1 is userid and column 2 is whether it is unique or not (thus, users 13-16 are duplicates, 10-12 are duplicates, and 6 and 7 are duplicates. I need an output variable labeling each user as a unique value, so something like this:

 

1 1 1

2 1 2

3 1 3

4 1 4

5 1 5

6 2 6

7 2 6 

8 1 7

9 1 8

10 3 9

11 3 9

12 3 9 

13 4 10

14 4 10

15 4 10

16 4 10

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

That is a strange structure. Also what are the NAMES of those variables?

data want ;
  set have ;
  by var2 notsorted ;
  var3 + (first.var2 or var2=1);
run;

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

That is a strange structure. Also what are the NAMES of those variables?

data want ;
  set have ;
  by var2 notsorted ;
  var3 + (first.var2 or var2=1);
run;
richart
Fluorite | Level 6

I agree it's strange, why I needed to find a way out of it. And you have provided just that! Cheers!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1120 views
  • 0 likes
  • 2 in conversation