<?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 By Multiple Variables in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Sorting-By-Multiple-Variables/m-p/648672#M22228</link>
    <description>Why would it show literally different days though?</description>
    <pubDate>Mon, 18 May 2020 19:24:59 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2020-05-18T19:24:59Z</dc:date>
    <item>
      <title>Sorting By Multiple Variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sorting-By-Multiple-Variables/m-p/648660#M22225</link>
      <description>&lt;P&gt;&lt;FONT size="2"&gt;Hello,&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;I am having trouble sorting my data by multiple variables.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data = ohstim.combined_stimulation_03;
          BY			    API_WELL_NO
		      DESCENDING 	DT_MODIFIED_STIMULATION
			             	DT_TREATMENT;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;FONT size="2"&gt;Using this code, I get the below results for the observations with API_WELL_NO of "01133244410000".&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Sorting Issues.JPG" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/39566i119B05CF4F3204C9/image-size/large?v=v2&amp;amp;px=999" role="button" title="Sorting Issues.JPG" alt="Sorting Issues.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;The observation I want to appear first is the one with the most recent DT_MODIFIED_STIMULATION value ("28MAR13") and the oldest DT_TREATMENT value ("12DEC12")&lt;/FONT&gt;&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;&lt;FONT size="2"&gt;The first two variables (API_WELL_NO and DT_MODIFIED_STIMULATION) are sorting correctly, but the third variable (DT_TREATMENT) is not. I think this has something to do with the identical DT_MODIFIED_STIMULATION values. For some reason, when they are identical SAS seems unable to sort them correctly.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;I need these observations to be in the correct order because I am using the below code to remove duplicates, so that only the first entry for each API_WELL_NO is retained.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data = ohstim.combined_stimulation_03 nodupkey equals;
	BY	API_WELL_NO;
run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;FONT size="2"&gt;My code is attached. Any help figuring this out would be greatly appreciated!!&lt;/FONT&gt;&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>Mon, 18 May 2020 18:57:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sorting-By-Multiple-Variables/m-p/648660#M22225</guid>
      <dc:creator>JJ_83</dc:creator>
      <dc:date>2020-05-18T18:57:58Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting By Multiple Variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sorting-By-Multiple-Variables/m-p/648666#M22226</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data = ohstim.combined_stimulation_03;
          BY			    API_WELL_NO
		      DESCENDING 	DT_MODIFIED_STIMULATION
		      DT_TREATMENT;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you post the exact code you ran including your log? The descending should only apply to the first variable the way I understand it, but it seems to be applied to both dt_modified_simulation and DT_Treatment here for some reason.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your results seem to align with this code, not the code you posted above.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data = ohstim.combined_stimulation_03;
          BY			    API_WELL_NO
		      DESCENDING 	DT_MODIFIED_STIMULATION
		      descending DT_TREATMENT;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/329582"&gt;@JJ_83&lt;/a&gt;&amp;nbsp;wrote:
&lt;P&gt;&lt;FONT size="2"&gt;My code is attached. Any help figuring this out would be greatly appreciated!!&lt;/FONT&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;FYI - your code isn't attached, your data sets are attached.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/329582"&gt;@JJ_83&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;FONT size="2"&gt;Hello,&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;I am having trouble sorting my data by multiple variables.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data = ohstim.combined_stimulation_03;
          BY			    API_WELL_NO
		      DESCENDING 	DT_MODIFIED_STIMULATION
			             	DT_TREATMENT;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT size="2"&gt;Using this code, I get the below results for the observations with API_WELL_NO of "01133244410000".&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Sorting Issues.JPG" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/39566i119B05CF4F3204C9/image-size/large?v=v2&amp;amp;px=999" role="button" title="Sorting Issues.JPG" alt="Sorting Issues.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;The observation I want to appear first is the one with the most recent DT_MODIFIED_STIMULATION value ("28MAR13") and the oldest DT_TREATMENT value ("12DEC12")&lt;/FONT&gt;&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;&lt;FONT size="2"&gt;The first two variables (API_WELL_NO and DT_MODIFIED_STIMULATION) are sorting correctly, but the third variable (DT_TREATMENT) is not. I think this has something to do with the identical DT_MODIFIED_STIMULATION values. For some reason, when they are identical SAS seems unable to sort them correctly.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;I need these observations to be in the correct order because I am using the below code to remove duplicates, so that only the first entry for each API_WELL_NO is retained.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data = ohstim.combined_stimulation_03 nodupkey equals;
	BY	API_WELL_NO;
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT size="2"&gt;My code is attached. Any help figuring this out would be greatly appreciated!!&lt;/FONT&gt;&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;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 May 2020 19:12:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sorting-By-Multiple-Variables/m-p/648666#M22226</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-05-18T19:12:33Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting By Multiple Variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sorting-By-Multiple-Variables/m-p/648670#M22227</link>
      <description>&lt;P&gt;Longish shot but is your Dt_modified_stimulation variable perhaps a datetime value with a format that only shows the date portion? If that is the case it could be there is only one value for the Dt_treatment variable and so it appears out of sequence.&lt;/P&gt;</description>
      <pubDate>Mon, 18 May 2020 19:21:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sorting-By-Multiple-Variables/m-p/648670#M22227</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-05-18T19:21:48Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting By Multiple Variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sorting-By-Multiple-Variables/m-p/648672#M22228</link>
      <description>Why would it show literally different days though?</description>
      <pubDate>Mon, 18 May 2020 19:24:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sorting-By-Multiple-Variables/m-p/648672#M22228</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-05-18T19:24:59Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting By Multiple Variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sorting-By-Multiple-Variables/m-p/648679#M22229</link>
      <description>&lt;P&gt;I am thinking more about the associated date values and that the first after descending is not a unique value at the date level but could be when the time is included.&lt;/P&gt;
&lt;P&gt;Consider:&lt;/P&gt;
&lt;PRE&gt;data example;
   input x :datetime. y :date9.;
   format x dtdate9. y date9.;
datalines;
01Jan2020:01:00:00  08dec2019
01Jan2020:02:00:00  09dec2019
01Jan2020:03:00:00  10dec2019
01Jan2020:04:00:00  11dec2019
01Jan2020:05:00:00  12dec2019
01Jan2020:06:00:00  13dec2019
;

Proc sort data=example;
   by descending x;
run;

proc print data=example;
run;&lt;/PRE&gt;
&lt;P&gt;With only ONE Y value for each X value it appears as if the Y is sorted descending (because of the values I picked) but the X has a single day value. I did not include the Y in the sort to minimize any confusion that a "descending" may have also applied to Y.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It should be unlikely, but "unlikely" does not mean "never happens". So if other suggestions don't solve then perhaps looking at it with a slightly twisted perspective may be needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A similar order issue can also occur with Date values that somehow end up with a decimal portion. I won't say how long it took me trace that issue down in a data set...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2020 14:44:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sorting-By-Multiple-Variables/m-p/648679#M22229</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-05-19T14:44:03Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting By Multiple Variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sorting-By-Multiple-Variables/m-p/648835#M22240</link>
      <description>&lt;P&gt;Hi Reeza,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for letting me know. I have attached my code exactly as I have run it, and my log.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2020 13:46:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sorting-By-Multiple-Variables/m-p/648835#M22240</guid>
      <dc:creator>JJ_83</dc:creator>
      <dc:date>2020-05-19T13:46:24Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting By Multiple Variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sorting-By-Multiple-Variables/m-p/648847#M22241</link>
      <description>&lt;P&gt;Hi Ballardw,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the idea, it looks like that is exactly what is going on! I would never have thought of that!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you have any advice on how to remove the time stamp from the DT_MODIFIED_STIMULATION variable?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2020 14:14:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sorting-By-Multiple-Variables/m-p/648847#M22241</guid>
      <dc:creator>JJ_83</dc:creator>
      <dc:date>2020-05-19T14:14:11Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting By Multiple Variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sorting-By-Multiple-Variables/m-p/648865#M22242</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/329582"&gt;@JJ_83&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi Ballardw,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for the idea, it looks like that is exactly what is going on! I would never have thought of that!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you have any advice on how to remove the time stamp from the DT_MODIFIED_STIMULATION variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;There are several choices. Easiest would be create a new variable with just the date component using the datepart function:&lt;/P&gt;
&lt;PRE&gt;dateonly = datepart(Dt_modified_stimulation);
format dateonly date9.;&lt;/PRE&gt;
&lt;P&gt;Pick your preferred date variable name instead of dateonly.&lt;/P&gt;
&lt;P&gt;Other options would be to replace the existing variable the same way using your existing variable as the target name. You &lt;STRONG&gt;really&lt;/STRONG&gt; need to change the format in this case.&lt;/P&gt;
&lt;P&gt;Or you could change the time component to the start or end of the day using the INTNX function.&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2020 14:49:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sorting-By-Multiple-Variables/m-p/648865#M22242</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-05-19T14:49:26Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting By Multiple Variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sorting-By-Multiple-Variables/m-p/649893#M22310</link>
      <description>&lt;P&gt;Using the datepart approach worked perfectly! Thank you so much!&lt;/P&gt;</description>
      <pubDate>Fri, 22 May 2020 12:50:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sorting-By-Multiple-Variables/m-p/649893#M22310</guid>
      <dc:creator>JJ_83</dc:creator>
      <dc:date>2020-05-22T12:50:21Z</dc:date>
    </item>
  </channel>
</rss>

