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
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(...)
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(...)
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
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.