BookmarkSubscribeRSS Feed
noda6003
Quartz | Level 8

is there any program where i can check the maximum length of float/integer variables including decimals.

 I found one link but it uses P21 metadata sheet. I just need to check the max length used in all datasets in a folder and get the significant digit.

 

Any help

8 REPLIES 8
Kurt_Bremser
Super User

The maximum number of decimal digits that SAS can work with reliably is between 15 and 16.

 

What you want to do is mathematically impossible, as a simple fraction like 1/3 already has an infinite number of decimal digits by definition.

A very large integer wiil cause SAS to display in scientific notation (even with the best32. format, if the number is larger than 1E33), so the number of characters will not be what you want.

noda6003
Quartz | Level 8

I have specification which has all dataset names with format as float and length as 8 and what i want is to check the datasets maximum length of variable and if it is 5.1 then i want to overwrite my specification with significant value in this case as 5.1 instead of 8

noda6003
Quartz | Level 8

 need to get the below from datasets

float Num The largest allowable whole
number width plus the maximum
number of decimal digits.

Patrick
Opal | Level 21

@noda6003 wrote:

 need to get the below from datasets

float Num The largest allowable whole
number width plus the maximum
number of decimal digits.


The format of a SAS variable only influences how a value gets printed/written. It has no influence on how the value gets stored internally.

The way you formulate your question makes me feel that you're eventually trying to do something that doesn't really make sense. Have a read of the docu here and if you then still feel that what you want to do makes sense then eventually reformulate your question and ask here again.  

Kurt_Bremser
Super User

You confuse the length and the format.

The length is the number of bytes used to store the number in binary floating encoding, the format determines how the stored value is displayed.

I guess you want to determine the longest format(!) used in your datasets and then set this in all datasets. Is that correct? 

noda6003
Quartz | Level 8

Sorry for confusing.

 

I want to know The largest allowable whole number width plus the maximum number of decimal digits in each variable 

Kurt_Bremser
Super User

The largest integer that can be represented with 8 bytes floating point is approximately 2 * 10 ** 308 (308 - 309 digits). See the wikipedia entry on floating point arithmetic. Only the 16 most significant digits would be represented accurately, of course.

You can look for the maximal value in a given column, but the maximla number of digits is irrelevant (as already noted, 1/3 has an infinite numbef of decimal digits).

In light of all this, make up your mind what you really want to achieve and restate your question. If possible, make up an example.

ballardw
Super User

@noda6003 wrote:

I have specification which has all dataset names with format as float and length as 8 and what i want is to check the datasets maximum length of variable and if it is 5.1 then i want to overwrite my specification with significant value in this case as 5.1 instead of 8


The statement "dataset names with format as float and length as 8" typically doesn't make much sense in SAS as data set names can't start with digits. Do you mean variables within data sets or are you dealing with an external DBMS.

 

Also display formats, which are easy to find, do not affect the actual values stored. So more "digits" may be stored than the default format displays.

data example;
   x=123.12345;
   format x f5.1;
run;
/* which will default to showing 123.1*/
proc print data=example;
run;
/* but more digits can be displayed when requested*/
proc print data=example;
   format x best12.;
run;

Length, when referring to SAS numeric variables is the number of bytes used for storage and is limited to the integers 3 through 8. Please look in the SAS documentation for the limits of storage given a number of bytes.

Large economy size hint: if the values contain any decimals you want to stay with 8.

 

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!

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.

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
  • 8 replies
  • 1723 views
  • 0 likes
  • 4 in conversation