<?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: Keeping the defined sortedby values in the metadata in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Keeping-the-defined-sortedby-values-in-the-metadata/m-p/825055#M325873</link>
    <description>&lt;P&gt;When searching on the net, I could find three other values but I don't know if there is any other one.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;SK when using nodupkey in proc sort or distinct in proc sql&lt;/LI&gt;
&lt;LI&gt;SR when using nodup in proc sort&lt;/LI&gt;
&lt;LI&gt;O when removing the sorting&lt;/LI&gt;
&lt;/UL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc datasets lib = work nolist nodetails;
    modify class (sortedby = _NULL_);
    run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 23 Jul 2022 13:55:25 GMT</pubDate>
    <dc:creator>xxformat_com</dc:creator>
    <dc:date>2022-07-23T13:55:25Z</dc:date>
    <item>
      <title>Keeping the defined sortedby values in the metadata</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-the-defined-sortedby-values-in-the-metadata/m-p/823697#M325265</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The two examples below gives the same result: sortedby includes the sorting order.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture1.JPG" style="width: 148px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/73364iAC1A1894BCB4200A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Capture1.JPG" alt="Capture1.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;But when the dataset is modified (add the commented dataset to test it - additional variable could also be added - so proc copy would not be sufficient), the sorted order is lost.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture2.JPG" style="width: 145px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/73365iB858DF7151F7C70F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Capture2.JPG" alt="Capture2.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Is this meant to be. Is there a way to avoid it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=sashelp.class out=class;
    by sex descending name;
run;

/*
data class;
    set class;
run;*/

proc sql;
    select name, sortedby
    from dictionary.columns
    where upcase(libname)='WORK' and
          upcase(memname)='CLASS';
quit;

*---------------------------------------------;
data class (sortedby=sex descending name);
    set class ;
run;

/*
data class;
    set class;
run;*/

proc sql;
    select name, sortedby
    from dictionary.columns
    where upcase(libname)='WORK' and
          upcase(memname)='CLASS';
quit;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 17 Jul 2022 12:15:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-the-defined-sortedby-values-in-the-metadata/m-p/823697#M325265</guid>
      <dc:creator>xxformat_com</dc:creator>
      <dc:date>2022-07-17T12:15:03Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping the defined sortedby values in the metadata</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-the-defined-sortedby-values-in-the-metadata/m-p/823718#M325276</link>
      <description>&lt;P&gt;The sortedby option is a writable data set attribute that doesn't ensure that the data is actually sorted this way.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Creating a table using Proc Sort ensures that the table is sorted.&lt;/P&gt;
&lt;P&gt;IF you know your table is sorted and you want SAS to set the attribute for verified sorted then use Proc Sort with the PRESORTED option. With this option SAS will first verify if a table is already sorted and only actually sort the table if not confirmed.&lt;/P&gt;
&lt;P&gt;Below code should explain it.&lt;/P&gt;
&lt;P&gt;I'm not sure where the sortedby option adds value to processing as SAS will only use more efficient processing (like in a Proc SQL) if the sort order is verified - which is a table attribute you can't write directly.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=sashelp.class out=class;
  by sex descending name;
run;

proc sql;
    select memname, sorttype
    from dictionary.tables
    where upcase(libname)='WORK' and
          upcase(memname)='CLASS';
quit;

data class (sortedby=sex descending name);
  set sashelp.class;
run;

proc sql;
    select memname, sorttype
    from dictionary.tables
    where upcase(libname)='WORK' and
          upcase(memname)='CLASS';
quit;

proc sort data=work.class presorted;
  by sex descending name;
run;

proc sql;
    select memname, sorttype
    from dictionary.tables
    where upcase(libname)='WORK' and
          upcase(memname)='CLASS';
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1658068621636.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/73372iD3320A0E42D11A13/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1658068621636.png" alt="Patrick_0-1658068621636.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 17 Jul 2022 14:41:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-the-defined-sortedby-values-in-the-metadata/m-p/823718#M325276</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-07-17T14:41:21Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping the defined sortedby values in the metadata</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-the-defined-sortedby-values-in-the-metadata/m-p/824576#M325650</link>
      <description>&lt;P&gt;I see your point. Having the information in the dataset metadata does not ensure that it reflects the actual order of the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you aware of a SAS Online Documentation listing all possible values for SORTTYPE?&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2022 09:51:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-the-defined-sortedby-values-in-the-metadata/m-p/824576#M325650</guid>
      <dc:creator>xxformat_com</dc:creator>
      <dc:date>2022-07-21T09:51:33Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping the defined sortedby values in the metadata</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-the-defined-sortedby-values-in-the-metadata/m-p/824590#M325655</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/184742"&gt;@xxformat_com&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I see your point. Having the information in the dataset metadata does not ensure that it reflects the actual order of the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you aware of a SAS Online Documentation listing all possible values for SORTTYPE?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I'm not but to my knowledge it's only verified or not verified - S or W&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2022 11:06:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-the-defined-sortedby-values-in-the-metadata/m-p/824590#M325655</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-07-21T11:06:25Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping the defined sortedby values in the metadata</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-the-defined-sortedby-values-in-the-metadata/m-p/825055#M325873</link>
      <description>&lt;P&gt;When searching on the net, I could find three other values but I don't know if there is any other one.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;SK when using nodupkey in proc sort or distinct in proc sql&lt;/LI&gt;
&lt;LI&gt;SR when using nodup in proc sort&lt;/LI&gt;
&lt;LI&gt;O when removing the sorting&lt;/LI&gt;
&lt;/UL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc datasets lib = work nolist nodetails;
    modify class (sortedby = _NULL_);
    run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Jul 2022 13:55:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-the-defined-sortedby-values-in-the-metadata/m-p/825055#M325873</guid>
      <dc:creator>xxformat_com</dc:creator>
      <dc:date>2022-07-23T13:55:25Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping the defined sortedby values in the metadata</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-the-defined-sortedby-values-in-the-metadata/m-p/825062#M325877</link>
      <description>&lt;P&gt;Thanks for sharing.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro testIt(param);
  proc sort data=sashelp.class out=class &amp;amp;param;
    by sex descending name;
  run;
  title "Proc Sort with &amp;amp;param";
  proc sql;
      select memname, sorttype
      from dictionary.tables
      where upcase(libname)='WORK' and
            upcase(memname)='CLASS';
  quit;
  title;
%mend;

%testIt();
%testIt(nodupkey);
%testIt(noduprec);
%testIt(nouniquekey);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1658582322847.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/73651iEE6C5FAE891F26C2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1658582322847.png" alt="Patrick_0-1658582322847.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Jul 2022 13:18:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-the-defined-sortedby-values-in-the-metadata/m-p/825062#M325877</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-07-23T13:18:50Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping the defined sortedby values in the metadata</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-the-defined-sortedby-values-in-the-metadata/m-p/836464#M330729</link>
      <description>&lt;P&gt;I've just found this documentation for S (strong) and W (weak):&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/documentation/cdl/en/sclref/59578/HTML/default/viewer.htm#a000143464.htm" target="_blank"&gt;https://support.sas.com/documentation/cdl/en/sclref/59578/HTML/default/viewer.htm#a000143464.htm&lt;/A&gt; &lt;/P&gt;</description>
      <pubDate>Mon, 03 Oct 2022 03:50:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-the-defined-sortedby-values-in-the-metadata/m-p/836464#M330729</guid>
      <dc:creator>xxformat_com</dc:creator>
      <dc:date>2022-10-03T03:50:31Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping the defined sortedby values in the metadata</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-the-defined-sortedby-values-in-the-metadata/m-p/836475#M330733</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/184742"&gt;@xxformat_com&lt;/a&gt;&amp;nbsp;Nice! Same information but links to a more recent SAS version.&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.2/lefunctionsref/p048h4pczkr351n1pk558jo8hcc0.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.2/lefunctionsref/p048h4pczkr351n1pk558jo8hcc0.htm&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Oct 2022 07:35:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-the-defined-sortedby-values-in-the-metadata/m-p/836475#M330733</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-10-03T07:35:11Z</dc:date>
    </item>
  </channel>
</rss>

