<?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: tagging in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/tagging/m-p/43982#M9016</link>
    <description>One have to be careful when joining tables. In most cases you wish to join on key columns, that is the on/where-clause should contain unique values at least in on of the tables being joined, otherwise there might unpredictable results. Has var3 unique vales? Please attach some example data (of both input and expected output).&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
Linus</description>
    <pubDate>Fri, 05 Sep 2008 07:40:25 GMT</pubDate>
    <dc:creator>LinusH</dc:creator>
    <dc:date>2008-09-05T07:40:25Z</dc:date>
    <item>
      <title>tagging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/tagging/m-p/43981#M9015</link>
      <description>Hello,&lt;BR /&gt;
&lt;BR /&gt;
let's say i have tables a and b.&lt;BR /&gt;
&lt;BR /&gt;
a has var1 var2 and b has var3 var4&lt;BR /&gt;
&lt;BR /&gt;
then i need to create a table that adds a column to table a named tag which depends on the first 5 chars of var1. so when substr(var1,1,5) is equal to a certain value of var3 then tag = var4.&lt;BR /&gt;
&lt;BR /&gt;
here's the code:&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
select * from a left join b&lt;BR /&gt;
on substr(var1,1,5) = var3;&lt;BR /&gt;
quit; &lt;BR /&gt;
&lt;BR /&gt;
assuming that there are only two values for var4. how come when i create a table that separates the two values of var3, their total count is different to the whole?&lt;BR /&gt;
&lt;BR /&gt;
i feel i wasn't able to explain it well but if you understood what i'm trying to talk about your help is much appreciated. is there wrong with my code? or logic? or other thing? thanks a lot! &lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt;</description>
      <pubDate>Fri, 05 Sep 2008 07:08:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/tagging/m-p/43981#M9015</guid>
      <dc:creator>milts</dc:creator>
      <dc:date>2008-09-05T07:08:29Z</dc:date>
    </item>
    <item>
      <title>Re: tagging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/tagging/m-p/43982#M9016</link>
      <description>One have to be careful when joining tables. In most cases you wish to join on key columns, that is the on/where-clause should contain unique values at least in on of the tables being joined, otherwise there might unpredictable results. Has var3 unique vales? Please attach some example data (of both input and expected output).&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
Linus</description>
      <pubDate>Fri, 05 Sep 2008 07:40:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/tagging/m-p/43982#M9016</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2008-09-05T07:40:25Z</dc:date>
    </item>
    <item>
      <title>Re: tagging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/tagging/m-p/43983#M9017</link>
      <description>Your question is one of performing a lookup.  In SQL creating a table with a resolved lookup generally involves the use of a LEFT JOIN.&lt;BR /&gt;
&lt;BR /&gt;
data one;&lt;BR /&gt;
  length var1 var2 $8;&lt;BR /&gt;
  input var1 var2;&lt;BR /&gt;
datalines;&lt;BR /&gt;
abcdef qwerty&lt;BR /&gt;
bcdefg tyuiop&lt;BR /&gt;
cdefgh zxcvb&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data two;&lt;BR /&gt;
  length var3 var4 $8;&lt;BR /&gt;
  input var3 var4;&lt;BR /&gt;
datalines;&lt;BR /&gt;
abcde Richard&lt;BR /&gt;
xyzab Linus&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  create table one_tagged as&lt;BR /&gt;
  select &lt;BR /&gt;
    one.*&lt;BR /&gt;
  , two.var4 as tag&lt;BR /&gt;
  from &lt;BR /&gt;
    one&lt;BR /&gt;
  left join&lt;BR /&gt;
    two&lt;BR /&gt;
  on &lt;BR /&gt;
    substr(one.var1,1,5) = two.var3&lt;BR /&gt;
  ;&lt;BR /&gt;
quit; &lt;BR /&gt;
&lt;BR /&gt;
Note that these types of joins are often utilized as a VIEW stored in a permanent library (create view instead of create table).  That way the join is always upto date.&lt;BR /&gt;
&lt;BR /&gt;
Furthermore, this type of lookup (left join) can also be accomplished using custom formats.  A common use of formats is to map a range of values to some other value (a lookup)&lt;BR /&gt;
&lt;BR /&gt;
Richard A. DeVenezia&lt;BR /&gt;
&lt;A href="http://www.devenezia.com" target="_blank"&gt;http://www.devenezia.com&lt;/A&gt;</description>
      <pubDate>Wed, 10 Sep 2008 15:30:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/tagging/m-p/43983#M9017</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2008-09-10T15:30:57Z</dc:date>
    </item>
  </channel>
</rss>

