05-18-2015 09:40 AM
I am trying to join two datasets on an ID variable present in both datasets. However, in one dataset, the ID is formatted to always be at least 3 digits by adding leading 0s if the ID is only a 1- or 2-digit number (so like 001, 050, 067, etc). In the other dataset, the ID variable does not have the leading 0s, and the same values that I used as examples before would be 1, 50, 67, etc. I'm not sure how to match on these values considering the mismatch. Trimming the 0s would be difficult because some IDs have two leading 0s, some one leading 0, and others zero leading 0s. Within each dataset, the IDs have different lengths (either 3 or 4).
Any help is much appreciated.
05-18-2015 10:00 AM
Personally I would convert the two to numeric for comparison:
create table WANT as
from HAVE A
left join ANOTHER_HAVE B
Note that it assumes both are character. If they are number, or one or the other is number, no need to input it.
05-18-2015 10:16 AM
Make SQL's join be more powerful by prxmatch . I am going to write a paper about it .Waiting ...................
input k $;
input k $ flag;
create table want as
from a left join b on prxmatch(cats('/^0*',b.k,'/'),a.k);