<?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: Views and &amp;quot;Cannot sort in place&amp;quot; error in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Views-and-quot-Cannot-sort-in-place-quot-error/m-p/726024#M225591</link>
    <description>&lt;P&gt;If you want to create a view which returns the rows sorted then consider below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql feedback;
  create view work.trim_price as
  select *
  from temp
  where 0&amp;lt;rank&amp;lt;99 or year=1999
  order by loc, year
  ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 13 Mar 2021 03:44:06 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2021-03-13T03:44:06Z</dc:date>
    <item>
      <title>Views and "Cannot sort in place" error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Views-and-quot-Cannot-sort-in-place-quot-error/m-p/725999#M225579</link>
      <description>&lt;P&gt;Hi all SAS Users,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am new to VIEW, even I am trying to read some documents about that but still a novice in that part.&lt;/P&gt;
&lt;P&gt;Today I faced a problem named&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ERROR: Cannot sort in place.&lt;/PRE&gt;
&lt;P&gt;So, there are two scenarios, the first one (without views) it can run smoothly, the second one (with views) it runs with an error&lt;/P&gt;
&lt;P&gt;The first scenario&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data trim_price ;/*without views - this is the only difference between two codes*/
	set temp;
	 if 0&amp;lt;rank&amp;lt;99 or year=1999;
run;
*sort by country;
proc sort data=work.trim_price;
by LOC year;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The log&lt;/P&gt;
&lt;PRE&gt;37         *removing stocks if yearly amihud
38         in the top 1% within a country each year;
39         
40         *sort by country;
41         proc sort data=work.trim_price;
42         by LOC year;
43         run;

NOTE: There were 52599 observations read from the data set WORK.TRIM_PRICE.&lt;/PRE&gt;
&lt;P&gt;The second one&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data trim_price / view=trim_price;
	set temp;
	 if 0&amp;lt;rank&amp;lt;99 or year=1999;
run;
*sort by country;
proc sort data=work.trim_price;
by LOC year;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The log&lt;/P&gt;
&lt;PRE&gt;ERROR: Cannot sort in place.
ERROR: Unable to create WORK.TRIM_PRICE.DATA because WORK.TRIM_PRICE.VIEW already exists.&lt;/PRE&gt;
&lt;P&gt;Could you please explain to me the reason behind this? And whether this error is caused &lt;STRONG&gt;just&lt;/STRONG&gt; because of the &lt;STRONG&gt;view&lt;/STRONG&gt; or is there any possible hidden error?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Warmest regards and have a nice weekend.&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>Fri, 12 Mar 2021 22:11:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Views-and-quot-Cannot-sort-in-place-quot-error/m-p/725999#M225579</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-03-12T22:11:43Z</dc:date>
    </item>
    <item>
      <title>Re: Views and "Cannot sort in place" error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Views-and-quot-Cannot-sort-in-place-quot-error/m-p/726001#M225580</link>
      <description>&lt;P&gt;Remember that Views are instructions on how to pull data from some other source.&lt;/P&gt;
&lt;P&gt;So you can't change the order of the data in that instruction set.&lt;/P&gt;
&lt;P&gt;You can specify an OUT= data set in proc sort but that may make the reason you are attempting to use a view moot.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you know that you want a specific order in the set you might consider creating your view using Proc SQL with an Order By clause:&lt;/P&gt;
&lt;PRE&gt;proc sql;
   create view sorted as
   select * 
   from sashelp.class
   order by sex, age, weight
   ;
quit;


proc print data=sorted;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Mar 2021 22:19:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Views-and-quot-Cannot-sort-in-place-quot-error/m-p/726001#M225580</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-03-12T22:19:25Z</dc:date>
    </item>
    <item>
      <title>Re: Views and "Cannot sort in place" error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Views-and-quot-Cannot-sort-in-place-quot-error/m-p/726002#M225581</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your suggestion, I am curious about that part&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;You can specify an OUT= data set in proc sort but that may make the reason you are attempting to use a view moot.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;So, it equals to my first scenario( without &lt;STRONG&gt;view&lt;/STRONG&gt;) regarding consuming the same storage, isn't it? I hope that I explain your idea properly.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Warm regards.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Mar 2021 22:26:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Views-and-quot-Cannot-sort-in-place-quot-error/m-p/726002#M225581</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-03-12T22:26:44Z</dc:date>
    </item>
    <item>
      <title>Re: Views and "Cannot sort in place" error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Views-and-quot-Cannot-sort-in-place-quot-error/m-p/726003#M225582</link>
      <description>&lt;P&gt;Sorting a view in-place doesn't make sense and isn't allowed. You've created the view based on a different table. If you want the data to come out in a different order sort the TEMP table and recreate the view.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to sort the data coming out of the view use the OUT = option in your PROC SORT to store the sorted data in a different output dataset.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Mar 2021 22:27:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Views-and-quot-Cannot-sort-in-place-quot-error/m-p/726003#M225582</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-03-12T22:27:25Z</dc:date>
    </item>
    <item>
      <title>Re: Views and "Cannot sort in place" error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Views-and-quot-Cannot-sort-in-place-quot-error/m-p/726011#M225587</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I want to keep the dataname, can I do that?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data trim_price ;/*without views - this is the only difference between two codes*/
	set temp;
	 if 0&amp;lt;rank&amp;lt;99 or year=1999;
run;
*sort by country;
proc sort data=work.trim_price;
by LOC year;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Warm regards.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Mar 2021 23:07:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Views-and-quot-Cannot-sort-in-place-quot-error/m-p/726011#M225587</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-03-12T23:07:56Z</dc:date>
    </item>
    <item>
      <title>Re: Views and "Cannot sort in place" error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Views-and-quot-Cannot-sort-in-place-quot-error/m-p/726022#M225590</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/212695"&gt;@Phil_NZ&lt;/a&gt; - Really you don't need to ask. Just run it and if it works without error then of course that is fine. Updating in place with real datasets is perfectly OK.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Remember a view is essentially a read-only "window" into the original data behind it. If you wanted to change what you saw through a shop window would you change the window or what was behind it? The concept is the same.&lt;/P&gt;</description>
      <pubDate>Sat, 13 Mar 2021 03:03:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Views-and-quot-Cannot-sort-in-place-quot-error/m-p/726022#M225590</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-03-13T03:03:06Z</dc:date>
    </item>
    <item>
      <title>Re: Views and "Cannot sort in place" error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Views-and-quot-Cannot-sort-in-place-quot-error/m-p/726024#M225591</link>
      <description>&lt;P&gt;If you want to create a view which returns the rows sorted then consider below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql feedback;
  create view work.trim_price as
  select *
  from temp
  where 0&amp;lt;rank&amp;lt;99 or year=1999
  order by loc, year
  ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 13 Mar 2021 03:44:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Views-and-quot-Cannot-sort-in-place-quot-error/m-p/726024#M225591</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-03-13T03:44:06Z</dc:date>
    </item>
    <item>
      <title>Re: Views and "Cannot sort in place" error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Views-and-quot-Cannot-sort-in-place-quot-error/m-p/726025#M225592</link>
      <description>&lt;P&gt;You are sort the wrong thing.&amp;nbsp; If you want to change the order the data is returned by the data step view then change the order of the order of the data that the view reads.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=temp;
  by LOC year;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 13 Mar 2021 04:15:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Views-and-quot-Cannot-sort-in-place-quot-error/m-p/726025#M225592</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-03-13T04:15:15Z</dc:date>
    </item>
  </channel>
</rss>

