Many times you have a variable in SAS that is character and you want to convert it to numeric. This tends to come up a lot when importing from Excel. Excel shows a number, but SAS reads the column in as a character variable.

It is a bit difficult to *replace* the original character variable with a numeric one, but it is trivial to create a new numeric variable. Just use the input() function.

The syntax is:

numericVar = input(charVar, informat.);

NumericVar is the numeric variable you are hoping to create.

CharVar is the character variable that holds the 'number'.

Informat is a numeric informat that tells SAS how to translate the numeric 'characters' into a useful number. Dates are often used to illustrate this concept:

data _null_;

charDate = '01mar06';

numDate = input(charDate, date7.);

run;

In the above case, date7. tells SAS how to interpret the character string '01mar06'

into a number (in this case, the number of days since Jan 01, 1960).

Of course your character variable can be something as simple as '1234'. In that case this would work:

data _null_;

charVar = '1234';

numvAR = input(charVar, 4.);

run;

People often confuse the input() function with the put() function. I always

remembered by emphasizing the n sound with this little refrain:

__In__put

__In__to

__N__umeric.