<?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 Sort in a data step to get more compact code in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sort-in-a-data-step-to-get-more-compact-code/m-p/748066#M234896</link>
    <description>&lt;P&gt;I often find myself creating a data-set and then sorting it since for instance I want to do an visual inspection of my data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, with pseudo code it looks like:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;EDIT: When creating the data set, I do some other things such as keeping some columns and create a new one.&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;* Creating my data-set; &lt;BR /&gt;&lt;BR /&gt;data MyData;&lt;BR /&gt; set SomeDataSet;&lt;BR /&gt; keep colA colB;&lt;BR /&gt; NewCol = ColA - ColB;&lt;BR /&gt;run; &lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* Sorting my data-set;&lt;BR /&gt;&lt;BR /&gt;proc sort data = MyData; 
   by ColumnA; 
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now, this quickly becomes alot of code, can this be done more compactly? For instance sort the data already in the data step? Any other methods to recommend?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thanks.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 15 Jun 2021 10:13:29 GMT</pubDate>
    <dc:creator>SasStatistics</dc:creator>
    <dc:date>2021-06-15T10:13:29Z</dc:date>
    <item>
      <title>Sort in a data step to get more compact code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-in-a-data-step-to-get-more-compact-code/m-p/748066#M234896</link>
      <description>&lt;P&gt;I often find myself creating a data-set and then sorting it since for instance I want to do an visual inspection of my data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, with pseudo code it looks like:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;EDIT: When creating the data set, I do some other things such as keeping some columns and create a new one.&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;* Creating my data-set; &lt;BR /&gt;&lt;BR /&gt;data MyData;&lt;BR /&gt; set SomeDataSet;&lt;BR /&gt; keep colA colB;&lt;BR /&gt; NewCol = ColA - ColB;&lt;BR /&gt;run; &lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* Sorting my data-set;&lt;BR /&gt;&lt;BR /&gt;proc sort data = MyData; 
   by ColumnA; 
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now, this quickly becomes alot of code, can this be done more compactly? For instance sort the data already in the data step? Any other methods to recommend?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thanks.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jun 2021 10:13:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-in-a-data-step-to-get-more-compact-code/m-p/748066#M234896</guid>
      <dc:creator>SasStatistics</dc:creator>
      <dc:date>2021-06-15T10:13:29Z</dc:date>
    </item>
    <item>
      <title>Re: Sort in a data step to get more compact code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-in-a-data-step-to-get-more-compact-code/m-p/748069#M234898</link>
      <description>&lt;P&gt;The first step is not necessary at all, just use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data= SomeDataset out = MyData; 
   by ColumnA; 
run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Jun 2021 08:53:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-in-a-data-step-to-get-more-compact-code/m-p/748069#M234898</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-06-15T08:53:18Z</dc:date>
    </item>
    <item>
      <title>Re: Sort in a data step to get more compact code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-in-a-data-step-to-get-more-compact-code/m-p/748080#M234902</link>
      <description>Thanks, please view my edit, my pseudo code example was bad.</description>
      <pubDate>Tue, 15 Jun 2021 10:13:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-in-a-data-step-to-get-more-compact-code/m-p/748080#M234902</guid>
      <dc:creator>SasStatistics</dc:creator>
      <dc:date>2021-06-15T10:13:55Z</dc:date>
    </item>
    <item>
      <title>Re: Sort in a data step to get more compact code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-in-a-data-step-to-get-more-compact-code/m-p/748081#M234903</link>
      <description>&lt;P&gt;I think your idea of "compact code" and my idea of "compact code" are probably different.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need to do a subtraction in a DATA step, and then a sort, then these are two different processes. You can't do them both in one step * so you are left with the need to do these two different processes in two steps. NOTE: there are times when you can do two different processes in one step, this isn't one of them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;* — I suppose you could use hash objects to do all of this in one data step, if you want to use an advanced method.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jun 2021 10:20:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-in-a-data-step-to-get-more-compact-code/m-p/748081#M234903</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-06-15T10:20:05Z</dc:date>
    </item>
    <item>
      <title>Re: Sort in a data step to get more compact code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-in-a-data-step-to-get-more-compact-code/m-p/748083#M234904</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/381436"&gt;@SasStatistics&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thanks, please view my edit, my pseudo code example was bad.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, it was &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt; pointed out: one could use a hash-object to do the sorting in the data step, but you would have to write more than three lines of code to get the same result, so using easy-to-read steps is by far more desirable than having one big step.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jun 2021 10:27:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-in-a-data-step-to-get-more-compact-code/m-p/748083#M234904</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-06-15T10:27:52Z</dc:date>
    </item>
    <item>
      <title>Re: Sort in a data step to get more compact code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-in-a-data-step-to-get-more-compact-code/m-p/748085#M234905</link>
      <description>&lt;P&gt;You could do a sort in a data step on the fly, but it can only work as long as the complete dataset (including the B-tree) can be kept in memory, and it would be A LOT MORE code.&lt;/P&gt;
&lt;P&gt;If you want to avoid storing an intermediate dataset, you can use your data step to define a view and use that as input in the PROC SORT, but you will still have to write the code (even a little more, as you need the /VIEW= in the DATA statement).&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jun 2021 10:31:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-in-a-data-step-to-get-more-compact-code/m-p/748085#M234905</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-06-15T10:31:26Z</dc:date>
    </item>
    <item>
      <title>Re: Sort in a data step to get more compact code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-in-a-data-step-to-get-more-compact-code/m-p/748091#M234906</link>
      <description>&lt;P&gt;If you switch from a DATA step to PROC SQL, you can do it in one step.&amp;nbsp; My SQL is rusty at best so you will need to test for syntax errors:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
create table MyData as&lt;BR /&gt;  select ColA, ColB, NewCol as ColA - ColB,&lt;BR /&gt;  from SomeDataSet,
  order by ColA;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Jun 2021 11:18:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-in-a-data-step-to-get-more-compact-code/m-p/748091#M234906</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-06-15T11:18:59Z</dc:date>
    </item>
  </channel>
</rss>

