<?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 How to create the min and max of the date with conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-the-min-and-max-of-the-date-with-conditions/m-p/698769#M213728</link>
    <description>&lt;P&gt;Hi, I am having one problem that I could not figure out how to do this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is an example of the data I have:&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input patient $ admitted_date :mmddyy10. discharge_date :mmddyy10. disposition $50.;format admitted_date discharge_date yymmdd10.;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;A 3/2/2020&amp;nbsp; 3/15/2020 transferred to other hospital&lt;/P&gt;&lt;P&gt;A 3/15/2020 4/2/2020&amp;nbsp; home&lt;/P&gt;&lt;P&gt;B 5/3/2020&amp;nbsp; 6/27/2020 transferred to other hospital&lt;/P&gt;&lt;P&gt;B 6/27/2020 6/29/2020 home&lt;/P&gt;&lt;P&gt;C 8/1/2020&amp;nbsp; 8/25/2020 died&lt;/P&gt;&lt;P&gt;D 5/15/2020 6/1/2020&amp;nbsp; transferred to other hospital&lt;/P&gt;&lt;P&gt;D 6/1/2020&amp;nbsp; 7/2/2020&amp;nbsp; home&lt;/P&gt;&lt;P&gt;A 6/2/2020&amp;nbsp; 6/25/2020 died&lt;/P&gt;&lt;P&gt;B 8/1/2020&amp;nbsp; 8/2/2020&amp;nbsp; transferred to other hospital&lt;/P&gt;&lt;P&gt;B 8/2/2020&amp;nbsp; 8/15/2020 transferred to other hospital&lt;/P&gt;&lt;P&gt;B 8/15/2020 8/25/2020 died;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Patient got to the hospital and maybe they got transferred to other hospitals because of the low bed capacity. I only want to capture them as 1 admission to the hospital (if they got transferred). However, they could get admitted again after that, their admission_count will be 2 (or even 3,4,5 times if they had to go to the hospitals again) . From the data above, I want something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Patient&lt;/TD&gt;&lt;TD&gt;admitted date&lt;/TD&gt;&lt;TD&gt;discharge_date&lt;/TD&gt;&lt;TD&gt;disposition&lt;/TD&gt;&lt;TD&gt;Min(admitted_date)&lt;/TD&gt;&lt;TD&gt;Max(discharge_date)&lt;/TD&gt;&lt;TD&gt;admission_count&lt;/TD&gt;&lt;TD&gt;final_disposition&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;3/2/2020&lt;/TD&gt;&lt;TD&gt;3/15/2020&lt;/TD&gt;&lt;TD&gt;transferred to other hospital&lt;/TD&gt;&lt;TD&gt;3/2/2020&lt;/TD&gt;&lt;TD&gt;4/2/2020&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;home&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;3/15/2020&lt;/TD&gt;&lt;TD&gt;4/2/2020&lt;/TD&gt;&lt;TD&gt;home&lt;/TD&gt;&lt;TD&gt;3/2/2020&lt;/TD&gt;&lt;TD&gt;4/2/2020&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;home&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;5/3/2020&lt;/TD&gt;&lt;TD&gt;6/27/2020&lt;/TD&gt;&lt;TD&gt;transferred to other hospital&lt;/TD&gt;&lt;TD&gt;5/3/2020&lt;/TD&gt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gt;6/25/2020&lt;/TD&gt;&lt;TD&gt;died&lt;/TD&gt;&lt;TD&gt;6/2/2020&lt;/TD&gt;&lt;TD&gt;6/25/2020&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;died&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;8/1/2020&lt;/TD&gt;&lt;TD&gt;8/2/2020&lt;/TD&gt;&lt;TD&gt;transferred to other hospital&lt;/TD&gt;&lt;TD&gt;8/1/2020&lt;/TD&gt;&lt;TD&gt;8/25/2020&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;died&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;8/2/2020&lt;/TD&gt;&lt;TD&gt;8/15/2020&lt;/TD&gt;&lt;TD&gt;transferred to other hospital&lt;/TD&gt;&lt;TD&gt;8/1/2020&lt;/TD&gt;&lt;TD&gt;8/25/2020&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;died&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;8/15/2020&lt;/TD&gt;&lt;TD&gt;8/25/2020&lt;/TD&gt;&lt;TD&gt;died&lt;/TD&gt;&lt;TD&gt;8/1/2020&lt;/TD&gt;&lt;TD&gt;8/25/2020&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;died&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help! I don't know how to do this &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much!&lt;/P&gt;</description>
    <pubDate>Mon, 16 Nov 2020 14:14:37 GMT</pubDate>
    <dc:creator>huongc2</dc:creator>
    <dc:date>2020-11-16T14:14:37Z</dc:date>
    <item>
      <title>How to create the min and max of the date with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-the-min-and-max-of-the-date-with-conditions/m-p/698769#M213728</link>
      <description>&lt;P&gt;Hi, I am having one problem that I could not figure out how to do this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is an example of the data I have:&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input patient $ admitted_date :mmddyy10. discharge_date :mmddyy10. disposition $50.;format admitted_date discharge_date yymmdd10.;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;A 3/2/2020&amp;nbsp; 3/15/2020 transferred to other hospital&lt;/P&gt;&lt;P&gt;A 3/15/2020 4/2/2020&amp;nbsp; home&lt;/P&gt;&lt;P&gt;B 5/3/2020&amp;nbsp; 6/27/2020 transferred to other hospital&lt;/P&gt;&lt;P&gt;B 6/27/2020 6/29/2020 home&lt;/P&gt;&lt;P&gt;C 8/1/2020&amp;nbsp; 8/25/2020 died&lt;/P&gt;&lt;P&gt;D 5/15/2020 6/1/2020&amp;nbsp; transferred to other hospital&lt;/P&gt;&lt;P&gt;D 6/1/2020&amp;nbsp; 7/2/2020&amp;nbsp; home&lt;/P&gt;&lt;P&gt;A 6/2/2020&amp;nbsp; 6/25/2020 died&lt;/P&gt;&lt;P&gt;B 8/1/2020&amp;nbsp; 8/2/2020&amp;nbsp; transferred to other hospital&lt;/P&gt;&lt;P&gt;B 8/2/2020&amp;nbsp; 8/15/2020 transferred to other hospital&lt;/P&gt;&lt;P&gt;B 8/15/2020 8/25/2020 died;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Patient got to the hospital and maybe they got transferred to other hospitals because of the low bed capacity. I only want to capture them as 1 admission to the hospital (if they got transferred). However, they could get admitted again after that, their admission_count will be 2 (or even 3,4,5 times if they had to go to the hospitals again) . From the data above, I want something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Patient&lt;/TD&gt;&lt;TD&gt;admitted date&lt;/TD&gt;&lt;TD&gt;discharge_date&lt;/TD&gt;&lt;TD&gt;disposition&lt;/TD&gt;&lt;TD&gt;Min(admitted_date)&lt;/TD&gt;&lt;TD&gt;Max(discharge_date)&lt;/TD&gt;&lt;TD&gt;admission_count&lt;/TD&gt;&lt;TD&gt;final_disposition&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;3/2/2020&lt;/TD&gt;&lt;TD&gt;3/15/2020&lt;/TD&gt;&lt;TD&gt;transferred to other hospital&lt;/TD&gt;&lt;TD&gt;3/2/2020&lt;/TD&gt;&lt;TD&gt;4/2/2020&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;home&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;3/15/2020&lt;/TD&gt;&lt;TD&gt;4/2/2020&lt;/TD&gt;&lt;TD&gt;home&lt;/TD&gt;&lt;TD&gt;3/2/2020&lt;/TD&gt;&lt;TD&gt;4/2/2020&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;home&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;5/3/2020&lt;/TD&gt;&lt;TD&gt;6/27/2020&lt;/TD&gt;&lt;TD&gt;transferred to other hospital&lt;/TD&gt;&lt;TD&gt;5/3/2020&lt;/TD&gt;&lt;TD&gt;6/29/2020&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;home&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&g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D&gt;2&lt;/TD&gt;&lt;TD&gt;died&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;8/1/2020&lt;/TD&gt;&lt;TD&gt;8/2/2020&lt;/TD&gt;&lt;TD&gt;transferred to other hospital&lt;/TD&gt;&lt;TD&gt;8/1/2020&lt;/TD&gt;&lt;TD&gt;8/25/2020&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;died&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;8/2/2020&lt;/TD&gt;&lt;TD&gt;8/15/2020&lt;/TD&gt;&lt;TD&gt;transferred to other hospital&lt;/TD&gt;&lt;TD&gt;8/1/2020&lt;/TD&gt;&lt;TD&gt;8/25/2020&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;died&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;8/15/2020&lt;/TD&gt;&lt;TD&gt;8/25/2020&lt;/TD&gt;&lt;TD&gt;died&lt;/TD&gt;&lt;TD&gt;8/1/2020&lt;/TD&gt;&lt;TD&gt;8/25/2020&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;died&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help! I don't know how to do this &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much!&lt;/P&gt;</description>
      <pubDate>Mon, 16 Nov 2020 14:14:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-the-min-and-max-of-the-date-with-conditions/m-p/698769#M213728</guid>
      <dc:creator>huongc2</dc:creator>
      <dc:date>2020-11-16T14:14:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to create the min and max of the date with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-the-min-and-max-of-the-date-with-conditions/m-p/698861#M213765</link>
      <description>&lt;P&gt;You will need two steps for this, first to create the admission counts, and then to create the summary variables and merge them back to the original data:&lt;/P&gt;
&lt;P&gt;Source data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input patient $ admitted_date :mmddyy10. discharge_date :mmddyy10. disposition $50.;
format admitted_date discharge_date yymmdd10.;
datalines;
A 3/2/2020  3/15/2020 transferred to other hospital
A 3/15/2020 4/2/2020  home
B 5/3/2020  6/27/2020 transferred to other hospital
B 6/27/2020 6/29/2020 home
C 8/1/2020  8/25/2020 died
D 5/15/2020 6/1/2020  transferred to other hospital
D 6/1/2020  7/2/2020  home
A 6/2/2020  6/25/2020 died
B 8/1/2020  8/2/2020  transferred to other hospital
B 8/2/2020  8/15/2020 transferred to other hospital
B 8/15/2020 8/25/2020 died
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please post your example data in this way in the future, as it enables others to&amp;nbsp;&lt;EM&gt;exactly&lt;/EM&gt; recreate a dataset with a simple copy/paste and submit. See it not only as a basic courtesy, but also as a means to speed up getting a valid working answer.&lt;/P&gt;
&lt;P&gt;Sort and create the admission_count:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by patient admitted_date;
run;

data counts;
set have;
by patient;
l_dis = lag(discharge_date);
if first.patient
then admission_count = 1;
else if l_dis lt admitted_date then admission_count + 1;
drop l_dis;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now, in SQL, create the max and min dates, and the final disposition, and merge back to the source data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select
    patient,
    admitted_date,
    discharge_date,
    disposition,
    min(admitted_date) format yymmdd10. as min_admitted_date,
    max(discharge_date) format yymmdd10. as max_discharged_date,
    admission_count,
    (
      select disposition
      from counts t2
      where t1.patient = t2.patient and t1.admission_count = t2.admission_count
      group by t2.patient, t2.admission_count
      having t2.admitted_date = max(t2.admitted_date)
    ) as final_disposition
  from counts t1
  group by patient, admission_count
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If your dataset is large, the sub-select might become inefficient; in that case, it might be necessary to do some trickery in the data step to create final_disposition, or move everything there (code might not be as easy to read).&lt;/P&gt;</description>
      <pubDate>Sat, 14 Nov 2020 09:25:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-the-min-and-max-of-the-date-with-conditions/m-p/698861#M213765</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-14T09:25:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to create the min and max of the date with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-the-min-and-max-of-the-date-with-conditions/m-p/699183#M213873</link>
      <description>&lt;P&gt;Good morning! Thank you soooo much for helping me on this. I edited my post as suggested.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regarding the codes, the first step works so well on my data! But as you mentioned at the end, I might have to do some tricks to get the second step works since my data is large. (40,000 obs).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wonder after creating the counts data, maybe I could group by patient and admission_count, then do first.admitted_date and last.discharge_Date to capture their min and max? do you think it would work? Do you have any other suggestions in this case?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Again, thank you so much for helping on this. I just learned a new function "lag" from you. I am so happy that it works so well (and fast).&lt;/P&gt;</description>
      <pubDate>Mon, 16 Nov 2020 15:10:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-the-min-and-max-of-the-date-with-conditions/m-p/699183#M213873</guid>
      <dc:creator>huongc2</dc:creator>
      <dc:date>2020-11-16T15:10:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to create the min and max of the date with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-the-min-and-max-of-the-date-with-conditions/m-p/699195#M213876</link>
      <description>&lt;P&gt;40,000 is not large. With "large" I meant observation counts in the millions.&lt;/P&gt;
&lt;P&gt;Just run the code on the 40,000 obs and let us see the log.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Nov 2020 15:59:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-the-min-and-max-of-the-date-with-conditions/m-p/699195#M213876</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-16T15:59:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to create the min and max of the date with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-the-min-and-max-of-the-date-with-conditions/m-p/699197#M213877</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is my log. I tried with a small subset first:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NOTE: The query requires remerging summary statistics back with the original data.&lt;BR /&gt;NOTE: Table WORK.MIN_MAX created, with 3367 rows and 8 columns.&lt;/P&gt;&lt;P&gt;quit;&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 15:38.36&lt;BR /&gt;cpu time 15:43.67&lt;/P&gt;</description>
      <pubDate>Mon, 16 Nov 2020 16:02:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-the-min-and-max-of-the-date-with-conditions/m-p/699197#M213877</guid>
      <dc:creator>huongc2</dc:creator>
      <dc:date>2020-11-16T16:02:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to create the min and max of the date with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-the-min-and-max-of-the-date-with-conditions/m-p/699248#M213902</link>
      <description>&lt;P&gt;OK, so we see the notoriously bad performance of subselects in action; replace the SQL with these data steps:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sum;
set counts;
by patient admission_count;
retain min_admitted_date;
format min_admitted_date yymmdd10.;
if first.admission_count
then min_admitted_date = admitted_date;
if last.admission_count;
keep
  patient
  admission_count
  min_admitted_date
  discharge_date
  disposition
;
rename
  discharge_date=max_discharged_date
  disposition=final_disposition
;
run;

data want;
merge
  counts
  sum
;
by patient admission_count;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Nov 2020 17:40:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-the-min-and-max-of-the-date-with-conditions/m-p/699248#M213902</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-16T17:40:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to create the min and max of the date with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-the-min-and-max-of-the-date-with-conditions/m-p/699251#M213904</link>
      <description>&lt;P&gt;OMG, it works perfectly and soooo fast.&lt;/P&gt;&lt;P&gt;Thank you so much!!!!!!&lt;/P&gt;</description>
      <pubDate>Mon, 16 Nov 2020 17:55:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-the-min-and-max-of-the-date-with-conditions/m-p/699251#M213904</guid>
      <dc:creator>huongc2</dc:creator>
      <dc:date>2020-11-16T17:55:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to create the min and max of the date with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-the-min-and-max-of-the-date-with-conditions/m-p/699258#M213908</link>
      <description>&lt;P&gt;Sadly, Maxim 10 is still valid, although SQL has seen some improvements over the years.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Nov 2020 18:09:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-the-min-and-max-of-the-date-with-conditions/m-p/699258#M213908</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-16T18:09:30Z</dc:date>
    </item>
  </channel>
</rss>

