BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
marianhabesland
Calcite | Level 5

I am supposed to create a variable called SSN2. I currently have a variable called SSN that has the social security numbers in a format XXXXXXXXX, and want SSN2 to be in the format XXX-XX-XXXX, in other words adding hyphens in specific positions. I have tried using the CATX function, but I don't know if this is even the right function as I am just splitting the one variable up. Should I instead be using the SUBSTR function?

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Or neither, use a format. SAS even has a format...

https://support.sas.com/documentation/cdl/en/leforinforref/64790/HTML/default/viewer.htm#n1sroiq0fql...

 

Convert your SSN to numeric using INPUT and then apply the format. 

 

 

View solution in original post

2 REPLIES 2
Reeza
Super User

Or neither, use a format. SAS even has a format...

https://support.sas.com/documentation/cdl/en/leforinforref/64790/HTML/default/viewer.htm#n1sroiq0fql...

 

Convert your SSN to numeric using INPUT and then apply the format. 

 

 

TarunKumar
Pyrite | Level 9

 

 

data have;
input ss_no $9.;
datalines;
absdefght
abadefght
absdefgtk
absdefgtp
absdefert
asedrftgh
potrpshrt
;run;

data want;
set have;
ss_no_new = catx("-",substr(ss_no,1,3),substr(ss_no,4,2),substr(ss_no,6,4));
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2 replies
  • 6628 views
  • 2 likes
  • 3 in conversation