<?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 Join 2 tables by prioritizing the data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Join-2-tables-by-prioritizing-the-data/m-p/949456#M371403</link>
    <description>&lt;P&gt;I need to join the below 2 tables on Key. in the first table I have key1 and In the second table, I have key2, Rank and Contact data.&lt;/P&gt;
&lt;P&gt;In the final table, I need Rank1 data in contact1 and if Rank1 is not there, I need to check next Rank for contact1 data. If Rank1 data comes to contact1, then I shouldn't consider Rank1 for contact2 and contact3. Is there a way to do using proc sql?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Table A:&lt;/P&gt;
&lt;DIV class="s-table-container"&gt;
&lt;TABLE class="s-table"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH&gt;Key1&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;1234&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3456&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;P&gt;Table B&lt;/P&gt;
&lt;DIV class="s-table-container"&gt;
&lt;TABLE class="s-table"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH&gt;Key2&lt;/TH&gt;
&lt;TH&gt;Rank&lt;/TH&gt;
&lt;TH&gt;contact&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;1234&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;owner&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1234&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;co-owner&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1234&lt;/TD&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;CEO&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3456&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;co-owner&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3456&lt;/TD&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;CEO&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;P&gt;Final Table:&lt;/P&gt;
&lt;DIV class="s-table-container"&gt;
&lt;TABLE class="s-table"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH&gt;key&lt;/TH&gt;
&lt;TH&gt;contact1&lt;/TH&gt;
&lt;TH&gt;contact2&lt;/TH&gt;
&lt;TH&gt;contact3&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;1234&lt;/TD&gt;
&lt;TD&gt;owner&lt;/TD&gt;
&lt;TD&gt;co-owner&lt;/TD&gt;
&lt;TD&gt;CEO&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3456&lt;/TD&gt;
&lt;TD&gt;co-owner&lt;/TD&gt;
&lt;TD&gt;CEO&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;</description>
    <pubDate>Wed, 30 Oct 2024 09:34:55 GMT</pubDate>
    <dc:creator>gandikk</dc:creator>
    <dc:date>2024-10-30T09:34:55Z</dc:date>
    <item>
      <title>Join 2 tables by prioritizing the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-2-tables-by-prioritizing-the-data/m-p/949456#M371403</link>
      <description>&lt;P&gt;I need to join the below 2 tables on Key. in the first table I have key1 and In the second table, I have key2, Rank and Contact data.&lt;/P&gt;
&lt;P&gt;In the final table, I need Rank1 data in contact1 and if Rank1 is not there, I need to check next Rank for contact1 data. If Rank1 data comes to contact1, then I shouldn't consider Rank1 for contact2 and contact3. Is there a way to do using proc sql?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Table A:&lt;/P&gt;
&lt;DIV class="s-table-container"&gt;
&lt;TABLE class="s-table"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH&gt;Key1&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;1234&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3456&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;P&gt;Table B&lt;/P&gt;
&lt;DIV class="s-table-container"&gt;
&lt;TABLE class="s-table"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH&gt;Key2&lt;/TH&gt;
&lt;TH&gt;Rank&lt;/TH&gt;
&lt;TH&gt;contact&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;1234&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;owner&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1234&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;co-owner&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1234&lt;/TD&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;CEO&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3456&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;co-owner&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3456&lt;/TD&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;CEO&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;P&gt;Final Table:&lt;/P&gt;
&lt;DIV class="s-table-container"&gt;
&lt;TABLE class="s-table"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH&gt;key&lt;/TH&gt;
&lt;TH&gt;contact1&lt;/TH&gt;
&lt;TH&gt;contact2&lt;/TH&gt;
&lt;TH&gt;contact3&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;1234&lt;/TD&gt;
&lt;TD&gt;owner&lt;/TD&gt;
&lt;TD&gt;co-owner&lt;/TD&gt;
&lt;TD&gt;CEO&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3456&lt;/TD&gt;
&lt;TD&gt;co-owner&lt;/TD&gt;
&lt;TD&gt;CEO&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 30 Oct 2024 09:34:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-2-tables-by-prioritizing-the-data/m-p/949456#M371403</guid>
      <dc:creator>gandikk</dc:creator>
      <dc:date>2024-10-30T09:34:55Z</dc:date>
    </item>
    <item>
      <title>Re: Join 2 tables by prioritizing the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-2-tables-by-prioritizing-the-data/m-p/949457#M371404</link>
      <description>&lt;P&gt;First, I don't think you can do this entirely in SQL (without multiple joins which could be extremely slow on real-world large data sets)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second, since I believe strongly that you are better off with long data sets rather than wide data sets (&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_self"&gt;Maxim 19&lt;/A&gt;), here is the solution that produces a long data set from this data. (Which is also easy in SQL)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
     merge tableA tableB(rename=(key2=key1));
     by key1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2024 10:21:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-2-tables-by-prioritizing-the-data/m-p/949457#M371404</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-10-30T10:21:09Z</dc:date>
    </item>
    <item>
      <title>Re: Join 2 tables by prioritizing the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-2-tables-by-prioritizing-the-data/m-p/949463#M371405</link>
      <description>&lt;P&gt;I agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;here.&lt;/P&gt;
&lt;P&gt;The only (?) reason to do it in SQL if your (large) data resides in an external databbase, so you can push the query there.&lt;/P&gt;
&lt;P&gt;Then you need to join with table B three times, and using Rank in the join criterias.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2024 12:03:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-2-tables-by-prioritizing-the-data/m-p/949463#M371405</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2024-10-30T12:03:02Z</dc:date>
    </item>
    <item>
      <title>Re: Join 2 tables by prioritizing the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-2-tables-by-prioritizing-the-data/m-p/949464#M371406</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674"&gt;@LinusH&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;here.&lt;/P&gt;
&lt;P&gt;The only (?) reason to do it in SQL if your (large) data resides in an external databbase, so you can push the query there.&lt;/P&gt;
&lt;P&gt;Then you need to join with table B three times, and using Rank in the join criterias.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That assumes there are only 3 values of rank, which may or may not be known beforehand. Anyway, if you create a long data set, you could do a PROC TRANSPOSE to get a wide data set and then you don't need to know beforehand how many values of rank there are.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2024 12:06:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-2-tables-by-prioritizing-the-data/m-p/949464#M371406</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-10-30T12:06:22Z</dc:date>
    </item>
    <item>
      <title>Re: Join 2 tables by prioritizing the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-2-tables-by-prioritizing-the-data/m-p/949480#M371408</link>
      <description>&lt;P&gt;Example of &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;'s suggestion.&lt;/P&gt;
&lt;P&gt;Note the data in the form of working data steps (hint);&lt;/P&gt;
&lt;PRE&gt;data work.a;
   input Key $;
datalines;
1234
3456
;

Data work.B;
  input Key $ 	Rank 	contact $;
datalines;
1234 	1 	owner
1234 	2 	co-owner
1234 	3 	CEO
3456 	2 	co-owner
3456 	3 	CEO
;

data work.merged;
   merge work.a work.b;
   by key;
run;

proc transpose data=work.merged out=work.trans (drop=_name_)
    prefix=contact;
   by key;
   var contact;
run;&lt;/PRE&gt;
&lt;P&gt;If your data isn't sorted, or just in case, I would suggest sorting Work.A (or whatever you data set name is) by the Key. Then Work.B by the Key and Rank.&lt;/P&gt;
&lt;P&gt;If your data sets do have differently named key variables a data set option rename would address that:&lt;/P&gt;
&lt;PRE&gt;data work.merged;
   merge work.a work.b(rename=(key2=key));
   by key;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2024 14:25:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-2-tables-by-prioritizing-the-data/m-p/949480#M371408</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-10-30T14:25:54Z</dc:date>
    </item>
    <item>
      <title>Re: Join 2 tables by prioritizing the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-2-tables-by-prioritizing-the-data/m-p/949710#M371462</link>
      <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;You can achieve the desired result using a combination of the ROW_NUMBER() function and conditional aggregation. Here’s a SQL query that accomplishes your goal:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;PRE class=""&gt;&lt;CODE class=""&gt;&lt;SPAN class=""&gt;WITH&lt;/SPAN&gt; RankedContacts &lt;SPAN class=""&gt;AS&lt;/SPAN&gt; (
    &lt;SPAN class=""&gt;SELECT&lt;/SPAN&gt; 
        Key2 &lt;SPAN class=""&gt;AS&lt;/SPAN&gt; [Key],
        Contact,
        &lt;SPAN class=""&gt;ROW_NUMBER&lt;/SPAN&gt;() &lt;SPAN class=""&gt;OVER&lt;/SPAN&gt; (&lt;SPAN class=""&gt;PARTITION&lt;/SPAN&gt; &lt;SPAN class=""&gt;BY&lt;/SPAN&gt; Key2 &lt;SPAN class=""&gt;ORDER&lt;/SPAN&gt; &lt;SPAN class=""&gt;BY&lt;/SPAN&gt; Rank) &lt;SPAN class=""&gt;AS&lt;/SPAN&gt; RowNum
    &lt;SPAN class=""&gt;FROM&lt;/SPAN&gt; 
        TableB
)
&lt;SPAN class=""&gt;SELECT&lt;/SPAN&gt; 
    [Key],
    &lt;SPAN class=""&gt;MAX&lt;/SPAN&gt;(&lt;SPAN class=""&gt;CASE&lt;/SPAN&gt; &lt;SPAN class=""&gt;WHEN&lt;/SPAN&gt; RowNum &lt;SPAN class=""&gt;=&lt;/SPAN&gt; &lt;SPAN class=""&gt;1&lt;/SPAN&gt; &lt;SPAN class=""&gt;THEN&lt;/SPAN&gt; Contact &lt;SPAN class=""&gt;END&lt;/SPAN&gt;) &lt;SPAN class=""&gt;AS&lt;/SPAN&gt; contact1,
    &lt;SPAN class=""&gt;MAX&lt;/SPAN&gt;(&lt;SPAN class=""&gt;CASE&lt;/SPAN&gt; &lt;SPAN class=""&gt;WHEN&lt;/SPAN&gt; RowNum &lt;SPAN class=""&gt;=&lt;/SPAN&gt; &lt;SPAN class=""&gt;2&lt;/SPAN&gt; &lt;SPAN class=""&gt;THEN&lt;/SPAN&gt; Contact &lt;SPAN class=""&gt;END&lt;/SPAN&gt;) &lt;SPAN class=""&gt;AS&lt;/SPAN&gt; contact2,
    &lt;SPAN class=""&gt;MAX&lt;/SPAN&gt;(&lt;SPAN class=""&gt;CASE&lt;/SPAN&gt; &lt;SPAN class=""&gt;WHEN&lt;/SPAN&gt; RowNum &lt;SPAN class=""&gt;=&lt;/SPAN&gt; &lt;SPAN class=""&gt;3&lt;/SPAN&gt; &lt;SPAN class=""&gt;THEN&lt;/SPAN&gt; Contact &lt;SPAN class=""&gt;END&lt;/SPAN&gt;) &lt;SPAN class=""&gt;AS&lt;/SPAN&gt; contact3
&lt;SPAN class=""&gt;FROM&lt;/SPAN&gt; 
    RankedContacts
&lt;SPAN class=""&gt;GROUP&lt;/SPAN&gt; &lt;SPAN class=""&gt;BY&lt;/SPAN&gt; 
    [Key];&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Result:&lt;/P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="thomas_aquas_0-1730469495681.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/101933i236358CE9C46A195/image-size/medium?v=v2&amp;amp;px=400" role="button" title="thomas_aquas_0-1730469495681.png" alt="thomas_aquas_0-1730469495681.png" /&gt;&lt;/span&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;This query first ranks the contacts based on their rank for each key. Then, it uses conditional aggregation to assign the appropriate contacts to contact1, contact2, and contact3.&lt;/P&gt;&lt;P&gt;A more extensive discussion of this issue can be found here:&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://finalexception.com/assigning-values-with-row-number-in-sql-server/" target="_blank" rel="nofollow noopener noreferrer"&gt;row number in sql server&lt;/A&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 01 Nov 2024 13:59:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-2-tables-by-prioritizing-the-data/m-p/949710#M371462</guid>
      <dc:creator>thomas_aquas</dc:creator>
      <dc:date>2024-11-01T13:59:07Z</dc:date>
    </item>
    <item>
      <title>Re: Join 2 tables by prioritizing the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-2-tables-by-prioritizing-the-data/m-p/949712#M371463</link>
      <description>&lt;P&gt;For further analysis, a long layout is better. The wide layout can easily achieved in PROC REPORT for reporting purposes:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
input Key1 $;
datalines;
1234
3456
;

data b;
infile datalines dsd dlm="09"x;
input Key2 $ Rank contact $;
datalines;
1234	1	owner
1234	2	co-owner
1234	3	CEO
3456	2	co-owner
3456	3	CEO
;

data want;
merge
  a
  b (rename=(key2=key1))
;
by key1;
if first.key1
then n = 1;
else n + 1;
cont = cats("contact",n);
run;

proc report data=want;
column key1 (contact rank),cont;
define key1 / "" group;
define contact / "" display;
define rank / noprint;
define cont / "" across;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Using rank with noprint is necessary because REPORT wants at least one ANALYSIS variable under the ACROSS, and this needs to be numeric.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt; 	contact1	contact2	contact3
1234	owner	co-owner	CEO
3456	co-owner	CEO	 
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Nov 2024 14:26:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-2-tables-by-prioritizing-the-data/m-p/949712#M371463</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-11-01T14:26:18Z</dc:date>
    </item>
    <item>
      <title>Re: Join 2 tables by prioritizing the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-2-tables-by-prioritizing-the-data/m-p/949713#M371464</link>
      <description>&lt;P&gt;This, of course, will only work in a remote database that understands this particular syntax. It will not work in SAS.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Nov 2024 14:28:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-2-tables-by-prioritizing-the-data/m-p/949713#M371464</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-11-01T14:28:03Z</dc:date>
    </item>
    <item>
      <title>Re: Join 2 tables by prioritizing the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-2-tables-by-prioritizing-the-data/m-p/949714#M371465</link>
      <description>&lt;P&gt;Note that PROC SQL does not support windowing functions nor WITH clauses so the only way to run something like that would be via explicit pass thru to some external database system.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That syntax seems to be SQL SERVER specific, but could probably be adopted for most other external databases that support SQL windowing functions and WITH clauses.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Nov 2024 14:32:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-2-tables-by-prioritizing-the-data/m-p/949714#M371465</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-11-01T14:32:30Z</dc:date>
    </item>
    <item>
      <title>Re: Join 2 tables by prioritizing the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-2-tables-by-prioritizing-the-data/m-p/949719#M371466</link>
      <description>&lt;P&gt;I don't see why you would need to combine the two tables.&amp;nbsp; Add the first table does not add any information that is not already in the second table.&amp;nbsp; Can you explain why they need to be joined?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just sort the data by KEY (which ever name for it you want to use) and RANK and then transpose it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your table appears to already be sorted.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input Key2 Rank contact $ ;
cards;
1234 1 owner
1234 2 co-owner
1234 3 CEO
3456 2 co-owner
3456 3 CEO
;

proc transpose data=have out=want(drop=_name_) prefix=contact;
  by key2;
  var contact;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs    Key2    contact1    contact2    contact3

 1     1234    owner       co-owner      CEO
 2     3456    co-owner    CEO

&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 Nov 2024 14:49:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-2-tables-by-prioritizing-the-data/m-p/949719#M371466</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-11-01T14:49:08Z</dc:date>
    </item>
  </channel>
</rss>

