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

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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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