<?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: How to retain all observations in a dataset when using PROC SQL to combine two datasets? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-all-observations-in-a-dataset-when-using-PROC-SQL/m-p/79706#M17162</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;using left join.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 28 Sep 2012 01:38:37 GMT</pubDate>
    <dc:creator>Linlin</dc:creator>
    <dc:date>2012-09-28T01:38:37Z</dc:date>
    <item>
      <title>How to retain all observations in a dataset when using PROC SQL to combine two datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-all-observations-in-a-dataset-when-using-PROC-SQL/m-p/79705#M17161</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I need to use proc sql to select information from one data set and match to another.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is what I did:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table merge as&lt;/P&gt;&lt;P&gt;&amp;nbsp; select * from data1 as a, data2 as b&lt;/P&gt;&lt;P&gt;&amp;nbsp; where a.var1=b.var1 and (a.var2&amp;gt; b.var4) and (a.var3&amp;lt;= b.var4);&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, after this, I would lose observations in data1 that do not satisfy the conditions "a.var1=b.var1 and (a.var2&amp;gt; b.var2) and (a.var2&amp;lt;= b.var2)“. Is there a way to retain all information in a and simply set the value of var3 to 0?&lt;/P&gt;&lt;P&gt;pro&lt;/P&gt;&lt;P&gt;Thanks a lot in advance!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Sep 2012 01:22:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-all-observations-in-a-dataset-when-using-PROC-SQL/m-p/79705#M17161</guid>
      <dc:creator>tediest</dc:creator>
      <dc:date>2012-09-28T01:22:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain all observations in a dataset when using PROC SQL to combine two datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-all-observations-in-a-dataset-when-using-PROC-SQL/m-p/79706#M17162</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;using left join.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Sep 2012 01:38:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-all-observations-in-a-dataset-when-using-PROC-SQL/m-p/79706#M17162</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2012-09-28T01:38:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain all observations in a dataset when using PROC SQL to combine two datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-all-observations-in-a-dataset-when-using-PROC-SQL/m-p/79707#M17163</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I guess it's var4 that you want to set to 0 when there is no match in data2? To do that, you can use a left join and the coalesce function, like this :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;proc sql;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&amp;nbsp; create table merge as&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&amp;nbsp; select a.*, coalesce(b.var4,0) as var4 &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&amp;nbsp; from data1 as a left join data2 as b&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&amp;nbsp; on a.var1=b.var1 and (a.var2&amp;gt; b.var4) and (a.var3&amp;lt;= b.var4);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Sep 2012 01:40:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-all-observations-in-a-dataset-when-using-PROC-SQL/m-p/79707#M17163</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2012-09-28T01:40:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain all observations in a dataset when using PROC SQL to combine two datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-all-observations-in-a-dataset-when-using-PROC-SQL/m-p/79708#M17164</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks a lot for the prompt reply! This is very helpful. I have been searching for the right command but missed "left join". &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Sep 2012 01:44:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-all-observations-in-a-dataset-when-using-PROC-SQL/m-p/79708#M17164</guid>
      <dc:creator>tediest</dc:creator>
      <dc:date>2012-09-28T01:44:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain all observations in a dataset when using PROC SQL to combine two datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-all-observations-in-a-dataset-when-using-PROC-SQL/m-p/79709#M17165</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks PG! This is exactly what I need. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Sep 2012 01:45:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-all-observations-in-a-dataset-when-using-PROC-SQL/m-p/79709#M17165</guid>
      <dc:creator>tediest</dc:creator>
      <dc:date>2012-09-28T01:45:13Z</dc:date>
    </item>
  </channel>
</rss>

