Reputation: 1
I can not find the way to reverse text strings.
For example I want to reverse these:
MMMM121231M34
to become 43M132121MMMM
MM1M11M1
to become 1M11M1MM
1111213111
to become 1113121111
Upvotes: 0
Views: 52
Reputation: 1792
Judging from your examples, what you mean by 'rearrange' is actually 'reverse'.
In that case, you've got the very handy reverse()
function in SAS.
Used in context:
data test;
length text $32;
infile datalines;
input text $;
result=reverse(strip(text));
datalines;
MMMM121231M34
MM1M11M1
1111213111
;
run;
EDIT on @Joe's request: in the particular example above, I create the test
dataset by setting a length of 32 characters for the text
variable. Therefore, when reading the values from datalines
, these are padded with blanks up to that total of 32 characters. Hence, when reversing that value, the result has that many blanks at the start, followed by the actual value you are looking for. By adding the strip
function, you remove the excess blanks from the value of text
before reversing, keeping only the "real" value in the result.
Upvotes: 1