BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sass_numero_uno
Fluorite | Level 6

[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.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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.

 


 

View solution in original post

3 REPLIES 3
Reeza
Super User

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.

 


 

Tom
Super User Tom
Super User

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.

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

Creating Custom Steps in SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1093 views
  • 3 likes
  • 3 in conversation