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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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