Random generating ID

Accepted Solution Solved
Reply
Contributor
Posts: 37
Accepted Solution

Random generating ID

I am trying to figure out if there is a way to automate the process of assigning random IDs to a set of over 170K records. - is there a SAS function that do this for me? I have found some random ID creation code, but what I have found creates decimals and alphanumeric IDs and I cannot specify a specific range. I need this ID to be 20 characters long (all numeric).

 

Thank you for any help you can provide.


Accepted Solutions
Solution
‎01-29-2016 09:59 AM
Super User
Posts: 9,875

Re: Random generating ID

Check UUIDGEN() 

 

 

data _null_;
do i=1 to 20;
x=uuidgen();
put x=;
end;
run;

View solution in original post


All Replies
Contributor
Posts: 37

Re: Random generating ID

Also, these need to be unique ids
Super User
Posts: 5,388

Re: Random generating ID

Does it need to be unique?
Can you clarify the underlying requirement?
Data never sleeps
Super Contributor
Posts: 490

Re: Random generating ID

Yes PROC PLAN can do it 

Example:

proc plan seed=0;
  factors id=170000 /noprint;
  output out=IDs;
run;

data yes;
input x $ y$;
cards;
d f
h i
p o
;
run; 
data want; set IDs; set yes; run;
Contributor
Posts: 37

Re: Random generating ID

Yes,  they need to be unique for linkage purposes. Each id will be a person across different datasets and it needs to be all numbers 20 in length
Super User
Posts: 11,134

Re: Random generating ID

[ Edited ]

The result may contain digits but it will not be a number as 20 digits will exceed the storage precision of SAS.

data _null_;

x=1234567891234567890;

y=1234567891234567899;

put x= best32. y= best32.;

run;

 

I would consider if you have a number of fields if combined would work to concatenate them.

If this is for linkage purposes, how are you going to get the values into multiple datasets if they are random?

Solution
‎01-29-2016 09:59 AM
Super User
Posts: 9,875

Re: Random generating ID

Check UUIDGEN() 

 

 

data _null_;
do i=1 to 20;
x=uuidgen();
put x=;
end;
run;
Super User
Posts: 5,388

Re: Random generating ID

And do you need the to be 20 num long?
Data never sleeps
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 467 views
  • 1 like
  • 5 in conversation