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

Hi, I have learned that the default length of a numeric variable is 8. However, when I use the length statement on a numeric variable, it returns 12.

 

data test;
a = 1;
len = length(a);
run;

The result is 12:

i1001.png

 

Does anyone know why?

 

Thanks,

Sam

1 ACCEPTED SOLUTION

Accepted Solutions
RichardDeVen
Barite | Level 11

LENGTH is a character function. You are asking for the character length of a numeric variable. A read of the LENGTH documentation will tell you:

 

If string is a numeric constant, variable, or expression (either initialized or uninitialized), SAS automatically converts the numeric value to a right-justified character string by using the BEST12. format. In this case, LENGTH returns a value of 12 and writes a note in the SAS log stating that the numeric values have been converted to character values.

Important take away.... read the log.

View solution in original post

3 REPLIES 3
RichardDeVen
Barite | Level 11

LENGTH is a character function. You are asking for the character length of a numeric variable. A read of the LENGTH documentation will tell you:

 

If string is a numeric constant, variable, or expression (either initialized or uninitialized), SAS automatically converts the numeric value to a right-justified character string by using the BEST12. format. In this case, LENGTH returns a value of 12 and writes a note in the SAS log stating that the numeric values have been converted to character values.

Important take away.... read the log.

kisumsam
Quartz | Level 8
Great thanks!
Tom
Super User Tom
Super User

You are comparing apples and oranges.

The LENGTH() function returns the length of a value, not the storage length of the variable.  Use the VLENGTH() function to find out the defined storage length for a variable.  The reason you get 12 is because the LENGTH() function works on character strings, not numbers.  SAS will convert the number to a character string using the BEST12 format.  So no matter what numeric value you try to pass to the LENGTH() function the answer will always be 12.

CFC_SAS_Communities_400x225.jpg

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 3469 views
  • 2 likes
  • 3 in conversation