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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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