06-20-2017 11:11 AM
I have numeric variable with decimals
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?
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.
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;
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.
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.
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.