String to numeric lopping off last 2 digits

Solved
Frequent Contributor
Posts: 124

String to numeric lopping off last 2 digits

Greetings all.  I've got some string data that are numbers left padded with zeros.  In the source DB2 table they are decimal(10,0), but I am getting them from an Oracle database that includes text in the same column, and all the numeric data are zero padded to 10 characters long.  I though I could simply use input, but that is lopping off the right 2 characters.  This is what I am trying...

data _null_ ;

string = '0123456789' ;

num = input(string,8.) ;

put num ;

run ; quit ;

I would expect the value of num to be 123456789, but it is ending up being 1234567.  I'm not sure why this is not working.  Any ideas?  Thank you.

Greg

Accepted Solutions
Solution
‎02-05-2014 04:12 PM
Frequent Contributor
Posts: 124

Re: String to numeric lopping off last 2 digits

DOH!  I was thinking that 8. would allow for the greatest number possible, but 10. works.

All Replies
Solution
‎02-05-2014 04:12 PM
Frequent Contributor
Posts: 124

Re: String to numeric lopping off last 2 digits

DOH!  I was thinking that 8. would allow for the greatest number possible, but 10. works.

Super User
Posts: 13,583

Re: String to numeric lopping off last 2 digits

Don't forget to count the decimal point when reading decimal values as well.

Reading 1234.567  with 7.3 will also disappoint. (Hint: 1234.56 is 7 characters).

Frequent Contributor
Posts: 124

Re: String to numeric lopping off last 2 digits

So if I'm getting this right, for a 10 digit number, I need to use a numeric variable with length 6., but in the input statement I need to use 10 to specify the number of characters?

Posts: 3,852

Re: String to numeric lopping off last 2 digits

I would not bother to make ANY numeric variable length LT 8.  The W for an INFORMAT should be GE the longest string of digit characters, signs, decimals, commas and dollar signs being read.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
• 4 replies
• 281 views
• 6 likes
• 3 in conversation