BookmarkSubscribeRSS Feed
timmy555
Calcite | Level 5

I have a dataset in which the social security number names the variable soc is in the format 55555555. But I need it to be the usually for

 

 

5 REPLIES 5
SASKiwi
PROC Star

I suspect your variable SOC is character. It needs to be a number to apply the SSN format:

data want;
  set have (obs= 10);
  socialsecurity=input(soc, best12.);
  format socialsecurity ssn11.;
  put socialsecurity = ;
run;
timmy555
Calcite | Level 5

is there another way to apply the dashes through a function procedure?

timmy555
Calcite | Level 5

I figured it our thankyou needs the input and put function. 

Jagadishkatam
Amethyst | Level 16

You can also try the perl regular expression incase you havent tried the code i posted.

Thanks,
Jag
Jagadishkatam
Amethyst | Level 16

Please try the below untested code

 

data have;
x='555555555';
y=prxchange('s/(\d{3,3})(\d{2,2})(\d{4,4})/$1-$2-$3/',-1,x);
run;
Thanks,
Jag

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 492 views
  • 0 likes
  • 3 in conversation