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

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