BookmarkSubscribeRSS Feed
lulu3
Obsidian | Level 7

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!

3 REPLIES 3
Tom
Super User Tom
Super User

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
;
lulu3
Obsidian | Level 7

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.

Tom
Super User Tom
Super User

Why not use the SSN format?

data want;
  set have ;
  ssno11 = put(ssno,ssn11.);
run;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2191 views
  • 2 likes
  • 2 in conversation