<?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 Finding the first and last date in dataset in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Finding-the-first-and-last-date-in-dataset/m-p/16605#M3082</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I may have misunderstood the question.&amp;nbsp; But, regardless of whether I did or didn't, an alternative solution would be to just use a datastep.&amp;nbsp; E.g., if I was wrong and you only want the first and last records, then the following might suffice:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have end=last;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if _n_ eq 1 or last then output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Conversely, if you actually do need the minimum and maximum dates in the file, then you could use something like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want (drop=_:);&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have end=last;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain _maxdate _mindate;&lt;/P&gt;&lt;P&gt;&amp;nbsp; _mindate=min(_mindate,thedates);&lt;/P&gt;&lt;P&gt;&amp;nbsp; _maxdate=max(_maxdate,thedates);&lt;/P&gt;&lt;P&gt;&amp;nbsp; if last then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; thedates=_mindate;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; thedates=_maxdate;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 16 Dec 2011 21:35:45 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2011-12-16T21:35:45Z</dc:date>
    <item>
      <title>Finding the first and last date in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Finding-the-first-and-last-date-in-dataset/m-p/16602#M3079</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to find what the older and most recent dates in a dataset are. I am not concerend with the first and last dates by ID, but simply the first date (one line, one date) and the last date (one line, one date) in the data file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there any way to do this? Only two lines of data would be needed, one line with the first date and a second line with the last date. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for any help you can provide. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HyunJee&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 16 Dec 2011 15:51:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Finding-the-first-and-last-date-in-dataset/m-p/16602#M3079</guid>
      <dc:creator>HyunJee</dc:creator>
      <dc:date>2011-12-16T15:51:33Z</dc:date>
    </item>
    <item>
      <title>Finding the first and last date in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Finding-the-first-and-last-date-in-dataset/m-p/16603#M3080</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; informat thedates date9.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format thedates date9.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input thedates;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;01dec2011&lt;/P&gt;&lt;P&gt;02dec2011&lt;/P&gt;&lt;P&gt;03dec2011&lt;/P&gt;&lt;P&gt;04dec2011&lt;/P&gt;&lt;P&gt;05dec2011&lt;/P&gt;&lt;P&gt;06dec2011&lt;/P&gt;&lt;P&gt;07dec2011&lt;/P&gt;&lt;P&gt;08dec2011&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table want as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select distinct thedates&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from have&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; having thedates=min(thedates) or&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; thedates=max(thedates)&lt;/P&gt;&lt;P&gt;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 16 Dec 2011 15:58:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Finding-the-first-and-last-date-in-dataset/m-p/16603#M3080</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-12-16T15:58:09Z</dc:date>
    </item>
    <item>
      <title>Finding the first and last date in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Finding-the-first-and-last-date-in-dataset/m-p/16604#M3081</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; If you have access to SAS/ETS by any means you might want to consider using PROC TIMESERIES as well.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Udo&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; informat thedates date9. other;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format thedates date9.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input thedates other;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;01dec2011 1&lt;/P&gt;&lt;P&gt;02dec2011 1&lt;/P&gt;&lt;P&gt;03dec2011 1&lt;/P&gt;&lt;P&gt;04dec2011 1&lt;/P&gt;&lt;P&gt;05dec2011 2&lt;/P&gt;&lt;P&gt;06dec2011 2&lt;/P&gt;&lt;P&gt;07dec2011 2&lt;/P&gt;&lt;P&gt;08dec2011 2&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;proc timeseries data=have out=_null_ outsum=need(keep=_name_ start end);&lt;/P&gt;&lt;P&gt;id thedates interval=day;&lt;/P&gt;&lt;P&gt;var other;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 16 Dec 2011 18:45:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Finding-the-first-and-last-date-in-dataset/m-p/16604#M3081</guid>
      <dc:creator>udo_sas</dc:creator>
      <dc:date>2011-12-16T18:45:05Z</dc:date>
    </item>
    <item>
      <title>Finding the first and last date in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Finding-the-first-and-last-date-in-dataset/m-p/16605#M3082</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I may have misunderstood the question.&amp;nbsp; But, regardless of whether I did or didn't, an alternative solution would be to just use a datastep.&amp;nbsp; E.g., if I was wrong and you only want the first and last records, then the following might suffice:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have end=last;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if _n_ eq 1 or last then output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Conversely, if you actually do need the minimum and maximum dates in the file, then you could use something like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want (drop=_:);&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have end=last;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain _maxdate _mindate;&lt;/P&gt;&lt;P&gt;&amp;nbsp; _mindate=min(_mindate,thedates);&lt;/P&gt;&lt;P&gt;&amp;nbsp; _maxdate=max(_maxdate,thedates);&lt;/P&gt;&lt;P&gt;&amp;nbsp; if last then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; thedates=_mindate;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; thedates=_maxdate;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 16 Dec 2011 21:35:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Finding-the-first-and-last-date-in-dataset/m-p/16605#M3082</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-12-16T21:35:45Z</dc:date>
    </item>
    <item>
      <title>Finding the first and last date in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Finding-the-first-and-last-date-in-dataset/m-p/16606#M3083</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is a way using PROC SQL.&amp;nbsp; But if there is only one date value you will get a dataset with only one observation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql noprint ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table minmax as select distinct DATE&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from have having DATE= min(DATE) or DATE= max(DATE)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; order by 1&lt;/P&gt;&lt;P&gt;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You could pull out min and max as two columns and then transpose.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 17 Dec 2011 00:28:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Finding-the-first-and-last-date-in-dataset/m-p/16606#M3083</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2011-12-17T00:28:36Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the first and last date in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Finding-the-first-and-last-date-in-dataset/m-p/16607#M3084</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; informat thedates date9.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format thedates date9.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input thedates;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;01dec2011&lt;/P&gt;&lt;P&gt;02dec2011&lt;/P&gt;&lt;P&gt;03dec2011&lt;/P&gt;&lt;P&gt;04dec2011&lt;/P&gt;&lt;P&gt;05dec2011&lt;/P&gt;&lt;P&gt;06dec2011&lt;/P&gt;&lt;P&gt;07dec2011&lt;/P&gt;&lt;P&gt;08dec2011&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table want as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select min(thedates) as min_date format=date9.,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; max(thedates) as max_date format=date9.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from have;&lt;/P&gt;&lt;P&gt; quit;&lt;/P&gt;&lt;P&gt; proc print; title from dataset &amp;amp;syslast;run;&lt;/P&gt;&lt;P&gt; proc transpose data=want out=new(rename=(_name_=date)) ;&lt;/P&gt;&lt;P&gt; run;&lt;/P&gt;&lt;P&gt; proc print; title from dataset &amp;amp;syslast;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Linlin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 17 Dec 2011 01:00:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Finding-the-first-and-last-date-in-dataset/m-p/16607#M3084</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2011-12-17T01:00:53Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the first and last date in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Finding-the-first-and-last-date-in-dataset/m-p/16608#M3085</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This code works great. This is a correct answer also, but I could only make as helpful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for your help and providing an example code. Extremely helpful &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Dec 2011 16:50:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Finding-the-first-and-last-date-in-dataset/m-p/16608#M3085</guid>
      <dc:creator>HyunJee</dc:creator>
      <dc:date>2011-12-19T16:50:15Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the first and last date in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Finding-the-first-and-last-date-in-dataset/m-p/16609#M3086</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I like how this code prints out the min and max date of interest. Thank you very much for providing the example code!&lt;/P&gt;&lt;P&gt; &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Dec 2011 16:51:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Finding-the-first-and-last-date-in-dataset/m-p/16609#M3086</guid>
      <dc:creator>HyunJee</dc:creator>
      <dc:date>2011-12-19T16:51:35Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the first and last date in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Finding-the-first-and-last-date-in-dataset/m-p/16610#M3087</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The solution you provided was helpful also and provided the needed result. Thank you!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Dec 2011 16:52:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Finding-the-first-and-last-date-in-dataset/m-p/16610#M3087</guid>
      <dc:creator>HyunJee</dc:creator>
      <dc:date>2011-12-19T16:52:48Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the first and last date in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Finding-the-first-and-last-date-in-dataset/m-p/16611#M3088</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you to everyone for you input and assistance. Extremely helpful!!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Dec 2011 16:53:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Finding-the-first-and-last-date-in-dataset/m-p/16611#M3088</guid>
      <dc:creator>HyunJee</dc:creator>
      <dc:date>2011-12-19T16:53:16Z</dc:date>
    </item>
  </channel>
</rss>

