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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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