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

Hello all,

 

I am trying to assign random numbers to a given set of IDs. The reason for assinging random numbers to the IDs is to de-identify the information from the IDs. There should not be any relationship between the IDs and the Random numbers generated from them. For example: 

 

if I have a set of IDs as: 

 

IDs Random Numbers
15768
15768
22749
22749
22749
59574
59574
59574

 

The random numbers in the above tables are just the examples. These numbers can be any given number until and unless there is no relationship between the IDs and Random numbers. The only intention for decoding the IDs is to secure the information. Again, these random numbers cannot be used to lookback the IDs.

 

Thank you

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

data have;
input id;
cards;
1
1
2
2
2
3
4
5
5
;
run;
data want;
 set have;
 by id;
 retain ran;
 if first.id then ran=ceil(1000000000000*ranuni(0));
run;

View solution in original post

4 REPLIES 4
Ksharp
Super User

data have;
input id;
cards;
1
1
2
2
2
3
4
5
5
;
run;
data want;
 set have;
 by id;
 retain ran;
 if first.id then ran=ceil(1000000000000*ranuni(0));
run;
danwarags
Obsidian | Level 7

Thanks Ksharp. This code works. If I wanted to assign random numbers in particular range how should I modify the code. For example for a given set of 2000 IDs I want to assign random numbers in the range 100000- 102000. How should I do this. For example:

 

ObsID
11456
23765
335632
489564
           .            .
           .            .
           .            .
2000580058

 

My output should look something like: 

 

ObsIDRandom
11456100000
23765101997
335632101456
489564100002
.. 
.. 
.. 
2000580058102000

 

In the above example, the number of observations in the dataset are 2000. The Random numbers are assigned such that they are in particular range i.e 100000-102000. 

 

Thanks for your help

Ksharp
Super User


data have;
 do obs=1 to 2000;
  output;
 end;
run;
data temp;
 set have;
 ran=ranuni(0);
run;
proc rank data=temp out=want;
 var ran;
 ranks r;
run;
data want;
 set want;
 random=100001+r;
 drop r;
run;



Ksharp
Super User
Last code is not right. Try this one:



data have;
 do obs=1 to 2000;
  output;
 end;
run;
data temp;
 set have;
 ran=ranuni(0);
run;
proc rank data=temp out=want;
 var ran;
 ranks r;
run;
data want;
 set want;
 random=100000+r;
 drop r;
run;

proc sql;
select count(distinct random),max(random),min(random) from want;quit;


sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 2994 views
  • 1 like
  • 2 in conversation