Discover More Tips and Techniques on This Blog

Length of Numeric variables GT 8 in SAS| StudySAS BLOG

Q&A: numeric variables length more than 8? We all know that the default length of the numeric variables in SAS is 8 and if suppose I want to store a number lets say (12345678910, which has a length 11 to numeric variable) to variable total, what should I do?


What if the numeric variable digits are more than 12 digits and i want to store them all without any E values?

ANS)

The default length of numeric variables in SAS is 8 and all the numbers that we see in the sas datasets are called as floating numbers(floating point binary) and not a regular sequence numbers form 1 to 10. When we are using SAS/Windows as our operating system and then the minimum length for any numeric variable should be 3(not 1 as we get confused all the time). So if a variable contas less than 3 digits means it is stored with less space.

The reason is, since a numeric variable will need a power and and the sign(+ or -), if SAS want to store a numberit defenitely needs a minimum of 3 bytes.

Depending upon the operating system we are using for SAS, the range for numeric variables can be 2 to 8 or 3 to 8.

Since the type of floating-point values is upto 16 decimal digits. we can store numbers upto 16(1234567891012234) total 16 digits for a numeric variable, but that can be possible if we use a format statement.

Ex:
data dsn;

a=1234567891012234;
format a best16.;run;


 
If we open the output, we can see all the 16 digits were stored for the variable a exactly in the dataset dsn.

If the the value of numeric variable is upto 12 disgits we don't require to specify any formats, if it is more than 12 digits we have to mention specify the format statement. without it we will see error in the system log.

6 comments:

  1. CRM Segmentation and Clustering Using SAS Enterprise Miner (Sas Press Series) by Randall S. Collica (Paperback - Jun 4, 2007)

    Do you have this book?
    http://www.amazon.com/Segmentation-Clustering-Using-Enterprise-Miner/dp/1590475089/ref=sr_1_1?ie=UTF8&s=books&qid=1234502810&sr=1-1

    ReplyDelete
  2. sarath, can't we use 'Length' statement instead?

    ReplyDelete
  3. by default .... all numeric values can have a max...length 8...

    length statement .. wont.. work... if the ..value is more than 8 digits...

    ReplyDelete
  4. what is the length of two numeric variables which are concatenated using || operator.

    ReplyDelete
  5. When you concatenate 2 numeric variables using concatenate operator ||(pipe) the resultant variable you get is a character variable.... Length of the new variable ... is $24....

    ReplyDelete
  6. how did u get length as 24 can u explain it in detail?

    ReplyDelete

Disclosure:

In the spirit of transparency and innovation, I want to share that some of the content on this blog is generated with the assistance of ChatGPT, an AI language model developed by OpenAI. While I use this tool to help brainstorm ideas and draft content, every post is carefully reviewed, edited, and personalized by me to ensure it aligns with my voice, values, and the needs of my readers. My goal is to provide you with accurate, valuable, and engaging content, and I believe that using AI as a creative aid helps achieve that. If you have any questions or feedback about this approach, feel free to reach out. Your trust and satisfaction are my top priorities.