<?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 Is SORTED BY important metadata? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Is-SORTED-BY-important-metadata/m-p/594157#M76058</link>
    <description>&lt;P&gt;I have a data set from which a couple sets, identical to the source set, are derived. The original code sorted each derived set one at a time. To speed up the program, I would like to change it to just sort the source data set. But I notice when I do this that the source set's metadata shows "SORTED BY whatever", but the derived sets do not show that they are sorted by anything.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My question is, does it matter? Is there any practical difference between 2 sets with the same exact record order if one's metadata indicates how it is sorted and the other does not?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks. I know kind of a weird question.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data source;
infile datalines dlm=',';
length a $1. b 3.;
input a $ b;
datalines;
a,1
b,2
c,3
d,4
e,5
;
proc sort;
by a;
run;

data derived1 derived2;
set source;
by a;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 04 Oct 2019 16:36:47 GMT</pubDate>
    <dc:creator>Mike_B</dc:creator>
    <dc:date>2019-10-04T16:36:47Z</dc:date>
    <item>
      <title>Is SORTED BY important metadata?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Is-SORTED-BY-important-metadata/m-p/594157#M76058</link>
      <description>&lt;P&gt;I have a data set from which a couple sets, identical to the source set, are derived. The original code sorted each derived set one at a time. To speed up the program, I would like to change it to just sort the source data set. But I notice when I do this that the source set's metadata shows "SORTED BY whatever", but the derived sets do not show that they are sorted by anything.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My question is, does it matter? Is there any practical difference between 2 sets with the same exact record order if one's metadata indicates how it is sorted and the other does not?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks. I know kind of a weird question.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data source;
infile datalines dlm=',';
length a $1. b 3.;
input a $ b;
datalines;
a,1
b,2
c,3
d,4
e,5
;
proc sort;
by a;
run;

data derived1 derived2;
set source;
by a;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Oct 2019 16:36:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Is-SORTED-BY-important-metadata/m-p/594157#M76058</guid>
      <dc:creator>Mike_B</dc:creator>
      <dc:date>2019-10-04T16:36:47Z</dc:date>
    </item>
    <item>
      <title>Re: Is SORTED BY important metadata?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Is-SORTED-BY-important-metadata/m-p/594159#M76059</link>
      <description>Only later on, if you try and do another sort, SAS will attempt to sort it again, whereas if you have a sorted by tag then it knows it's sorted and will not sort it again. &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 04 Oct 2019 16:40:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Is-SORTED-BY-important-metadata/m-p/594159#M76059</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-10-04T16:40:36Z</dc:date>
    </item>
    <item>
      <title>Re: Is SORTED BY important metadata?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Is-SORTED-BY-important-metadata/m-p/594170#M76061</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/97807"&gt;@Mike_B&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use the &lt;A href="https://documentation.sas.com/?docsetId=ledsoptsref&amp;amp;docsetTarget=p1pnjylslu2ryrn1ra3a6ney2bzs.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank" rel="noopener"&gt;SORTEDBY= dataset option&lt;/A&gt; to attach that metadata to the derived datasets (&lt;EM&gt;without&lt;/EM&gt; sorting them):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data derived(sortedby=a) derived2(sortedby=a);
set source;
by a;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Oct 2019 17:08:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Is-SORTED-BY-important-metadata/m-p/594170#M76061</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-10-04T17:08:12Z</dc:date>
    </item>
    <item>
      <title>Re: Is SORTED BY important metadata?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Is-SORTED-BY-important-metadata/m-p/594175#M76062</link>
      <description>&lt;P&gt;For completeness there is this article on "Sorted Datasets" and the "The Sort Indicator". &amp;nbsp;&lt;STRONG&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000766829.htm#a003160983" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000766829.htm#a003160983&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Oct 2019 17:13:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Is-SORTED-BY-important-metadata/m-p/594175#M76062</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2019-10-04T17:13:06Z</dc:date>
    </item>
    <item>
      <title>Re: Is SORTED BY important metadata?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Is-SORTED-BY-important-metadata/m-p/594183#M76063</link>
      <description>&lt;P&gt;Thanks. Found &lt;A title="sort flags" href="http://sasnrd.com/sas-sorted-validated-flag/" target="_blank" rel="noopener"&gt;this article&lt;/A&gt; that elaborates on the concept. So I decided to use the sortedby data set option + the presorted proc sort option.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data derived1(sortedby=a) derived2(sortedby=a);
set source;
by a;
run;

proc sort data=derived1 presorted;
by a;
proc sort data=derived2 presorted;
by a;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Oct 2019 17:42:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Is-SORTED-BY-important-metadata/m-p/594183#M76063</guid>
      <dc:creator>Mike_B</dc:creator>
      <dc:date>2019-10-04T17:42:24Z</dc:date>
    </item>
    <item>
      <title>Re: Is SORTED BY important metadata?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Is-SORTED-BY-important-metadata/m-p/594409#M76064</link>
      <description>&lt;P&gt;&amp;gt;&lt;EM&gt; My question is, does it matter?&lt;/EM&gt;&lt;BR /&gt;This metadata is hugely important if you want to leverage one of SAS's strengths in terms or storage: it keeps data sets sorted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that there are 2 sorted flags. The VALIDATED sort flag is the one that matters as SAS can ignore the flag that you set yourself in some cases. See &lt;A href="http://sasnrd.com/sas-sorted-validated-flag/" target="_self"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The last step when creating a permanent table should be a &lt;FONT face="courier new,courier"&gt;proc sort&lt;/FONT&gt; (with option &lt;FONT face="courier new,courier"&gt;presorted&lt;/FONT&gt; if applicable) so the VALIDATED flag is set. The output data set should also set other options: &lt;FONT face="courier new,courier"&gt;index=&lt;/FONT&gt; if needed, &lt;FONT face="courier new,courier"&gt;compression=&lt;/FONT&gt; to choose the best method for that particular data, and the&lt;FONT face="courier new,courier"&gt;&amp;nbsp;write=&amp;nbsp;alter= &lt;/FONT&gt;options, to avoiding anyone overwriting the data set by accident. The password can be well-known if needed. The goal is to avoid accidental changes. Other useful options can be set too to improve performance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=SUMS 
          out =PRODLIB.FINAL( index   =(CUSTOMER_ID) 
                              compress=char 
                              write   =ProdData 
                              alter   =ProdData
                              label   ="Created %sysfunc(datetime(),datetime20.) by &amp;amp;sysuserid"
                              bufsize =32k
                              bufno   =25
                              pointobs=no)
          presorted;
  by DATE; 
run;&lt;/CODE&gt;&lt;/PRE&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>Mon, 07 Oct 2019 04:18:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Is-SORTED-BY-important-metadata/m-p/594409#M76064</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-10-07T04:18:23Z</dc:date>
    </item>
  </channel>
</rss>

