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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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