<?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 Can you sort data using ORDER BY in Proc SQL so that it saves the sorted order in a table? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Can-you-sort-data-using-ORDER-BY-in-Proc-SQL-so-that-it-saves/m-p/950861#M371791</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset that is sorted by only an ID variable.&amp;nbsp; However, I would like to re-sort the data ID and Date of BIRTH&amp;nbsp; and SEX in that order.&lt;/P&gt;&lt;P&gt;Can I use Proc SQL to store the resorted data in a new table ?&amp;nbsp; Or will the order by be used only to display the results?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am interested in resorting and saving the data in a new table, so any hints will help.&amp;nbsp; I know it is easy to do this using Proc Sort in the Data Step&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc SQL;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table NEW as select * from OLD&lt;/P&gt;&lt;P&gt;&amp;nbsp; order by ID, DOB, SEX;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;</description>
    <pubDate>Thu, 14 Nov 2024 21:52:37 GMT</pubDate>
    <dc:creator>mtakayesu1</dc:creator>
    <dc:date>2024-11-14T21:52:37Z</dc:date>
    <item>
      <title>Can you sort data using ORDER BY in Proc SQL so that it saves the sorted order in a table?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-you-sort-data-using-ORDER-BY-in-Proc-SQL-so-that-it-saves/m-p/950861#M371791</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset that is sorted by only an ID variable.&amp;nbsp; However, I would like to re-sort the data ID and Date of BIRTH&amp;nbsp; and SEX in that order.&lt;/P&gt;&lt;P&gt;Can I use Proc SQL to store the resorted data in a new table ?&amp;nbsp; Or will the order by be used only to display the results?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am interested in resorting and saving the data in a new table, so any hints will help.&amp;nbsp; I know it is easy to do this using Proc Sort in the Data Step&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc SQL;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table NEW as select * from OLD&lt;/P&gt;&lt;P&gt;&amp;nbsp; order by ID, DOB, SEX;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2024 21:52:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-you-sort-data-using-ORDER-BY-in-Proc-SQL-so-that-it-saves/m-p/950861#M371791</guid>
      <dc:creator>mtakayesu1</dc:creator>
      <dc:date>2024-11-14T21:52:37Z</dc:date>
    </item>
    <item>
      <title>Re: Can you sort data using ORDER BY in Proc SQL so that it saves the sorted order in a table?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-you-sort-data-using-ORDER-BY-in-Proc-SQL-so-that-it-saves/m-p/950862#M371792</link>
      <description>&lt;P&gt;Yes! Your code will produce the outcome you are looking for. Dataset NEW will sorted by ID, DOB, SEX.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2024 22:35:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-you-sort-data-using-ORDER-BY-in-Proc-SQL-so-that-it-saves/m-p/950862#M371792</guid>
      <dc:creator>sjb1</dc:creator>
      <dc:date>2024-11-14T22:35:48Z</dc:date>
    </item>
    <item>
      <title>Re: Can you sort data using ORDER BY in Proc SQL so that it saves the sorted order in a table?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-you-sort-data-using-ORDER-BY-in-Proc-SQL-so-that-it-saves/m-p/950864#M371793</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Can I use Proc SQL to store the resorted data in a new table ?&amp;nbsp; Or will the order by be used only to display the results?&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;SAS tables are sequential and the sort order is how data gets stored physically. That's different to most databases.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Whether you use the SQL syntax as shared or Proc Sort will have the same result. Afaik both procedures use the same "module" in the background for the actual sorting of a SAS table.&lt;/P&gt;
&lt;P&gt;Proc Sort gives you more options like NODUPKEY or in cases where the source table is potentially already sorted the way you want it PRESORTED (which then will only physically sort the table if it isn't already sorted).&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2024 23:58:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-you-sort-data-using-ORDER-BY-in-Proc-SQL-so-that-it-saves/m-p/950864#M371793</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-11-14T23:58:07Z</dc:date>
    </item>
    <item>
      <title>Re: Can you sort data using ORDER BY in Proc SQL so that it saves the sorted order in a table?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-you-sort-data-using-ORDER-BY-in-Proc-SQL-so-that-it-saves/m-p/950904#M371797</link>
      <description>&lt;P&gt;I wouldn't be too quick in assuming SQL ORDER BY produces the same result as PROC SORT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes it will IF ... each combination of the sort variables has only one observation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if there is more than one observation with the same ID/DOB/SEX triplet, then you can't make that assumption.&amp;nbsp; &amp;nbsp;Now PROC SORT has an option (EQUALS vs NOEQUALS) that gives you a little control.&amp;nbsp; The EQUALS option (which is the default) preserves the original order of observations with tied triplets.&amp;nbsp; &amp;nbsp;NOEQUALS does not enforce that result (which theoretically might allow a bit more efficiency).&amp;nbsp; &amp;nbsp;I do not believe that the ORDER BY clause in PROC SQL provides for honoring the EQUALS behavior, which would be necessary to guarantee identical results to PROC SORT&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2024 21:13:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-you-sort-data-using-ORDER-BY-in-Proc-SQL-so-that-it-saves/m-p/950904#M371797</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-11-15T21:13:19Z</dc:date>
    </item>
    <item>
      <title>Re: Can you sort data using ORDER BY in Proc SQL so that it saves the sorted order in a table?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-you-sort-data-using-ORDER-BY-in-Proc-SQL-so-that-it-saves/m-p/950913#M371803</link>
      <description>&lt;P&gt;This is mostly (*) equivalent to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort
  data=old
  out=new
;
by id dob sex;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;*) see the other posts in the thread.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2024 09:58:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-you-sort-data-using-ORDER-BY-in-Proc-SQL-so-that-it-saves/m-p/950913#M371803</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-11-15T09:58:33Z</dc:date>
    </item>
    <item>
      <title>Re: Can you sort data using ORDER BY in Proc SQL so that it saves the sorted order in a table?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-you-sort-data-using-ORDER-BY-in-Proc-SQL-so-that-it-saves/m-p/951222#M371874</link>
      <description>&lt;P&gt;Thank you for this response.&amp;nbsp; I have come across more than one observation with the same ID/DOB/SEX triplet sort key.&amp;nbsp; And you are correct.&amp;nbsp; Comparing the Proc SORT vs. PROC SQL, the PROC SQL method doesn't have the same EQUALS behavior as PROC SORT, so when I attempted to pick the first record in the sort key based on PROC SQL or PROC SORT I have noticed slight differences in output.&amp;nbsp; Yes you do get the same number of observations, but the distribution looks different.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Nov 2024 14:54:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-you-sort-data-using-ORDER-BY-in-Proc-SQL-so-that-it-saves/m-p/951222#M371874</guid>
      <dc:creator>mtakayesu1</dc:creator>
      <dc:date>2024-11-19T14:54:52Z</dc:date>
    </item>
  </channel>
</rss>

