Hi:
Look in the documentation for the topics:
Functions and CALL Routines
INPUT Function
The bottom line is that to convert a CHARACTER variable to a number, you use the INPUT function like this:
newnumvar = INPUT(oldcharvar,numeric-informat.); (DATA step) OR INPUT(oldcharvar,numeric-informat.) as newnumvar (SQL)
So you were ALMOST right in your INPUT statement. Think of it this way, in order to turn your old character variable into a NEW numeric variable, you have to give the NUMERIC INformat to use.
See the example below.
cynthia
** make some data;
** ssnc is a 9 position character variable with SSN;
** ssn is a numeric variable;
data testit;
name = 'alan';
ssn = 123456789;
ssnc = '123456789';
output;
name = 'bob';
ssn = 002334444;
ssnc = '002334444';
output;
run;
ods listing;
proc sql ;
select name, ssn format=ssn11., ssnc,
input(ssnc,9.) as newssn format=ssn11.
from work.testit;
quit;
and the output:
name ssn ssnc newssn ----------------------------------------- alan 123-45-6789 123456789 123-45-6789 bob 002-33-4444 002334444 002-33-4444
Hi:
Look in the documentation for the topics:
Functions and CALL Routines
INPUT Function
The bottom line is that to convert a CHARACTER variable to a number, you use the INPUT function like this:
newnumvar = INPUT(oldcharvar,numeric-informat.); (DATA step) OR INPUT(oldcharvar,numeric-informat.) as newnumvar (SQL)
So you were ALMOST right in your INPUT statement. Think of it this way, in order to turn your old character variable into a NEW numeric variable, you have to give the NUMERIC INformat to use.
See the example below.
cynthia
** make some data;
** ssnc is a 9 position character variable with SSN;
** ssn is a numeric variable;
data testit;
name = 'alan';
ssn = 123456789;
ssnc = '123456789';
output;
name = 'bob';
ssn = 002334444;
ssnc = '002334444';
output;
run;
ods listing;
proc sql ;
select name, ssn format=ssn11., ssnc,
input(ssnc,9.) as newssn format=ssn11.
from work.testit;
quit;
and the output:
name ssn ssnc newssn ----------------------------------------- alan 123-45-6789 123456789 123-45-6789 bob 002-33-4444 002334444 002-33-4444
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.