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!
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;
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;
I agree it's strange, why I needed to find a way out of it. And you have provided just that! Cheers!
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.