<?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: Start date and end date in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Start-date-and-end-date/m-p/796784#M33017</link>
    <description>&lt;P&gt;It would help immensely if you provide sample data, expected output and anything you've tried.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is your definition of first and last?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you cannot provide your actual data for some reason, please make fake data that represents your problem.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need a data set with dates as an example, use sashelp.stocks which has stock data over time.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if this was your data set what do you want as output.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data IBM;
set stocks;
where stock='IBM';
keep date;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/338281"&gt;@Sharan&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I have a series of dates in the dates column in the format 01jan2005.&lt;BR /&gt;How do I find the first date and last date? Please&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Generic questions otherwise, get a generic answer.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming first and last actually mean minimum and maximum dates, use proc means to get the min/max of the column and you have the first and last date.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 17 Feb 2022 03:38:01 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2022-02-17T03:38:01Z</dc:date>
    <item>
      <title>Start date and end date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Start-date-and-end-date/m-p/796783#M33016</link>
      <description>I have a series of dates in the dates column in the format 01jan2005.&lt;BR /&gt;How do I find the first date and last date? Please</description>
      <pubDate>Thu, 17 Feb 2022 03:13:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Start-date-and-end-date/m-p/796783#M33016</guid>
      <dc:creator>Sharan</dc:creator>
      <dc:date>2022-02-17T03:13:42Z</dc:date>
    </item>
    <item>
      <title>Re: Start date and end date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Start-date-and-end-date/m-p/796784#M33017</link>
      <description>&lt;P&gt;It would help immensely if you provide sample data, expected output and anything you've tried.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is your definition of first and last?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you cannot provide your actual data for some reason, please make fake data that represents your problem.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need a data set with dates as an example, use sashelp.stocks which has stock data over time.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if this was your data set what do you want as output.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data IBM;
set stocks;
where stock='IBM';
keep date;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/338281"&gt;@Sharan&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I have a series of dates in the dates column in the format 01jan2005.&lt;BR /&gt;How do I find the first date and last date? Please&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Generic questions otherwise, get a generic answer.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming first and last actually mean minimum and maximum dates, use proc means to get the min/max of the column and you have the first and last date.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Feb 2022 03:38:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Start-date-and-end-date/m-p/796784#M33017</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-02-17T03:38:01Z</dc:date>
    </item>
    <item>
      <title>Re: Start date and end date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Start-date-and-end-date/m-p/796792#M33018</link>
      <description>My data set looks like below:&lt;BR /&gt;&lt;BR /&gt;Dispense date of antibiotic&lt;BR /&gt;&lt;BR /&gt;03Sep2010&lt;BR /&gt;01Jan2005&lt;BR /&gt;30Jan2006&lt;BR /&gt;06 Apr2008&lt;BR /&gt;01Jan2009&lt;BR /&gt;30Jan2018&lt;BR /&gt;06 Apr2018&lt;BR /&gt;01Jan2015&lt;BR /&gt;30Jan2006&lt;BR /&gt;06 Apr2018&lt;BR /&gt;01Jan2005&lt;BR /&gt;30Jan2006&lt;BR /&gt;16 Apr2008&lt;BR /&gt;18Dec2020&lt;BR /&gt;05Jun2019&lt;BR /&gt;&lt;BR /&gt;so here the earliest date is 01Jan2005&lt;BR /&gt;and the latest date is 18Dec2020&lt;BR /&gt;&lt;BR /&gt;So please explain how i can obtain the two dates.&lt;BR /&gt;Thank you!&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 17 Feb 2022 04:28:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Start-date-and-end-date/m-p/796792#M33018</guid>
      <dc:creator>Sharan</dc:creator>
      <dc:date>2022-02-17T04:28:45Z</dc:date>
    </item>
    <item>
      <title>Re: Start date and end date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Start-date-and-end-date/m-p/796793#M33019</link>
      <description>&lt;DIV&gt;My data set looks like below:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Dispense date of antibiotic&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;03Sep2010&lt;/DIV&gt;&lt;DIV&gt;01Jan2005&lt;/DIV&gt;&lt;DIV&gt;30Jan2006&lt;/DIV&gt;&lt;DIV&gt;06 Apr2008&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;01Jan2009&lt;/SPAN&gt;&lt;DIV&gt;30Jan2018&lt;/DIV&gt;&lt;SPAN&gt;06 Apr2018&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;01Jan2015&lt;/SPAN&gt;&lt;DIV&gt;30Jan2006&lt;/DIV&gt;&lt;SPAN&gt;06 Apr2018&lt;BR /&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;01Jan2005&lt;/SPAN&gt;&lt;DIV&gt;30Jan2006&lt;/DIV&gt;&lt;SPAN&gt;16 Apr2008&lt;BR /&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;18Dec2020&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;05Jun2019&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;so here the earliest date is 01Jan2005&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;and the latest date is 18Dec2020&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;So please explain how I can obtain the two dates.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Thank you!&lt;/SPAN&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 17 Feb 2022 04:29:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Start-date-and-end-date/m-p/796793#M33019</guid>
      <dc:creator>Sharan</dc:creator>
      <dc:date>2022-02-17T04:29:16Z</dc:date>
    </item>
    <item>
      <title>Re: Start date and end date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Start-date-and-end-date/m-p/796796#M33020</link>
      <description>&lt;P&gt;Do you want report? If so, what would the report look like?&lt;/P&gt;
&lt;P&gt;If you want a data set, what does that look like?&lt;/P&gt;
&lt;P&gt;For the entire set? Or some sort of subset like each person/location/activity?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: Appearance, which is all a format is, has nothing to do with comparisons that might be used such earliest (minimum numeric value) or latest (maximum numeric value).&lt;/P&gt;</description>
      <pubDate>Thu, 17 Feb 2022 04:50:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Start-date-and-end-date/m-p/796796#M33020</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-02-17T04:50:47Z</dc:date>
    </item>
    <item>
      <title>Re: Start date and end date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Start-date-and-end-date/m-p/796807#M33021</link>
      <description>&lt;P&gt;If these are SAS dates and not just strings that look like dates, then this will get your values:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select
  min(date) as first format=yymmdd10.,
  max(date) as last format=yymmdd10.
from have;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Feb 2022 07:13:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Start-date-and-end-date/m-p/796807#M33021</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-02-17T07:13:13Z</dc:date>
    </item>
    <item>
      <title>Re: Start date and end date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Start-date-and-end-date/m-p/796808#M33022</link>
      <description>&lt;P&gt;You are working with datasets that has only one variable? Interesting.&lt;/P&gt;
&lt;P&gt;You could use proc summary/means:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have;
   var date;
   output out=firstlast(drop= _:) min=first_date max=last_date;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Feb 2022 07:26:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Start-date-and-end-date/m-p/796808#M33022</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-02-17T07:26:16Z</dc:date>
    </item>
    <item>
      <title>Re: Start date and end date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Start-date-and-end-date/m-p/796809#M33023</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input date date9.;
format date date9.;
cards;
03Sep2010
01Jan2005
30Jan2006
06Apr2008
01Jan2009
30Jan2018
06Apr2018
01Jan2015
30Jan2006
06Apr2018
01Jan2005
30Jan2006
16Apr2008
18Dec2020
05Jun2019
;
run;
proc print;
run;

/* first way O(n) */
data want1;
  set have end=end;
  first = min(first, date);
  last  = max(last,  date);
  put _all_;
  retain first last;

  if end then output;
  format first last date9.;
run;
proc print;
run;


/* second way ~O(nlogn) [assuming "good" quicksort] :-) */
proc sort data = have out = want2;
 by date;
run;
data want2;
  point = 1;
  set want2 point = point nobs=nobs;
  first = date;
  set want2 point = nobs;
  last = date;
  output;
  stop;
  format first last date9.;
run;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;B.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Feb 2022 08:06:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Start-date-and-end-date/m-p/796809#M33023</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2022-02-17T08:06:27Z</dc:date>
    </item>
  </channel>
</rss>

