Could you please tell me the use of substr function for numerical values is it same as for charecters. Here is example
data work.AreaCodes;
Phonenumber=3125551212;
Code='('!!substr(Phonenumber,1,3)!!')';
run;
No, you can't use substr with numeric data. If you run the code you included above, you'll get a message like this:-
NOTE: Numeric values have been converted to character values at the places given by:
What you should do is convert the data to text as Dblan showed above.
Also, for things like telephone numbers, you should use a text field anyway, not a numeric. Numeric fields only have a maximum of 8 bytes to store the number. Once the number gets above a certain magnitude, it starts suffering from rounding issues. For actual numeric data this possibly isn't such a big deal, however a telephone number that has been rounded to the nearest 3 is totally useless. This also applies to account numbers, credit card numbers, and in fact, I'd say ANY number which is a code rather than a value should be stored as a character field.
I have hit upon this issue before, and it's difficult to track down.
Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.