<?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 how to do left  join in sas dataset in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/how-to-do-left-join-in-sas-dataset/m-p/144601#M38419</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a quick question I have the following code&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table want as &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select label, value&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from dataSet1 left join dataSet2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; on start&amp;lt;=value&amp;lt;=end&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; group by label&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; order start;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The thing is this code is not working if I want to replicate this sql statement using a data step how would I do this &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it should be a left join &lt;/P&gt;&lt;P&gt;data want &lt;/P&gt;&lt;P&gt; set dataSet1(in=a) dataSet2(in=b);&lt;/P&gt;&lt;P&gt;//not sure what do here&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 17 Jan 2014 12:59:23 GMT</pubDate>
    <dc:creator>johnhuang12</dc:creator>
    <dc:date>2014-01-17T12:59:23Z</dc:date>
    <item>
      <title>how to do left  join in sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-do-left-join-in-sas-dataset/m-p/144601#M38419</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a quick question I have the following code&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table want as &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select label, value&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from dataSet1 left join dataSet2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; on start&amp;lt;=value&amp;lt;=end&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; group by label&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; order start;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The thing is this code is not working if I want to replicate this sql statement using a data step how would I do this &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it should be a left join &lt;/P&gt;&lt;P&gt;data want &lt;/P&gt;&lt;P&gt; set dataSet1(in=a) dataSet2(in=b);&lt;/P&gt;&lt;P&gt;//not sure what do here&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Jan 2014 12:59:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-do-left-join-in-sas-dataset/m-p/144601#M38419</guid>
      <dc:creator>johnhuang12</dc:creator>
      <dc:date>2014-01-17T12:59:23Z</dc:date>
    </item>
    <item>
      <title>Re: how to do left  join in sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-do-left-join-in-sas-dataset/m-p/144602#M38420</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;1. Why do you want to use a data step?&lt;/P&gt;&lt;P&gt;2. Search these forums and support.sas.com - this is one of the most frequent discussions in the history of SAS...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Jan 2014 14:01:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-do-left-join-in-sas-dataset/m-p/144602#M38420</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2014-01-17T14:01:09Z</dc:date>
    </item>
    <item>
      <title>Re: how to do left  join in sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-do-left-join-in-sas-dataset/m-p/144603#M38421</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You would first need to check your syntax and error log if a piece of code does not work. If it doesn't produce expected results, then it might be a functionality does not oblige to your requirements.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table want as &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select label, value&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from dataSet1 left join dataSet2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; on start&amp;lt;=value&amp;lt;=end&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; group by label&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; order &lt;STRONG&gt;by&lt;/STRONG&gt; start;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: line-through;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There is also typically a good practice when using SQL to use the dot notation to prefix variable names as per their source i.e.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table want as &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select a.label, a.value&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from dataSet1 as a left join dataSet2 as b&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; on b.start&amp;lt;=a.value&amp;lt;=b.end&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; group by a.label&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; order &lt;STRONG&gt;by&lt;/STRONG&gt; b.start;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Additionally, I don't think (but I might be wrong here) that SQL standards use the group by statement in a similar fashion to SAS data step with a merge statement. That is, to achieve the equivalent by statement, you would normally want to have something like&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table want as &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select a.label, a.value&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from dataSet1 as a left join dataSet2 as b&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; on&amp;nbsp; &lt;STRONG&gt;a.label=b.label and&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b.start&amp;lt;=a.value&amp;lt;=b.end&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: line-through;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; group by a.label&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; order &lt;STRONG&gt;by&lt;/STRONG&gt; b.start;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Furthermore there is an ambiguity with your order by statement (At least based on my best guess of what you were trying to achieve) since the LEFT join retains records from dataset1 which did not match and thus have no start and end values tied to the record.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The SQL group by statement is used to define what summary functions "sumarize by". The general idea is that all variables in the group by statement are found in the select statement and all other variables in the select statement use sumary functions so as to generate a single record per group by unique key. Otherwise, you generate a cartesian product.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Beyond that, I must agree with LinusH. Data step is not appropriate for all merges and it is why proc sql exists and is built in sas. It might be viable depending on your data but likely not as it is even less fuzz match friendly than proc sql (the fuzz occur with start&amp;lt;=value&amp;lt;=end condition). Other data step alternatives involving hash object are more flexible in terms of what can be achieved (when compared with a merge statement) but it is best to be familiar with proc sql prior to getting into the hash object as the object has memory limitations.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps&lt;/P&gt;&lt;P&gt;Vincent&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Jan 2014 14:43:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-do-left-join-in-sas-dataset/m-p/144603#M38421</guid>
      <dc:creator>Vince28_Statcan</dc:creator>
      <dc:date>2014-01-17T14:43:23Z</dc:date>
    </item>
    <item>
      <title>Re: how to do left  join in sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-do-left-join-in-sas-dataset/m-p/144604#M38422</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;i think you can do left join in data step using Merge.Lets say I have two datasets Table1 and Table2 which have has common variable ID.We first need to sort the two datasets by ID.After Sorting the twosets we can code as :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proc Sql;&lt;/P&gt;&lt;P&gt;Create table NEW as&lt;/P&gt;&lt;P&gt;Select T1.*,T2.* from&lt;/P&gt;&lt;P&gt;Table1 as T1 left join Table2 as T2&lt;/P&gt;&lt;P&gt;on T1.id=T2.id;&lt;/P&gt;&lt;P&gt;Quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will give matching rows with the non-matching rows from left table in the new dataset NEW.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Similarly in data step:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data NEW;&lt;/P&gt;&lt;P&gt;Merge Table1(in=T1) Table2(in=T2);&lt;/P&gt;&lt;P&gt;If T1;&lt;/P&gt;&lt;P&gt;by ID;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I suppose this works.Apologies if it does not help out.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 18 Jan 2014 11:23:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-do-left-join-in-sas-dataset/m-p/144604#M38422</guid>
      <dc:creator>vivek_shr</dc:creator>
      <dc:date>2014-01-18T11:23:04Z</dc:date>
    </item>
    <item>
      <title>Re: how to do left  join in sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-do-left-join-in-sas-dataset/m-p/144605#M38423</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What do you want it to do?&amp;nbsp; Your choice of variable names makes it look like you want to create FORMAT and apply it to your data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data dataset1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; input value @@;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;cards;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;1 23 3 5 15&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data dataset2 ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; input label $ start end ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;cards;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;LOW 0 10&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;HIGH 10 100&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data fmt ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; retain fmtname 'DECODE' fmttype 'N';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; set dataset2 ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;proc format cntlin=fmt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data want;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;set dataset1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;label = put(value,decode.);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;proc print;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;Obs&amp;nbsp;&amp;nbsp;&amp;nbsp; value&amp;nbsp;&amp;nbsp;&amp;nbsp; label&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LOW&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 23&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; HIGH&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LOW&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LOW&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 15&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; HIGH&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 18 Jan 2014 18:56:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-do-left-join-in-sas-dataset/m-p/144605#M38423</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-01-18T18:56:18Z</dc:date>
    </item>
  </channel>
</rss>

