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.

 

SAS Innovate 2025: Call for Content

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!

Submit your idea!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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