BookmarkSubscribeRSS Feed
R_Win
Calcite | Level 5
I have anumeric variable no i want the length of that numeric variable

data l;
input sal;
cards;
5449844894949849
17188
5454548978754545415
211151
run;

Dont keep $ after sal.if i keep $ after sal i am getting but i want it in numeric only
3 REPLIES 3
deleted_user
Not applicable
Hi sas_user,

int(log10(sal))+1;

will give you the length of the number, assuming no decimals. You then just need to find the maximum, either using proc sql, a data step or another proc.
Doc_Duke
Rhodochrosite | Level 12
Be careful with really long numbers. SAS stores all numbers in floating point and can only represent integers to certain level of precision. See the companion for your OS to determine the maximum length of an integer that can be represented for a particular number of bytes of storage.
deleted_user
Not applicable
If there were decimals, then, not withstanding Doc's comments, something like this might help:

data have;
input sal $ 48.;
cards;
54498448949.49849
171.88
5454548978.754545415
2111.51
run;

data _null_;
  set have end = eof;
  retain int 0;
  retain dec 0;
  array digits(2);
  digits(1) = scan(sal,1,'.');
  digits(2) = scan(sal,2,'.');
  if input(digits(1), 32.) gt int then int = digits(1);
  if input(digits(2), 32.) gt dec then dec = digits(2);
  if eof then do;
    i = compress(int(log10(int))+1);
    d = compress(int(log10(dec))+1);
    t = compress(int(log10(int))+1 + int(log10(dec))+1 + 1) || '.' || compress(int(log10(dec))+1);
    put 'NOTE: Integers: ' i ' Decimals: ' d ' suggested format: ' t;
  end;
run;

Which gave me a message like this:

NOTE: Integers: 11 Decimals: 9 suggested format: 21.9

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 12203 views
  • 1 like
  • 3 in conversation