Solved
Contributor
Posts: 40

# 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).

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

## Re: Random generating ID

Check UUIDGEN()

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

All Replies
Contributor
Posts: 40

## Re: Random generating ID

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

## 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: 40

## 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: 13,517

## 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: 10,770

## Re: Random generating ID

Check UUIDGEN()

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

## Re: Random generating ID

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