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

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

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;
Escada
Obsidian | Level 7
Perfect!
Thank you so much for your help, RW9.

Kind regards,
Fernando
Escada
Obsidian | Level 7
Please do not take into account the lenght of the ID of the fields in your answer, as it is not important.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Discussion stats
  • 3 replies
  • 2241 views
  • 0 likes
  • 2 in conversation