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

Hello,

In SAS where I have a data table in the work . What line of code do I use to convert a character column to text column with leading zeros. For example, in the column SSN, it has numeric digits but some don't have leading 0s. Like for example, it is has 11 instead of 0011. How do I convert all the values in that column in a character type column with leading zeros to signify the last four of a social security number.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@kmin87 wrote:

I want the last four social security with leading zeros. For example one of the value in the column is 11 in numeric format and I want it to be 0011 in character format in a new column in  a new data set


data test;
  ssn =999560011;
  lastfour = substr(put(ssn,ssn.),8);
run;

View solution in original post

3 REPLIES 3
SASKiwi
PROC Star

You don't need to convert SSNs. Try this:

data test;
  ssn = 11;
  format ssn ssn.;
  put ssn =;
run;

kmin87
Fluorite | Level 6

I want the last four social security with leading zeros. For example one of the value in the column is 11 in numeric format and I want it to be 0011 in character format in a new column in  a new data set

ballardw
Super User

@kmin87 wrote:

I want the last four social security with leading zeros. For example one of the value in the column is 11 in numeric format and I want it to be 0011 in character format in a new column in  a new data set


data test;
  ssn =999560011;
  lastfour = substr(put(ssn,ssn.),8);
run;

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!

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
  • 3 replies
  • 697 views
  • 1 like
  • 3 in conversation