SAS - Replace the n'th word in a string, if a certain length -


i have list of customer ids, formatted follows:

123-456-78; 123-345-45; 12-234-345; 123-34-456; 

i want able find every 2-digit portion of code , replace new number. example, "78" in first entry, "12" in third entry.

right i'm using scan function loop find each 2-digit section.

data work.test12;   set mylib.customers;  i=1 5;     x=scan(customer_id,i,'-');     if length(x)=2      do;         <??????>;     end; output; end; 

i think regular expression work nicely.

33         data _null_; 34            infile cards dsd dlm=';'; 35            input s :$16.; 36            if _n_ eq 1 rx = prxparse('s/(^|-)\d\d($|-)/\100\2/'); 37            retain rx; 38            length new $16; 39            if prxmatch(rx,strip(s)) new=prxchange(rx,1,strip(s)); 40            put s= new=; 41            cards4;  s=123-456-78 new=123-456-00 s=123-345-45 new=123-345-00 s=12-234-345 new=00-234-345 s=123-34-456 new=123-00-456 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -