<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: SQL Left Join while triming ZERO off in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SQL-Left-Join-while-triming-ZERO-off/m-p/739593#M230864</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
	create table temp as
	select * from fruit left join fruit_options 
	on input(fruit.ID_num, 8.) = fruit_options.ID_num
;
quit ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is a mistake in the example code, &lt;STRONG&gt;in both data sets id_num is read in as a numeric variable&lt;/STRONG&gt; so the leading 0 is removed from the example data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it is as shown, it would likely be a character variable, then use INPUT() to convert it on the join. If both are actually numeric you should not have any issues. Note that leading zeroes can be on a character variable. If the value is numeric with a Z format, SAS should still merge it correct, so if that's the case you have something else causing your non matches. If that is the case, please show an example of when this doesn't work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 06 May 2021 18:15:44 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-05-06T18:15:44Z</dc:date>
    <item>
      <title>SQL Left Join while triming ZERO off</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-Left-Join-while-triming-ZERO-off/m-p/739575#M230853</link>
      <description>&lt;P&gt;Hi: is it possible to trim zero off of a variable during left join.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, i want to do a left join with these two tables by ID_num. But ID_num in one table leads with zero in front of the number. Can i trim the zero while while doing a left join with it? or would i have to trim it using prxchange function then do the sql left join data step.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data fruit;&lt;BR /&gt;input ID_num Fruit_Type$ rate$;&lt;BR /&gt;datalines;&lt;BR /&gt;0123 Apples 1.2&lt;BR /&gt;0456 Oranges 1.3&lt;BR /&gt;0567 Bananas 1.4&lt;BR /&gt;0890 Pineapples 1.5&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data fruit_options;&lt;BR /&gt;input ID_num Fruit_Type2$ Add_on$ Price$;&lt;BR /&gt;datalines;&lt;BR /&gt;123 Oranges wine 75&lt;BR /&gt;456 Watermelon cheese 25&lt;BR /&gt;567 Plum cheese 50&lt;BR /&gt;890 OneFruit wine 35&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 06 May 2021 17:22:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-Left-Join-while-triming-ZERO-off/m-p/739575#M230853</guid>
      <dc:creator>Scooby3g</dc:creator>
      <dc:date>2021-05-06T17:22:30Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Left Join while triming ZERO off</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-Left-Join-while-triming-ZERO-off/m-p/739585#M230858</link>
      <description>&lt;P&gt;Ok, question why trim when ID_num is a numeric in both datasets. Which means this works:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
	create table temp as
	select * from fruit left join fruit_options 
	on fruit.ID_num = fruit_options.ID_num
;
quit ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 May 2021 17:51:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-Left-Join-while-triming-ZERO-off/m-p/739585#M230858</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2021-05-06T17:51:03Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Left Join while triming ZERO off</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-Left-Join-while-triming-ZERO-off/m-p/739587#M230860</link>
      <description>Thanks for your response!&lt;BR /&gt;What if it is in CHAR? Would I do a step like this while I only keep some variables?&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table FRUIT_basket2 as select *&lt;BR /&gt;from ((select * from fruit_options) as a&lt;BR /&gt;left join (select ID_num, Fruit_Type2 from fruit trim '0%' ) as b&lt;BR /&gt;on a.ID_num=b.ID_num);&lt;BR /&gt;quit;</description>
      <pubDate>Thu, 06 May 2021 18:03:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-Left-Join-while-triming-ZERO-off/m-p/739587#M230860</guid>
      <dc:creator>Scooby3g</dc:creator>
      <dc:date>2021-05-06T18:03:18Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Left Join while triming ZERO off</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-Left-Join-while-triming-ZERO-off/m-p/739590#M230862</link>
      <description>The reason for trimming is that sometimes with the zero present it doesn't always merge right when the datasets are large.</description>
      <pubDate>Thu, 06 May 2021 18:07:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-Left-Join-while-triming-ZERO-off/m-p/739590#M230862</guid>
      <dc:creator>Scooby3g</dc:creator>
      <dc:date>2021-05-06T18:07:36Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Left Join while triming ZERO off</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-Left-Join-while-triming-ZERO-off/m-p/739593#M230864</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
	create table temp as
	select * from fruit left join fruit_options 
	on input(fruit.ID_num, 8.) = fruit_options.ID_num
;
quit ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is a mistake in the example code, &lt;STRONG&gt;in both data sets id_num is read in as a numeric variable&lt;/STRONG&gt; so the leading 0 is removed from the example data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it is as shown, it would likely be a character variable, then use INPUT() to convert it on the join. If both are actually numeric you should not have any issues. Note that leading zeroes can be on a character variable. If the value is numeric with a Z format, SAS should still merge it correct, so if that's the case you have something else causing your non matches. If that is the case, please show an example of when this doesn't work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 May 2021 18:15:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-Left-Join-while-triming-ZERO-off/m-p/739593#M230864</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-05-06T18:15:44Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Left Join while triming ZERO off</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-Left-Join-while-triming-ZERO-off/m-p/739604#M230865</link>
      <description>&lt;P&gt;What if the variables joining are characters and one variable in a table has zeros while the other does not? In a scenario where you want to keep it as Character variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data fruit;&lt;BR /&gt;input ID_char$ Fruit_Type$ rate$;&lt;BR /&gt;datalines;&lt;BR /&gt;0123 Apples 1.2&lt;BR /&gt;0456 Oranges 1.3&lt;BR /&gt;0567 Bananas 1.4&lt;BR /&gt;0890 Pineapples 1.5&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data fruit_options;&lt;BR /&gt;input ID_char$ Fruit_Type2$ Add_on$ Price$;&lt;BR /&gt;datalines;&lt;BR /&gt;123 Oranges wine 75&lt;BR /&gt;456 Watermelon cheese 25&lt;BR /&gt;567 Plum cheese 50&lt;BR /&gt;890 OneFruit wine 35&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 06 May 2021 18:24:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-Left-Join-while-triming-ZERO-off/m-p/739604#M230865</guid>
      <dc:creator>Scooby3g</dc:creator>
      <dc:date>2021-05-06T18:24:46Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Left Join while triming ZERO off</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-Left-Join-while-triming-ZERO-off/m-p/739618#M230872</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/359105"&gt;@Scooby3g&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;What if the variables joining are characters and one variable in a table has zeros while the other does not? In a scenario where you want to keep it as Character variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data fruit;&lt;BR /&gt;input ID_char$ Fruit_Type$ rate$;&lt;BR /&gt;datalines;&lt;BR /&gt;0123 Apples 1.2&lt;BR /&gt;0456 Oranges 1.3&lt;BR /&gt;0567 Bananas 1.4&lt;BR /&gt;0890 Pineapples 1.5&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data fruit_options;&lt;BR /&gt;input ID_char$ Fruit_Type2$ Add_on$ Price$;&lt;BR /&gt;datalines;&lt;BR /&gt;123 Oranges wine 75&lt;BR /&gt;456 Watermelon cheese 25&lt;BR /&gt;567 Plum cheese 50&lt;BR /&gt;890 OneFruit wine 35&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;There are a number of approaches depending on the actual values. If the code to match on is essentially numbers where the leading zero is actually insignificant (i.e. "0123" and "00123" are not both in the data a mean something else) you can INPUT then character values in the On&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;On input(a.id,12.) = input(b.id,12.)&lt;/P&gt;
&lt;P&gt;or if only one is character and the other numeric input the character and not the numeric.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HOWEVER: if you have values like "0ABC123" and are matching "123" good luck.&lt;/P&gt;
&lt;P&gt;You can use almost any function in the ON to modify values. If &lt;STRONG&gt;all&lt;/STRONG&gt; the character values in one set have &lt;STRONG&gt;exactly one&lt;/STRONG&gt; leading zero and &lt;STRONG&gt;all&lt;/STRONG&gt; of the values in the other set have no leading zeroes you could use something like&lt;/P&gt;
&lt;P&gt;On a.id = cats('0',b.id)&amp;nbsp; to add exactly one leading 0 to the values without the leading 0.&lt;/P&gt;
&lt;P&gt;If there are random numbers of leading zeroes and the second set has some values with the leading 0 and others without then you need to provide the logic as to which values have too many or too few leading (or trailing) 0 characters.&lt;/P&gt;</description>
      <pubDate>Thu, 06 May 2021 19:09:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-Left-Join-while-triming-ZERO-off/m-p/739618#M230872</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-05-06T19:09:11Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Left Join while triming ZERO off</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-Left-Join-while-triming-ZERO-off/m-p/739619#M230873</link>
      <description>Then do the INPUT on BOTH of them, assuming they can be numeric or you need to standardize them before you join. &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 06 May 2021 19:15:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-Left-Join-while-triming-ZERO-off/m-p/739619#M230873</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-05-06T19:15:11Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Left Join while triming ZERO off</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-Left-Join-while-triming-ZERO-off/m-p/739631#M230879</link>
      <description>&lt;P&gt;Thanks all for you feedback and suggestions. It seems like the easier way to go about it is to cut the data then trim the zero using this. Then do a left join and assign what is A and what is B. I originally wanted to avoid this way because the datasets are large and I may run out of space when running it this way. &lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data fruit2;&lt;BR /&gt;set fruit;&lt;BR /&gt;ID_1= prxchange ('s/^0+//o', ID_char);&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table temp as&lt;BR /&gt;select * from Fruit2 as a&lt;BR /&gt;left join&amp;nbsp;fruit_options (keep=ID_char Fruit_Type2) as b&lt;BR /&gt;on a.ID_1=b.ID_char;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I've had issues with converting from btw with Char and Num before using the&lt;FONT color="#3366FF"&gt; Input&lt;/FONT&gt; and &lt;FONT color="#3366FF"&gt;Put&lt;/FONT&gt; functions so I am trying to avoid using those during join when possible. I was trying to go about it this way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table TEMP as select *
from ((select * from fruit where ID_num NOT LIKE '0%') as a
left join (select ID_num, Fruit_Type2, Add_on from fruit_options ) as b
on a.ID_num=b.ID_num);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 May 2021 19:54:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-Left-Join-while-triming-ZERO-off/m-p/739631#M230879</guid>
      <dc:creator>Scooby3g</dc:creator>
      <dc:date>2021-05-06T19:54:50Z</dc:date>
    </item>
  </channel>
</rss>

