Methinks using the "multiplication method" is a poor practice: It results in an implicit character-to-numeric type conversion and pollutes the log with a corresponding note "Character values have been converted to numeric values...". Besides, if the input is not a valid number, it will pollute the log even more with two more notes: "Invalid numeric data..." and "Missing values were generated...".
It's always much cleaner to use the INPUT function with a corresponding informat preceded by the ?? modifier. This way, you get a clean log without any vagaries and can test the result for a missing value if need be to find out if the informat has failed to interpret the input as a number or not.
Kind regards
Paul D.
> I tried using this method to convert into number and it worked.
You can only say "it worked" if you disregard message in the log. And you should never ignore log messages.
A good program generates a clean log. A bad program doesn't.
I fully agree on the fact clean log belongs to good programming practices. A reason for that is that when a real bug occurs, we want to make sure to only get messages related to that bug to fix it. It makes life easier.
Having said that, the input function returs a numeric value only when a numeric informat is used, not when a character informat is is used.
Finally, here is an example where an input function does not just convert from character to numeric! So, be careful!
data _null_;
x =input('200.',10.6);
y1=input('200',10.6);
y2=200/1000000;
put x=;
put y1=;
put y2=;
run;
In informats, the decimal fraction (the "d" value in all format documentations) should only be used when no decimal separator is supplied, but a defined number of fractional digits is used. Typical in mainframe data files where 000012345 often means 123 dollars and 45 cents.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.