BookmarkSubscribeRSS Feed
Nlr
Calcite | Level 5 Nlr
Calcite | Level 5
Hi!

How do you write the 'length' statement in the expression builder? Can it be used when you have a character column?
2 REPLIES 2
ChrisHemedinger
Community Manager
Are you trying to calculate the length of the character value? If so, you can use an expression like this in your calculated column:

LENGTHC( )

For example, if you want to calculate the length of each Name value in SASHELP.CLASS, use this:

LENGTHC(Name)

If you want to make sure that trailing blanks aren't counted, use this:

LENGTHC(TRIM(Name))

Chris
SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
ChrisNZ
Tourmaline | Level 20

If I understand the question correctly, you can either force the length with a put statement:

put( scan(VAR,1), $32.)

or (possibly; untested) add the length after the expression

scan(VAR,1)   length = 32

 

 

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
  • 2 replies
  • 2570 views
  • 0 likes
  • 3 in conversation