turn on suggestions

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
- /
- Length of numeric variable

Topic Options

- 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
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-20-2017 11:11 AM

I have numeric variable with decimals

data l;

input number;

cards;

54498.014

17188.12647

54545

211151.127287128718

run;

need to see the length of numeric variable in SAS SQL commond without put commond or with commond along with suppressing addional zeros.

Can any one help me to code this in SAS SQL please?

Number Length

54498.014 9

17188.12647 11

54545 5

211151.127312345 16

123456789012345678.1 20

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

Posted in reply to prakashpk

06-20-2017 11:44 AM

At least your last example won't work, as SAS numeric values have a precision of ~15 digits.

Google "SAS numeric precision" for in-depth information.

Otherwise, you can only determine the length from strings, and therefore will need the put() function.

---------------------------------------------------------------------------------------------

Maxims of Maximally Efficient SAS Programmers

Maxims of Maximally Efficient SAS Programmers

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

Posted in reply to prakashpk

06-20-2017 12:04 PM

Adding to Kurt,

You can read in the data as a character variable and just use the length function in the data step.

```
data l;
input number $50.;
number_length = length(number);
cards;
54498.014
17188.12647
54545
211151.127287128718
123456789012345678.1
;
run;
```

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

Posted in reply to Rwon

06-21-2017 03:53 AM

Thank you Rwon for your reply

Actually i know how to write in Data step, but i want to understand how it is written in SAS SQL format as i have data which comes from the server and need to see one of the attribute length, whether it is exceeding 19 which includes . and decimals. or number contains more than 6 decimal numbers. can you please send me SAS SQL code which i can use for this case.

Regards,

Prakash

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

Posted in reply to prakashpk

06-21-2017 04:03 AM

I guess that by "server" you mean a database system? In that case, you have a problem, as 19 digits go beyond the maximum precision available to SAS (~15 digits, as already mentioned), and numbers like that will not be correctly represented in SAS anyway.

I suggest you do a typecast in the database (SQL pass-through), and import into SAS as strings (character).

Or you have the table exported to a flat file from the DBMS, and then read the column as character with a SAS data step.

---------------------------------------------------------------------------------------------

Maxims of Maximally Efficient SAS Programmers

Maxims of Maximally Efficient SAS Programmers

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

Posted in reply to prakashpk

06-21-2017 05:53 AM

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

Posted in reply to prakashpk

06-21-2017 06:05 AM

The closest you'll get using proc sql is:

select length(NUMBER,best32. -l) from HAVE;

but that's a weird request, and you'll get surprises due to numeric precision as explained above.