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?
Or neither, use a format. SAS even has a format...
Convert your SSN to numeric using INPUT and then apply the format.
Or neither, use a format. SAS even has a format...
Convert your SSN to numeric using INPUT and then apply the format.
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;
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.
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.