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

Hi all,

I need to  generate the unique random number(dummy number) for character variable ID and it want to generate same number if  it as same value.

The length of the Id has 26 but in the output dummy Id i would like to have only 15 character.

I have tried the below code but am not getting the answer what i expected.Please help me.

data test;
input id $;
datalines;
193684370_00000001325585921261_43329
193684370_00000001325580292526_40630
195983065_00000001325664113980_33853
193684319_00000001322303549331_21813
195983065_00000001325579363334_29482
;
run;

      data test1;                                                   
            set test;                                
                              id2=translate(id,'WQSVXTYRZU','0123456789');
                       run;

Thanks for your help.

1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

data test;
input id $ 1-36;
datalines;
193684370_00000001325585921261_43329
193684370_00000001325580292526_40630
195983065_00000001325664113980_33853
193684319_00000001322303549331_21813
195983065_00000001325579363334_29482
;
run;
data test1; 
length id2 $ 15;
   set test;                                
id2=catx('-',translate(scan(id,1,'_'),'WQSVXTYRZU','0123456789'),translate(scan(id,3,'_'),'WQSVXTYRZU','0123456789'));
run;
proc print;run;
                        obs          id2                           id

                   1     QUVYZXVRW-XVVSU    193684370_00000001325585921261_43329
                   2     QUVYZXVRW-XWYVW    193684370_00000001325580292526_40630
                   3     QUTUZVWYT-VVZTV    195983065_00000001325664113980_33853
                   4     QUVYZXVQU-SQZQV    193684319_00000001322303549331_21813
                   5     QUTUZVWYT-SUXZS    195983065_00000001325579363334_29482

View solution in original post

2 REPLIES 2
Linlin
Lapis Lazuli | Level 10

data test;
input id $ 1-36;
datalines;
193684370_00000001325585921261_43329
193684370_00000001325580292526_40630
195983065_00000001325664113980_33853
193684319_00000001322303549331_21813
195983065_00000001325579363334_29482
;
run;
data test1; 
length id2 $ 15;
   set test;                                
id2=catx('-',translate(scan(id,1,'_'),'WQSVXTYRZU','0123456789'),translate(scan(id,3,'_'),'WQSVXTYRZU','0123456789'));
run;
proc print;run;
                        obs          id2                           id

                   1     QUVYZXVRW-XVVSU    193684370_00000001325585921261_43329
                   2     QUVYZXVRW-XWYVW    193684370_00000001325580292526_40630
                   3     QUTUZVWYT-VVZTV    195983065_00000001325664113980_33853
                   4     QUVYZXVQU-SQZQV    193684319_00000001322303549331_21813
                   5     QUTUZVWYT-SUXZS    195983065_00000001325579363334_29482

raveena
Obsidian | Level 7

Thanks Linlin.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 856 views
  • 0 likes
  • 2 in conversation