Hi Experts,
I would like to replace the 'UN' and 'UNK' two strings with '--' and '---' with prxchange. Could you please help me with the code.
I tried
new=prxchange('s/(\bUN\b)|(\bUNK\b)/---/',-1,date);
data have;
input date &$100.;
cards;
UN UNK 2018
;
Like this...
data have;
input date &$100.;
length new $ 100;
/*new = prxchange('s/\bUNK\b/---/', -1, date);*/
/*new = prxchange('s/\bUN\b/--/', -1, new);*/
new = prxchange('s/\bUN\b/--/', -1, prxchange('s/\bUNK\b/---/', -1, date));
cards;
UN UNK 2018
;
data have;
input date &$100.;
length new $ 100;
new = prxchange('s/\bUNK\b/---/', -1, date);
new = prxchange('s/\bUN\b/--/', -1, new);
cards;
UN UNK 2018
;
Thanks for your response.
Isn't possible to do it in a single line in the same prxchange rather than in two separate lines.
Like this...
data have;
input date &$100.;
length new $ 100;
/*new = prxchange('s/\bUNK\b/---/', -1, date);*/
/*new = prxchange('s/\bUN\b/--/', -1, new);*/
new = prxchange('s/\bUN\b/--/', -1, prxchange('s/\bUNK\b/---/', -1, date));
cards;
UN UNK 2018
;
I was working on the prxchange and thought we could simplify the code when compared to accepted solution. Instead of using two prxchange we can do it with one prxchange as below
data have;
input date &$100.;
date2=prxchange('s/(UN\s)(UNK\s)(\d*)/-- --- $3/i',-1,strip(date));
cards;
UN UNK 2018
;
data have;
input date &$100.;
date2=prxchange('s/(UN\s)(UNK\s)(\d*)/-- --- $3/i',-1,strip(date));
cards;
UN UNK 2018
UN 2018
UNK 2018
UN
UNK
;
In the above, the first line in the CARDS statement works, but the next 4 fail.
>Isn't possible to do it in a single line in the same prxchange rather than in two separate lines.
It is possible if the replacement string is not changing, for example always ---.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.