Hi Expert,
I would like to convert character number to numeric number with dash variables.
data have;
input id $ Character $11. ;
datalines;
1 123-45-7890
2 234-65-3960
3 351-47-9012
;
run;
I tried the following code, but the numeric variable was still character.
data want;
set have;
Numeric=input(Character, $11.);
run;
One more question, I want to know how to conver character from or to numeric number if the variable include dash (-).
Thank you for your help!
Those look like Social Security numbers. Leave them as character. You will not have any reason to take the mean of a SSNO. Or add two or more of them together so there is no reason to store them as numbers.
To remove the dashes use COMPRESS() function.
data have;
length id $8 ssno11 $11 ssno $9 ;
input id ssno11 ;
ssno = compress(ssno11,'-');
datalines;
1 123-45-7890
2 234-65-3960
3 351-47-9012
;
Yes, it is SSN. I have one dateset the SSN was original stored as numeric number (etc. 123-45-6789). I want to transfer the numeric SSN to character SSN. Do you have any suggestions?
Thanks.
Why not use the SSN format?
data want;
set have ;
ssno11 = put(ssno,ssn11.);
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.