- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
;
Jag
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for your response.
Isn't possible to do it in a single line in the same prxchange rather than in two separate lines.
Jag
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
;
Jag
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
>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 ---.