<?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 sorting data by dates in character form in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/sorting-data-by-dates-in-character-form/m-p/456075#M115484</link>
    <description>&lt;P&gt;Dear,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a quick question about sorting data by dates which are in character form. (eg. sorting data in ex dataset by usubjid and exstdtc ( character date) and finding first.obs or last.obs.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is it ok to sort data with out converting the exstdtc to numeric form and then find first.obs and last.obs (or) it is required to convert to numeric form and do the data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Please suggest.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 20 Apr 2018 20:25:13 GMT</pubDate>
    <dc:creator>knveraraju91</dc:creator>
    <dc:date>2018-04-20T20:25:13Z</dc:date>
    <item>
      <title>sorting data by dates in character form</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sorting-data-by-dates-in-character-form/m-p/456075#M115484</link>
      <description>&lt;P&gt;Dear,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a quick question about sorting data by dates which are in character form. (eg. sorting data in ex dataset by usubjid and exstdtc ( character date) and finding first.obs or last.obs.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is it ok to sort data with out converting the exstdtc to numeric form and then find first.obs and last.obs (or) it is required to convert to numeric form and do the data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Please suggest.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Apr 2018 20:25:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sorting-data-by-dates-in-character-form/m-p/456075#M115484</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2018-04-20T20:25:13Z</dc:date>
    </item>
    <item>
      <title>Re: sorting data by dates in character form</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sorting-data-by-dates-in-character-form/m-p/456080#M115485</link>
      <description>It depends. What format are the dates in? If it's YYMMDD it'll naturally sort out. If its Date9 it won't because 01Aug is alphabetically before 01Jan.</description>
      <pubDate>Fri, 20 Apr 2018 20:31:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sorting-data-by-dates-in-character-form/m-p/456080#M115485</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-04-20T20:31:55Z</dc:date>
    </item>
    <item>
      <title>Re: sorting data by dates in character form</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sorting-data-by-dates-in-character-form/m-p/456081#M115486</link>
      <description>&lt;P&gt;There's no reason for storing dates as character. Numeric dates can be stored in 4 bytes (less than any character date), and they can be used directly in date functions and with date formats. On top of that, they always sort in correct temporal order.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Apr 2018 20:32:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sorting-data-by-dates-in-character-form/m-p/456081#M115486</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-04-20T20:32:36Z</dc:date>
    </item>
    <item>
      <title>Re: sorting data by dates in character form</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sorting-data-by-dates-in-character-form/m-p/456091#M115489</link>
      <description>&lt;P&gt;If you want to use first. and last. and not to create a numeric variable, you can try something like this:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
select *,case when INPUT(Date,DATE9.)=min(INPUT(Date,DATE9.)) then "First"
			  When INPUT(Date,DATE9.)=max(INPUT(Date,DATE9.)) then "Last"
			  else " " end as F_L
	from test
	Group by ID
order by ID,INPUT(Date,DATE9.);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Apr 2018 21:01:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sorting-data-by-dates-in-character-form/m-p/456091#M115489</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-04-20T21:01:38Z</dc:date>
    </item>
    <item>
      <title>Re: sorting data by dates in character form</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sorting-data-by-dates-in-character-form/m-p/456099#M115495</link>
      <description>&lt;P&gt;What appearance do your current character-valued dates have?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;About the only one that sorts correctly with regularity is a yyyymmdd or one of its variants where mm(month) and dd(day) have leading zeroes. 2017-2-18 would come after 2017-11-15, or 2018-2-9 2018-2-12&amp;nbsp;&amp;nbsp;because character comparisons for sorting are done left to right&lt;/P&gt;
&lt;P&gt;(the -2 is after -1 in the first case and -9 after -1 in the second). So to get those to sort properly you need 2017-02-18 2018-02-09 and 2018-02-12.&lt;/P&gt;
&lt;P&gt;Two digits years are also a potential issue if the data crosses the century boundary: 990105&amp;nbsp; (5Jan1999) would come after 051212 (12Dec2005) as the 99 comes after 05.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the dates are mmddyy then order would basically ignore year as 01012018 would come before 01022017.&lt;/P&gt;
&lt;P&gt;if the dates are ddmmyy then you would have the first of all months then the second 01012018 01022018 01032018 then 0201208 (back to January).&lt;/P&gt;
&lt;P&gt;Date9 or Date7 (05Jan2017) would have April and August before January, February and March...&lt;/P&gt;</description>
      <pubDate>Fri, 20 Apr 2018 21:42:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sorting-data-by-dates-in-character-form/m-p/456099#M115495</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-04-20T21:42:13Z</dc:date>
    </item>
  </channel>
</rss>

