Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- General Programming
- /
- Proc SQL and getting the length of a number

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-08-2013 01:42 PM

Hi

Is it possible to get the lenght of a number in proc sql. Even better if the number of decmail places is included.

I tried converting the number to a character and then getting the length. But this automatically rounded the numbers removing the decimal places. Which is not what I want

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-08-2013 02:14 PM

So, you would want length=*infinity* for irrational numbers such as Pi and e, as well as for rational numbers with infinite decimal expansions such as 1/3?

PG

PG

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-08-2013 03:06 PM

You could try something like this . . .adapt to make it work with your data . . . .

/* generate some random numbers for illustration */

data have ;

drop i;

do i = 1 to 100;

id + 1;

x = round(ranuni(i)*10000,.01);

OUTPUT;

END;

RUN;

/* convert number to character and determine length */

/* note: result will be dependent on number of decimals and includes decimal point */

proc sql;

select t.*, strip(put(t.x, 12.2)) as xchar format=$15., length (strip(put(t.x, 12.2))) as lenxchar

from have t;

quit ;