[SAS 7.1] Why do certain functions such as REVERSE and TRANSLATE add trailing blanks to match string length to the longest string in that field?
E.g.
1
12
123
1234
12345
When reversed, becomes
1____
21___
321__
4321_
54321
Where underscores represent blanks.
SAS pads strings with blanks to take up the assigned length.
This only becomes apparent when you're trying to do something and white space is a factor, such as string functions.
@sass_numero_uno wrote:
[SAS 7.1] Why do certain functions such as REVERSE and TRANSLATE add trailing blanks to match string length to the longest string in that field?
E.g.
1
12
123
1234
12345
When reversed, becomes
1____
21___
321__
4321_
54321
Where underscores represent blanks.
SAS pads strings with blanks to take up the assigned length.
This only becomes apparent when you're trying to do something and white space is a factor, such as string functions.
@sass_numero_uno wrote:
[SAS 7.1] Why do certain functions such as REVERSE and TRANSLATE add trailing blanks to match string length to the longest string in that field?
E.g.
1
12
123
1234
12345
When reversed, becomes
1____
21___
321__
4321_
54321
Where underscores represent blanks.
Do you know why this happens?
They don't ADD any spaces. They just don't remove them.
Your description of the how REVERSE works is wrong. If you reverse a string of length 5 then the original trailing spaces will now be at the beginning.
Perhaps you started with values that had LEADING spaces? Perhaps as the output of the PUT() function or some other numeric to character conversion?
Note that the normal PUT statement that either does not use a format or uses the generic character format $ will remove leading/trailing spaces while writing. You can use a different format to see the spaces. Like $CHAR or $QUOTE format.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.