- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 06-15-2021 10:43 AM
(1209 views)
How to remove a special character in beginning and last of specific variable
Example "...Tes.t..." and needs to be "Tes.t" as compress function removes all dots
9 REPLIES 9
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
How many variables do you need to this for? If it is just that one, you could use SUBSTR.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
a lot of variables
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
ant not all variables having same length
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You need to provide more details about specifically what the rules are and how they can be applied. Otherwise I can show you a solution that will work for exactly what you post but then won't work on your actual data.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
let me clarify more
i have values like (....abd.de..,..wer..r..,etc) as system out put
i need to remove the dots only in the begining and end of each record and keep the dots as it is between the words to be like below
abd.de
wer..r
i have values like (....abd.de..,..wer..r..,etc) as system out put
i need to remove the dots only in the begining and end of each record and keep the dots as it is between the words to be like below
abd.de
wer..r
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
i think i found a solution as below
var1=tranwrd(variable,'.',' ');
final=tranwrd(srtip(var1),' ','.');
run;
it works 🙂
thanks 🙂
var1=tranwrd(variable,'.',' ');
final=tranwrd(srtip(var1),' ','.');
run;
it works 🙂
thanks 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
That replaces your dots in the middle with spaces which wasn't what you said you wanted to do.
data have;
input string $20.;
cards;
.....abd.de..
..wer..r...
..dum..test....
;;;;
run;
data want;
set have;
start=anyalpha(string);
end=anyalpha(left(reverse(string)));
want = substr(string, start, length(string) - end - start + 2);
var1=tranwrd(string,'.',' ');
final=tranwrd(strip(string),' ','.');
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You probably want to use TRANSLATE() so you can swap the periods and spaces and then swap them back. If you want to remove the trailing periods from values that last have trailing spaces then use TRIM() on the value first.
You can then apply that to a series of variables by using an ARRAY.
For example you could try it on all of the character variables.
data want ;
set have;
array _c _character_;
do over _c;
_c=translate(strip(translate(trim(_c),'. ',' .')),'. ',' .');
end;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data have; input string $20.; want=prxchange('s/^\.+|\.+$//',-1,strip(string)); cards; ...Tes.t... .....abd.de.. ..wer..r... ..dum..test.... ;;;; run;