## Assigning random Alphanumeric IDs to empty cells

Solved
Occasional Contributor
Posts: 17

# Assigning random Alphanumeric IDs to empty cells

Hi,

I have an existing table which contains a column listing IDs. However some of its cells contain an empty ID:

ID         Age

XYS        29

60

STW       55

WTR      36

45

I would like to assign Alphanumeric IDs (20 digits) to these empty cells in order for them to be filled, but never repeated. This should also happen, irrespectively of the number of rows of the data set, as follows:

ID               Age

XYSRW        29

RAND1         60

STWQT        55

WTRWQ       36

RAND2         45

Can somebody help me on this issue, with a simple statement that fills automatically these empty fields randomly?

Thank you so much.

Fernando

Accepted Solutions
Solution
‎04-21-2016 05:00 AM
Super User
Posts: 9,599

## Re: Assigning random Alphanumeric IDs to empty cells

Hi,

```data want (drop=cnt);
set have;
retain cnt;
if _n_=1 then cnt=1;
if missing(id) then do;
id=cats("RAND",put(cnt,best.));
cnt=cnt+1;
end;
run;```

All Replies
Solution
‎04-21-2016 05:00 AM
Super User
Posts: 9,599

## Re: Assigning random Alphanumeric IDs to empty cells

Hi,

```data want (drop=cnt);
set have;
retain cnt;
if _n_=1 then cnt=1;
if missing(id) then do;
id=cats("RAND",put(cnt,best.));
cnt=cnt+1;
end;
run;```
Occasional Contributor
Posts: 17

## Re: Assigning random Alphanumeric IDs to empty cells

Perfect!
Thank you so much for your help, RW9.

Kind regards,
Fernando
Occasional Contributor
Posts: 17

## Re: Assigning random Alphanumeric IDs to empty cells

Please do not take into account the lenght of the ID of the fields in your answer, as it is not important.
🔒 This topic is solved and locked.