[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.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.