<?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 do i sort a view? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-do-i-sort-a-view/m-p/505410#M1160</link>
    <description>&lt;P&gt;Cool. Did use the first. approach but was hoping that there's some option or trick with proc sort. Something along the line of:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data= PrepData / view=PrepData... etc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just looking to expand my 'sort' horizon.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 18 Oct 2018 01:12:01 GMT</pubDate>
    <dc:creator>DucatiJong</dc:creator>
    <dc:date>2018-10-18T01:12:01Z</dc:date>
    <item>
      <title>How do i sort a view?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-i-sort-a-view/m-p/505389#M1155</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have some preparation steps and like to keep these as view but problem occurred when I try to perform a sort (as one of the prep step). My sort step is critical so any idea how I can sort the view (ideally retaining it as a view)&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 view&amp;nbsp;Prep as&lt;/P&gt;&lt;P&gt;&amp;nbsp; select ID&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,Vars&lt;/P&gt;&lt;P&gt;&amp;nbsp; from InputData;&lt;/P&gt;&lt;P&gt;&amp;nbsp; quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data = Prep nodupkey;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by ID;&lt;/P&gt;&lt;P&gt;&amp;nbsp; run;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Oct 2018 22:45:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-i-sort-a-view/m-p/505389#M1155</guid>
      <dc:creator>DucatiJong</dc:creator>
      <dc:date>2018-10-17T22:45:48Z</dc:date>
    </item>
    <item>
      <title>Re: How do i sort a view?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-i-sort-a-view/m-p/505392#M1156</link>
      <description>&lt;P&gt;You would have to put the results into a data set:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=prep nodupkey out=next_step;&lt;/P&gt;
&lt;P&gt;by ID;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alternatively, you could modify the SQL view, adding UNIQUE to get rid of duplicates, and adding ORDER BY to get a sorted result.&amp;nbsp; Along the lines of:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;create view Prep as&lt;/P&gt;
&lt;P&gt;select distinct ID, vars&lt;/P&gt;
&lt;P&gt;from InputData&lt;/P&gt;
&lt;P&gt;order by ID;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Oct 2018 22:54:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-i-sort-a-view/m-p/505392#M1156</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-10-17T22:54:59Z</dc:date>
    </item>
    <item>
      <title>Re: How do i sort a view?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-i-sort-a-view/m-p/505394#M1157</link>
      <description>&lt;P&gt;Thanks for your reply. I could have provided more detail. I was using the sort to enforce retention of the first record based on ID. In another word if i have different variable values against the ID i would only want to keep the first record of that ID. Distinct would retain all different occurences.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Oct 2018 23:07:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-i-sort-a-view/m-p/505394#M1157</guid>
      <dc:creator>DucatiJong</dc:creator>
      <dc:date>2018-10-17T23:07:21Z</dc:date>
    </item>
    <item>
      <title>Re: How do i sort a view?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-i-sort-a-view/m-p/505399#M1158</link>
      <description>&lt;P&gt;Of course, if your data set is already sorted, that's easy:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want / view=want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by id;&lt;/P&gt;
&lt;P&gt;if first.id;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if it isn't, hashing will solve this.&amp;nbsp; Unfortunately, the syntax is beyond the limit of my hashing skills.&amp;nbsp; But here's the idea:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want / view=want;&lt;/P&gt;
&lt;P&gt;load data into a hash table with ID as the key (and vars as the data), with instructions to ignore duplicates;&lt;/P&gt;
&lt;P&gt;unload the data from the hash table into the data set;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Oct 2018 23:36:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-i-sort-a-view/m-p/505399#M1158</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-10-17T23:36:02Z</dc:date>
    </item>
    <item>
      <title>Re: How do i sort a view?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-i-sort-a-view/m-p/505410#M1160</link>
      <description>&lt;P&gt;Cool. Did use the first. approach but was hoping that there's some option or trick with proc sort. Something along the line of:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data= PrepData / view=PrepData... etc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just looking to expand my 'sort' horizon.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Oct 2018 01:12:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-i-sort-a-view/m-p/505410#M1160</guid>
      <dc:creator>DucatiJong</dc:creator>
      <dc:date>2018-10-18T01:12:01Z</dc:date>
    </item>
    <item>
      <title>Re: How do i sort a view?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-i-sort-a-view/m-p/505425#M1165</link>
      <description>&lt;P&gt;What about a UNIQUE clause in your SELECT SQL statement right up front?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SELECT UNIQUE id ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could also do something simple like this :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort&amp;nbsp; data = VIEWNAME&amp;nbsp; out = sorted ; ***I think the VIEW name can be inserted directly here???**;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by ID someother_var &amp;nbsp; ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data select_unique&amp;nbsp; ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set sorted&amp;nbsp; ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; by ID someother_var&amp;nbsp; ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if first.ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This will select a unique value for ID based on the sorted value of some other variable(s).&amp;nbsp; The most obvious example would be to sort by date. Selecting the first observation will automatically select the most recent date as and the observation will be unique for ID in the resulting view or dataset. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Oct 2018 04:31:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-i-sort-a-view/m-p/505425#M1165</guid>
      <dc:creator>Kow</dc:creator>
      <dc:date>2018-10-18T04:31:08Z</dc:date>
    </item>
  </channel>
</rss>

