<?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 find ABS value between two variables one with 1 obs and another with 20 obs? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-ABS-value-between-two-variables-one-with-1-obs-and/m-p/79694#M17154</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You cannot merge by date as the dates do not match.&lt;/P&gt;&lt;P&gt;You could create a dummy variable that is a constant in each and merge on that (not really needed, but it you had a grouping variable it might help).&lt;/P&gt;&lt;P&gt;You could just set the single obs dataset once.&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if _n_=1 then set delivery_dataset;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set test_dataset;&lt;/P&gt;&lt;P&gt;&amp;nbsp; diff = delivery_date - test_date;&lt;/P&gt;&lt;P&gt;&amp;nbsp; absdiff = abs(diff);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Probably easiest to just use PROC SQL.&lt;/P&gt;&lt;P&gt;proc sql noprint ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table want as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select a.delivery_date,b.test_date,a.delivery_date-b.test_date as diff, abs(a.delivery_date - b.test_date) as absdiff&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from delivery_dataset a , test_dataset b&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; order by 4 &lt;/P&gt;&lt;P&gt;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 20 May 2013 05:09:21 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2013-05-20T05:09:21Z</dc:date>
    <item>
      <title>How to find ABS value between two variables one with 1 obs and another with 20 obs?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-ABS-value-between-two-variables-one-with-1-obs-and/m-p/79693#M17153</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a variable delivery_date with one observation and test_date with 20 observations. I'd like to find the closest date in test_date to delivery_date by find the minimum absolute difference and retain the minimum value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I merge the datasets I only get two observations paired up and get missing values for the rest. Would anyone please explain how to go about this with maybe a do loop or...???&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" height="96" style="width: 82px;"&gt;&lt;TBODY&gt;&lt;TR style="height: 15.0pt;"&gt;&lt;TD height="20" style="height: 15.0pt; width: 88pt;" width="117"&gt;delivery_date &lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15.0pt;"&gt;&lt;TD align="right" class="xl63" height="20" style="height: 15.0pt;"&gt;11/16/2011&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15.0pt;"&gt;&lt;TD align="right" class="xl63" height="20" style="height: 15.0pt;"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15.0pt;"&gt;&lt;TD align="right" class="xl63" height="20" style="height: 15.0pt;"&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="width: 95px;"&gt;&lt;TBODY&gt;&lt;TR style="height: 15.0pt;"&gt;&lt;TD height="20" style="height: 15.0pt; width: 71pt;" width="95"&gt;Test_date&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15.0pt;"&gt;&lt;TD align="right" class="xl65" height="20" style="height: 15.0pt;"&gt;13-Mar-11&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15.0pt;"&gt;&lt;TD align="right" class="xl65" height="20" style="height: 15.0pt;"&gt;10-Apr-11&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15.0pt;"&gt;&lt;TD align="right" class="xl65" height="20" style="height: 15.0pt;"&gt;20-May-11&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15.0pt;"&gt;&lt;TD align="right" class="xl65" height="20" style="height: 15.0pt;"&gt;9-Jun-11&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15.0pt;"&gt;&lt;TD align="right" class="xl65" height="20" style="height: 15.0pt;"&gt;31-Jul-11&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15.0pt;"&gt;&lt;TD align="right" class="xl65" height="20" style="height: 15.0pt;"&gt;17-Aug-11&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15.0pt;"&gt;&lt;TD align="right" class="xl65" height="20" style="height: 15.0pt;"&gt;12-Sep-11&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15.0pt;"&gt;&lt;TD align="right" class="xl65" height="20" style="height: 15.0pt;"&gt;10-Nov-11&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15.0pt;"&gt;&lt;TD align="right" class="xl65" height="20" style="height: 15.0pt;"&gt;11-Oct-11&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15.0pt;"&gt;&lt;TD align="right" class="xl65" height="20" style="height: 15.0pt;"&gt;12-Dec-11&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15.0pt;"&gt;&lt;TD align="right" class="xl65" height="20" style="height: 15.0pt;"&gt;29-Feb-12&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15.0pt;"&gt;&lt;TD align="right" class="xl65" height="20" style="height: 15.0pt;"&gt;13-Mar-13&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15.0pt;"&gt;&lt;TD align="right" class="xl65" height="20" style="height: 15.0pt;"&gt;10-Apr-10&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15.0pt;"&gt;&lt;TD align="right" class="xl65" height="20" style="height: 15.0pt;"&gt;20-May-10&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15.0pt;"&gt;&lt;TD align="right" class="xl65" height="20" style="height: 15.0pt;"&gt;9-Jun-10&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15.0pt;"&gt;&lt;TD align="right" class="xl65" height="20" style="height: 15.0pt;"&gt;21-Jul-11&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15.0pt;"&gt;&lt;TD align="right" class="xl65" height="20" style="height: 15.0pt;"&gt;15-Aug-11&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15.0pt;"&gt;&lt;TD align="right" class="xl65" height="20" style="height: 15.0pt;"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15.0pt;"&gt;&lt;TD align="right" class="xl65" height="20" style="height: 15.0pt;"&gt;19-Oct-11&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15.0pt;"&gt;&lt;TD align="right" class="xl65" height="20" style="height: 15.0pt;"&gt;21-Nov-11&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15.0pt;"&gt;&lt;TD align="right" class="xl65" height="20" style="height: 15.0pt;"&gt;22-Dec-11&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 20 May 2013 03:38:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-ABS-value-between-two-variables-one-with-1-obs-and/m-p/79693#M17153</guid>
      <dc:creator>Sandy</dc:creator>
      <dc:date>2013-05-20T03:38:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to find ABS value between two variables one with 1 obs and another with 20 obs?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-ABS-value-between-two-variables-one-with-1-obs-and/m-p/79694#M17154</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You cannot merge by date as the dates do not match.&lt;/P&gt;&lt;P&gt;You could create a dummy variable that is a constant in each and merge on that (not really needed, but it you had a grouping variable it might help).&lt;/P&gt;&lt;P&gt;You could just set the single obs dataset once.&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if _n_=1 then set delivery_dataset;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set test_dataset;&lt;/P&gt;&lt;P&gt;&amp;nbsp; diff = delivery_date - test_date;&lt;/P&gt;&lt;P&gt;&amp;nbsp; absdiff = abs(diff);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Probably easiest to just use PROC SQL.&lt;/P&gt;&lt;P&gt;proc sql noprint ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table want as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select a.delivery_date,b.test_date,a.delivery_date-b.test_date as diff, abs(a.delivery_date - b.test_date) as absdiff&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from delivery_dataset a , test_dataset b&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; order by 4 &lt;/P&gt;&lt;P&gt;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 20 May 2013 05:09:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-ABS-value-between-two-variables-one-with-1-obs-and/m-p/79694#M17154</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-05-20T05:09:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to find ABS value between two variables one with 1 obs and another with 20 obs?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-ABS-value-between-two-variables-one-with-1-obs-and/m-p/79695#M17155</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Tom&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 20 May 2013 12:33:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-ABS-value-between-two-variables-one-with-1-obs-and/m-p/79695#M17155</guid>
      <dc:creator>Sandy</dc:creator>
      <dc:date>2013-05-20T12:33:37Z</dc:date>
    </item>
  </channel>
</rss>

