<?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 can I keep the order of rows the same after a left join? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-keep-the-order-of-rows-the-same-after-a-left-join/m-p/782919#M249592</link>
    <description>&lt;P&gt;The table on the left was in a random order&lt;/P&gt;</description>
    <pubDate>Mon, 29 Nov 2021 14:33:43 GMT</pubDate>
    <dc:creator>aalluru</dc:creator>
    <dc:date>2021-11-29T14:33:43Z</dc:date>
    <item>
      <title>How can I keep the order of rows the same after a left join?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-keep-the-order-of-rows-the-same-after-a-left-join/m-p/782912#M249590</link>
      <description>&lt;P&gt;I'm joining table a with table b using a left join and I want the resultant table to be in the same order that table a was in. However the order seems to be changing to the ascending order of the variable that I used to join on. How can I prevent that from happening?&lt;/P&gt;</description>
      <pubDate>Mon, 29 Nov 2021 13:55:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-keep-the-order-of-rows-the-same-after-a-left-join/m-p/782912#M249590</guid>
      <dc:creator>aalluru</dc:creator>
      <dc:date>2021-11-29T13:55:50Z</dc:date>
    </item>
    <item>
      <title>Re: How can I keep the order of rows the same after a left join?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-keep-the-order-of-rows-the-same-after-a-left-join/m-p/782915#M249591</link>
      <description>&lt;P&gt;Do you know what the table on the left was ordered by originally? You can use an `ORDER BY` clause after your join if it's that simple.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You'd probably need to specify the variable that it was sorted on along with its alias (e.g., ORDER BY a.unique_id).&lt;/P&gt;</description>
      <pubDate>Mon, 29 Nov 2021 14:16:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-keep-the-order-of-rows-the-same-after-a-left-join/m-p/782915#M249591</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2021-11-29T14:16:31Z</dc:date>
    </item>
    <item>
      <title>Re: How can I keep the order of rows the same after a left join?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-keep-the-order-of-rows-the-same-after-a-left-join/m-p/782919#M249592</link>
      <description>&lt;P&gt;The table on the left was in a random order&lt;/P&gt;</description>
      <pubDate>Mon, 29 Nov 2021 14:33:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-keep-the-order-of-rows-the-same-after-a-left-join/m-p/782919#M249592</guid>
      <dc:creator>aalluru</dc:creator>
      <dc:date>2021-11-29T14:33:43Z</dc:date>
    </item>
    <item>
      <title>Re: How can I keep the order of rows the same after a left join?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-keep-the-order-of-rows-the-same-after-a-left-join/m-p/782921#M249593</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/355241"&gt;@aalluru&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case create your own (temporary) sort key and use that in the ORDER BY clause.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create sample data for demonstration */

data have_a;
set sashelp.classfit;
keep name predict;
run;

data have_b;
set sashelp.class;
keep name age;
run;

/* Create view with a sort key (sequential number) */

data _have_a / view=_have_a;
set have_a;
_seqno=_n_;
run;

/* Perform left join maintaining sort order of HAVE_A and delete the view */

proc sql;
create table want(drop=_seqno) as
select a.*, age
from _have_a a left join have_b b
on a.name=b.name
order by _seqno;

drop view _have_a;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Nov 2021 14:39:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-keep-the-order-of-rows-the-same-after-a-left-join/m-p/782921#M249593</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-11-29T14:39:43Z</dc:date>
    </item>
    <item>
      <title>Re: How can I keep the order of rows the same after a left join?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-keep-the-order-of-rows-the-same-after-a-left-join/m-p/782924#M249596</link>
      <description>Yes! This worked! Thank you!!</description>
      <pubDate>Mon, 29 Nov 2021 14:56:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-keep-the-order-of-rows-the-same-after-a-left-join/m-p/782924#M249596</guid>
      <dc:creator>aalluru</dc:creator>
      <dc:date>2021-11-29T14:56:48Z</dc:date>
    </item>
  </channel>
</rss>

