<?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: Sorting Data in Developers</title>
    <link>https://communities.sas.com/t5/Developers/Sorting-Data/m-p/617430#M619</link>
    <description>&lt;P&gt;Creating s sorted table in CAS seems to be possible using partioning functionality. You can order variables within a partition. So to create an ordered CAS table, you should create one (dummy) partition for the whole table.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Examples how to get an ordered CAS table */
cas;
caslib _all_ assign;
 
/* following code uses a 9.4 SAS dataset as input and creates a sorted table in CAS */
data work.unsorted;
     group = "A";       
     w1 = 5; w2 = 6; output;
     w1 = 3; w2 = 3; output;
     w1 = 1; w2 = 2; output;
     w1 = 3; w2 = 4; output;
run;

proc casutil
   outcaslib="casuser";
   load data= "unsorted" casout="sort1" replace partitionby=(group) orderby=(w1 w2) ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It's also possible to create a sorted CAS table based on a CAS table as input. This routine could replace a proc sort from 9.4:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Following code runs in CAS and sorts the columns in a CAS table */&lt;BR /&gt;
/* A dummy group is added to put all data in the same partition */&lt;BR /&gt;&lt;BR /&gt;
data casuser.unsorted;
     group = "A";       
     w1 = 5; w2 = 6; output;
     w1 = 3; w2 = 3; output;
     w1 = 1; w2 = 2; output;
     w1 = 3; w2 = 4; output;
run;

data casuser.sort3 (partition=(group) orderby=(w1 w2));
    set casuser.unsorted ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can use this sorted dataset for subsequent datasteps.&amp;nbsp;But: to use constructs like retain and lag() you still have to change the datastep code: you could add the datastep option&lt;EM&gt;&amp;nbsp; / single=yes&lt;/EM&gt; to force CAS to run the datastep single threaded or use some retain logic to deal with multi threading.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One thing that is not working like it should do: order variables in descending order like in following example:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=casref&amp;amp;docsetTarget=p12eiok32viouqn1huacr2d39nl0.htm&amp;amp;docsetVersion=1.0&amp;amp;locale=en"&gt;https://documentation.sas.com/?docsetId=casref&amp;amp;docsetTarget=p12eiok32viouqn1huacr2d39nl0.htm&amp;amp;docsetVersion=1.0&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;This example contains some syntax errors and is not sorting variable ch as it should do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My own example to show this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* following code runs in CAS and should order column w2 descending within column w1 */
/* This is not working as expected: column w2 is not ordered descending within w1  */
data casuser.sort4 (partition=(group) orderby=(w1 DESCENDING w2));
    set casuser.unsorted ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Why is this not working???&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>Wed, 15 Jan 2020 13:38:34 GMT</pubDate>
    <dc:creator>Frank_Boekamp</dc:creator>
    <dc:date>2020-01-15T13:38:34Z</dc:date>
    <item>
      <title>Sorting Data</title>
      <link>https://communities.sas.com/t5/Developers/Sorting-Data/m-p/610139#M604</link>
      <description>&lt;P&gt;Hi everyone,&lt;BR /&gt;&lt;BR /&gt;In SAS Viya, How could you sort data ? Please advise if you have some information.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2019 06:51:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Sorting-Data/m-p/610139#M604</guid>
      <dc:creator>RonLee</dc:creator>
      <dc:date>2019-12-09T06:51:14Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting Data</title>
      <link>https://communities.sas.com/t5/Developers/Sorting-Data/m-p/610166#M605</link>
      <description>&lt;P&gt;You don't need to sort data in CAS in order to consume it sorted (by group processing, if first./last. in a data step).&lt;/P&gt;</description>
      <pubDate>Sat, 07 Dec 2019 02:39:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Sorting-Data/m-p/610166#M605</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-12-07T02:39:26Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting Data</title>
      <link>https://communities.sas.com/t5/Developers/Sorting-Data/m-p/610434#M606</link>
      <description>&lt;P&gt;Sorting data sets in CAS is not even possible, proc sort and order by in proc FEDSQL for example do not exist in CAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Be careful using SAS base code in CAS: see &lt;U&gt;&lt;FONT color="#000025" face="Calibri,Calibri_MSFontService,Sans-Serif" style="background-color: #ffffff;"&gt;running the DATA step in CAS with special attention to RETAIN, LAG, and _N_&lt;/FONT&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&lt;A class="Hyperlink SCXW199572596 BCX1" style="color: inherit; cursor: text; font-family: &amp;amp;quot; segoe ui&amp;amp;quot;,&amp;amp;quot;segoe ui web&amp;amp;quot;,arial,verdana,sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; -ms-touch-select: none; -ms-user-select: text; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-tap-highlight-color: transparent; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px; padding: 0px; margin: 0px;" href="https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2018/2184-2018.pdf" target="_blank" rel="noopener noreferrer"&gt;&lt;SPAN class="TextRun Underlined SCXW199572596 BCX1" style="color: #0000ff; font-family: Calibri,Calibri_MSFontService,Sans-Serif; font-size: 11pt; line-height: 19.42px; -ms-touch-select: none; -ms-user-select: text; text-decoration: underline; -webkit-tap-highlight-color: transparent; padding: 0px; margin: 0px;" data-contrast="none"&gt;&lt;SPAN class="NormalTextRun SCXW199572596 BCX1" style="background-color: inherit; -ms-touch-select: none; -ms-user-select: text; -webkit-tap-highlight-color: transparent; padding: 0px; margin: 0px;"&gt;https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2018/2184-2018.pdf&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using SAS Studio on Viya, you can use the 'old' style SAS Base code. But then you are not profiting from the big performance gain in CAS which originates from multiple threading and in-memory processing of data.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2019 11:12:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Sorting-Data/m-p/610434#M606</guid>
      <dc:creator>Frank_Boekamp</dc:creator>
      <dc:date>2019-12-09T11:12:47Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting Data</title>
      <link>https://communities.sas.com/t5/Developers/Sorting-Data/m-p/617430#M619</link>
      <description>&lt;P&gt;Creating s sorted table in CAS seems to be possible using partioning functionality. You can order variables within a partition. So to create an ordered CAS table, you should create one (dummy) partition for the whole table.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Examples how to get an ordered CAS table */
cas;
caslib _all_ assign;
 
/* following code uses a 9.4 SAS dataset as input and creates a sorted table in CAS */
data work.unsorted;
     group = "A";       
     w1 = 5; w2 = 6; output;
     w1 = 3; w2 = 3; output;
     w1 = 1; w2 = 2; output;
     w1 = 3; w2 = 4; output;
run;

proc casutil
   outcaslib="casuser";
   load data= "unsorted" casout="sort1" replace partitionby=(group) orderby=(w1 w2) ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It's also possible to create a sorted CAS table based on a CAS table as input. This routine could replace a proc sort from 9.4:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Following code runs in CAS and sorts the columns in a CAS table */&lt;BR /&gt;
/* A dummy group is added to put all data in the same partition */&lt;BR /&gt;&lt;BR /&gt;
data casuser.unsorted;
     group = "A";       
     w1 = 5; w2 = 6; output;
     w1 = 3; w2 = 3; output;
     w1 = 1; w2 = 2; output;
     w1 = 3; w2 = 4; output;
run;

data casuser.sort3 (partition=(group) orderby=(w1 w2));
    set casuser.unsorted ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can use this sorted dataset for subsequent datasteps.&amp;nbsp;But: to use constructs like retain and lag() you still have to change the datastep code: you could add the datastep option&lt;EM&gt;&amp;nbsp; / single=yes&lt;/EM&gt; to force CAS to run the datastep single threaded or use some retain logic to deal with multi threading.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One thing that is not working like it should do: order variables in descending order like in following example:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=casref&amp;amp;docsetTarget=p12eiok32viouqn1huacr2d39nl0.htm&amp;amp;docsetVersion=1.0&amp;amp;locale=en"&gt;https://documentation.sas.com/?docsetId=casref&amp;amp;docsetTarget=p12eiok32viouqn1huacr2d39nl0.htm&amp;amp;docsetVersion=1.0&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;This example contains some syntax errors and is not sorting variable ch as it should do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My own example to show this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* following code runs in CAS and should order column w2 descending within column w1 */
/* This is not working as expected: column w2 is not ordered descending within w1  */
data casuser.sort4 (partition=(group) orderby=(w1 DESCENDING w2));
    set casuser.unsorted ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Why is this not working???&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>Wed, 15 Jan 2020 13:38:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Sorting-Data/m-p/617430#M619</guid>
      <dc:creator>Frank_Boekamp</dc:creator>
      <dc:date>2020-01-15T13:38:34Z</dc:date>
    </item>
  </channel>
</rss>

