<?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: SAS Merge using proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-Merge-using-proc-sql/m-p/524581#M142659</link>
    <description>&lt;P&gt;&amp;nbsp;They can both be matched since we want to know whom in B are similar to those in A.&lt;/P&gt;</description>
    <pubDate>Fri, 04 Jan 2019 15:31:16 GMT</pubDate>
    <dc:creator>GeetVish</dc:creator>
    <dc:date>2019-01-04T15:31:16Z</dc:date>
    <item>
      <title>SAS Merge using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Merge-using-proc-sql/m-p/524574#M142652</link>
      <description>&lt;P&gt;&amp;nbsp;I have two datasets A and B with a common column severity. I need to identify which row of B has the severity closest to the severity of the each row of A. It is called the nearest neighbor problem.&lt;/P&gt;&lt;P&gt;I am&amp;nbsp; reading in both A and B and then for each row of A search for the nearest neighbor in B using a do loop. However, I am not sure how to create index for B so that a do loop can be done.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Please NOTE : There are no common variables&amp;nbsp; and the subjects are in different studies. The purpose of the analysis is to figure out who in B is the closest subject to each one in A.&amp;nbsp;.&amp;nbsp;&lt;/P&gt;&lt;P&gt;In terms of disease severity.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The final output should be below:-- please HELP AND URGENT :-&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Severity_A&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;subject_A&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&l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…&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help will be greatly appreciated. Thank you very much!&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jan 2019 15:15:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Merge-using-proc-sql/m-p/524574#M142652</guid>
      <dc:creator>GeetVish</dc:creator>
      <dc:date>2019-01-04T15:15:12Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Merge using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Merge-using-proc-sql/m-p/524578#M142656</link>
      <description>&lt;P&gt;Actual data to go with your desired results would be helpful.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you need unique nearest neighbors?&amp;nbsp; Meaning that if in Set A we have severity values of 1.3 and 1.5, and in Set B we have a 1.4 and a 2.7.&amp;nbsp; Can the 1.3 and the 1.5 both be matched to the 1.4 or do we need to use unique values?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jan 2019 15:26:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Merge-using-proc-sql/m-p/524578#M142656</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2019-01-04T15:26:44Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Merge using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Merge-using-proc-sql/m-p/524579#M142657</link>
      <description>&lt;P&gt;Please clarify the apparent inconsistency in your text:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/164865"&gt;@GeetVish&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;I have two datasets A and B &lt;FONT color="#0000ff"&gt;&lt;STRONG&gt;with a common column severity&lt;/STRONG&gt;&lt;/FONT&gt;. I need to identify which row of B has the severity closest to the severity of the each row of A. It is called the nearest neighbor problem.&lt;/P&gt;
&lt;P&gt;I am&amp;nbsp; reading in both A and B and then for each row of A search for the nearest neighbor in B using a do loop. However, I am not sure how to create index for B so that a do loop can be done.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Please NOTE : &lt;FONT color="#ff0000"&gt;&lt;STRONG&gt;There are no common variables&amp;nbsp;&lt;/STRONG&gt;&lt;/FONT&gt; and the subjects are in different studies. The purpose of the analysis is to figure out who in B is the closest subject to each one in A.&amp;nbsp;.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In terms of disease severity.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please provide examples of appropriate variables from BOTH input data sets, best as data step code to ensure we have the correct names and types. Then provide example output expected from that example input. Your example output as shown also does not show a "nearest neighbor" result but a "five nearest neighbors" result. If the desire is 5 nearest then please say so as that is a significantly different problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since Proc Sql does not support do loops I am having a hard time imagining what you may be contemplating.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jan 2019 15:27:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Merge-using-proc-sql/m-p/524579#M142657</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-01-04T15:27:09Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Merge using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Merge-using-proc-sql/m-p/524581#M142659</link>
      <description>&lt;P&gt;&amp;nbsp;They can both be matched since we want to know whom in B are similar to those in A.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jan 2019 15:31:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Merge-using-proc-sql/m-p/524581#M142659</guid>
      <dc:creator>GeetVish</dc:creator>
      <dc:date>2019-01-04T15:31:16Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Merge using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Merge-using-proc-sql/m-p/524583#M142661</link>
      <description>&lt;P&gt;Dataset A:&lt;BR /&gt;Severity subject&lt;BR /&gt;1.2 1&lt;BR /&gt;2.3 2&lt;BR /&gt;3.4 3&lt;BR /&gt;5.3 4&lt;BR /&gt;6.7 5&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;Dataset B:&lt;BR /&gt;Severity subject&lt;BR /&gt;1.5 6&lt;BR /&gt;2.6 7&lt;BR /&gt;4.5 8&lt;BR /&gt;5.1 9&lt;BR /&gt;5.7 10&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jan 2019 15:32:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Merge-using-proc-sql/m-p/524583#M142661</guid>
      <dc:creator>GeetVish</dc:creator>
      <dc:date>2019-01-04T15:32:35Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Merge using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Merge-using-proc-sql/m-p/524589#M142663</link>
      <description>&lt;P&gt;can you help me ?&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jan 2019 16:11:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Merge-using-proc-sql/m-p/524589#M142663</guid>
      <dc:creator>GeetVish</dc:creator>
      <dc:date>2019-01-04T16:11:28Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Merge using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Merge-using-proc-sql/m-p/524591#M142665</link>
      <description>&lt;P&gt;&lt;SPAN&gt;can you help me ?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jan 2019 16:11:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Merge-using-proc-sql/m-p/524591#M142665</guid>
      <dc:creator>GeetVish</dc:creator>
      <dc:date>2019-01-04T16:11:43Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Merge using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Merge-using-proc-sql/m-p/524603#M142670</link>
      <description>&lt;P&gt;Without knowing your expected output we can only have our best guess. Try this.&lt;/P&gt;&lt;P&gt;To get to the final results uncomment the commented code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data A;
input Severity subject;
cards;
1.2 1
2.3 2
3.4 3
5.3 4
6.7 5
;
run;
   
Data B;
input Severity subject;
cards;
1.5 6
2.6 7
4.5 8
5.1 9
5.7 10
;
run;

proc sql;
create table c as
	select 	a.Severity as A_Severity
	,		a.Subject as A_Subject
	,		b.Severity as B_Severity
	,		b.Subject as B_Subject
	,		abs(A.Severity - B.Severity) as Distance
	from 	work.A as A
	,		work.B as B

/*	group by a.Subject*/
/*	having calculated Distance = min(Calculated Distance)*/
	order by A_Subject, Calculated Distance
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Jan 2019 16:32:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Merge-using-proc-sql/m-p/524603#M142670</guid>
      <dc:creator>DanielLangley</dc:creator>
      <dc:date>2019-01-04T16:32:45Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Merge using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Merge-using-proc-sql/m-p/524611#M142672</link>
      <description>&lt;P&gt;Thanks a lot , I will let you know if this is matching with requirement. But really appreciate your response and help&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jan 2019 16:39:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Merge-using-proc-sql/m-p/524611#M142672</guid>
      <dc:creator>GeetVish</dc:creator>
      <dc:date>2019-01-04T16:39:56Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Merge using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Merge-using-proc-sql/m-p/524616#M142674</link>
      <description>&lt;P&gt;the answer is perfect, Thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jan 2019 16:46:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Merge-using-proc-sql/m-p/524616#M142674</guid>
      <dc:creator>GeetVish</dc:creator>
      <dc:date>2019-01-04T16:46:52Z</dc:date>
    </item>
  </channel>
</rss>

