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

Hi Guys,

 

I find that I am in need of some advice again…

I have to join two tables, t1 has an 11 digit number, t2 is a matching number, but the string is only between 6 and 11 digits.  If starting from the last number in the string (the furthest right number) the numbers will match. i.e.  Both number are formatted as a character ($12.)

 

T1

T2

                                                     00000456789

                                                               456789

                                                     00003456789

                                                             3456789

                                                     00023456789

                                                           23456789

 

How do I add 0’s to the string in T2 to make it an 11 digit number?  Or is there a better way to join them?

 

I’m very new to all of this, so if you could explain it as if speaking to a child, that would be great.

 

Thanks in advance for your time,

 

paul

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Make them the same, either strip leading 0 or add leading zero. 

Add leading 0

 

put( var, z11.) 

 

Remove leading 0

 

input(var, best12.) 

 

You can either create a new variable and merge using the new variable or do conversion on join condition if using SQL. 

Eg:

T1= put(...)

 

View solution in original post

3 REPLIES 3
Reeza
Super User

Make them the same, either strip leading 0 or add leading zero. 

Add leading 0

 

put( var, z11.) 

 

Remove leading 0

 

input(var, best12.) 

 

You can either create a new variable and merge using the new variable or do conversion on join condition if using SQL. 

Eg:

T1= put(...)

 

Reeza
Super User

Sorry, missed portion about T2 already being character. 

You can convert to numeric to implement solution or use repeat to generate number of 0 based on length and concatenate VM,yes. 

 

Untested

 

Repeat(0, 11-length(t2)) ||  t2

pandhandj
Obsidian | Level 7
Hi Reeza, thanks for your input. I worked it out from what you said above. Initially the shorter number was Numeric, I had changed it in a previous step. So I went pack there and padded the 0's to the front and it worked great. thanks for your time, paul

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 4186 views
  • 0 likes
  • 2 in conversation