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;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: