<?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 select value by date? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-value-by-date/m-p/920175#M362412</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am relatively new to SAS and I am having trouble with a step.&amp;nbsp; I have a dataset that contains a patient identifier, an admission identifier (e.g. 1st, 2nd, 3rd), the admission date and and indicator for whether this was an "index" admission.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data have;                    
	format adm_date e8601da.;
	input patient admission adm_date mmddyy10. index;
	datalines;
1 1 01/12/2013 1
1 2 06/24/2013 1
1 3 08/12/2013 0
2 1 02/10/2013 0
2 2 01/05/2014 1
2 3 03/06/2014 1
3 1 02/11/2011 1
3 2 01/12/2012 0
4 1 03/21/2010 0
4 2 04/06/2010 0
4 3 09/05/2015 1
4 4 09/11/2016 0
;
run;


&lt;/PRE&gt;&lt;P&gt;Some patients have two index admissions (see patient 1 and 2 ) but I want each patient to have only one index admission, which would be the 1st of the two admissions (based on date).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
    <pubDate>Wed, 13 Mar 2024 18:58:33 GMT</pubDate>
    <dc:creator>Bumble_15</dc:creator>
    <dc:date>2024-03-13T18:58:33Z</dc:date>
    <item>
      <title>How to select value by date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-value-by-date/m-p/920175#M362412</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am relatively new to SAS and I am having trouble with a step.&amp;nbsp; I have a dataset that contains a patient identifier, an admission identifier (e.g. 1st, 2nd, 3rd), the admission date and and indicator for whether this was an "index" admission.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data have;                    
	format adm_date e8601da.;
	input patient admission adm_date mmddyy10. index;
	datalines;
1 1 01/12/2013 1
1 2 06/24/2013 1
1 3 08/12/2013 0
2 1 02/10/2013 0
2 2 01/05/2014 1
2 3 03/06/2014 1
3 1 02/11/2011 1
3 2 01/12/2012 0
4 1 03/21/2010 0
4 2 04/06/2010 0
4 3 09/05/2015 1
4 4 09/11/2016 0
;
run;


&lt;/PRE&gt;&lt;P&gt;Some patients have two index admissions (see patient 1 and 2 ) but I want each patient to have only one index admission, which would be the 1st of the two admissions (based on date).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2024 18:58:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-value-by-date/m-p/920175#M362412</guid>
      <dc:creator>Bumble_15</dc:creator>
      <dc:date>2024-03-13T18:58:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to select value by date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-value-by-date/m-p/920178#M362413</link>
      <description>&lt;PRE&gt;&lt;CODE class=""&gt;data have;                    
	format adm_date e8601da.;
	input patient admission adm_date mmddyy10. index;
	datalines;
1 1 01/12/2013 1
1 2 06/24/2013 1
1 3 08/12/2013 0
2 1 02/10/2013 0
2 2 01/05/2014 1
2 3 03/06/2014 1
3 1 02/11/2011 1
3 2 01/12/2012 0
4 1 03/21/2010 0
4 2 04/06/2010 0
4 3 09/05/2015 1
4 4 09/11/2016 0
;
run;

data want;
	set have;
	by patient index notsorted;
	if ~first.index and index=1 then index=0;
run;

proc compare b=want c=have listall;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Can you try this?&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2024 19:15:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-value-by-date/m-p/920178#M362413</guid>
      <dc:creator>Mazi</dc:creator>
      <dc:date>2024-03-13T19:15:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to select value by date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-value-by-date/m-p/920180#M362414</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by patient adm_date;
retain found;
if first.patient then found = 0;
if found and index then delete;
if index then found = 1;
drop found;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Mar 2024 19:17:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-value-by-date/m-p/920180#M362414</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-03-13T19:17:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to select value by date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-value-by-date/m-p/920190#M362419</link>
      <description>&lt;P&gt;Thank you for getting back to me!&amp;nbsp;&lt;/P&gt;&lt;P&gt;That code mostly worked but I actually have two patients where the data looks like patient 1 below, where the second index admission does not correspond to the 2nd admission. Sorry I didn't add that in before.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;ata have;                    
	format adm_date e8601da.;
	input patient admission adm_date mmddyy10. index;
	datalines;
1 1 01/12/2013 1
1 2 06/24/2013 0
1 3 08/12/2013 1
2 1 02/10/2013 0
2 2 01/05/2014 1
2 3 03/06/2014 1
3 1 02/11/2011 1
3 2 01/12/2012 0
4 1 03/21/2010 0
4 2 04/06/2010 0
4 3 09/05/2015 1
4 4 09/11/2016 0
;
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2024 19:58:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-value-by-date/m-p/920190#M362419</guid>
      <dc:creator>Bumble_15</dc:creator>
      <dc:date>2024-03-13T19:58:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to select value by date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-value-by-date/m-p/920192#M362421</link>
      <description>In this case, what should happen?</description>
      <pubDate>Wed, 13 Mar 2024 20:08:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-value-by-date/m-p/920192#M362421</guid>
      <dc:creator>Mazi</dc:creator>
      <dc:date>2024-03-13T20:08:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to select value by date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-value-by-date/m-p/920200#M362424</link>
      <description>&lt;P&gt;I am still hoping to retain the first visit marked index as the only index value.&lt;/P&gt;&lt;P&gt;So what I have is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data have;                    
	format adm_date e8601da.;
	input patient admission adm_date mmddyy10. index;
	datalines;
1 1 01/12/2013 1
1 2 06/24/2013 0
1 3 08/12/2013 1
2 1 02/10/2013 0
2 2 01/05/2014 1
2 3 03/06/2014 1
3 1 02/11/2011 1
3 2 01/12/2012 0
4 1 03/21/2010 0
4 2 04/06/2010 0
4 3 09/05/2015 1
4 4 09/11/2016 0
;
run;&lt;/PRE&gt;&lt;P&gt;and what I want is:&lt;/P&gt;&lt;PRE&gt;data have;                    
	format adm_date e8601da.;
	input patient admission adm_date mmddyy10. index;
	datalines;
1 1 01/12/2013 1
1 2 06/24/2013 0
1 3 08/12/2013 0
2 1 02/10/2013 0
2 2 01/05/2014 1
2 3 03/06/2014 0
3 1 02/11/2011 1
3 2 01/12/2012 0
4 1 03/21/2010 0
4 2 04/06/2010 0
4 3 09/05/2015 1
4 4 09/11/2016 0
;
run;&lt;/PRE&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2024 21:03:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-value-by-date/m-p/920200#M362424</guid>
      <dc:creator>Bumble_15</dc:creator>
      <dc:date>2024-03-13T21:03:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to select value by date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-value-by-date/m-p/920201#M362425</link>
      <description>&lt;P&gt;So you do not want to remove the additional index 9bservation, you want to make it "non-index".&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by patient adm_date;
retain found;
if first.patient then found = 0;
if found then index = 0;
if index then found = 1;
drop found;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Mar 2024 21:17:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-value-by-date/m-p/920201#M362425</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-03-13T21:17:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to select value by date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-value-by-date/m-p/920204#M362426</link>
      <description>&lt;PRE&gt;&lt;CODE class=""&gt;data have;                    
	format adm_date e8601da.;
	input patient admission adm_date mmddyy10. index;
	datalines;
1 1 01/12/2013 1
1 2 06/24/2013 0
1 3 08/12/2013 1
2 1 02/10/2013 0
2 2 01/05/2014 1
2 3 03/06/2014 1
3 1 02/11/2011 1
3 2 01/12/2012 0
4 1 03/21/2010 0
4 2 04/06/2010 0
4 3 09/05/2015 1
4 4 09/11/2016 0
;
run;

data want;
	set have;
	by patient;
	if first.patient then x=0;
	if index then x+1;
	if x&amp;gt;1 then index=0;
	drop x;
run;

data want2;                    
	format adm_date e8601da.;
	input patient admission adm_date mmddyy10. index;
	datalines;
1 1 01/12/2013 1
1 2 06/24/2013 0
1 3 08/12/2013 0
2 1 02/10/2013 0
2 2 01/05/2014 1
2 3 03/06/2014 0
3 1 02/11/2011 1
3 2 01/12/2012 0
4 1 03/21/2010 0
4 2 04/06/2010 0
4 3 09/05/2015 1
4 4 09/11/2016 0
;
run;


proc compare b=want c=want2 listall;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This should do it&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2024 21:40:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-value-by-date/m-p/920204#M362426</guid>
      <dc:creator>Mazi</dc:creator>
      <dc:date>2024-03-13T21:40:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to select value by date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-value-by-date/m-p/920227#M362432</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;                    
	input patient admission adm_date mmddyy10. index;
    format adm_date e8601da.;
	datalines;
1 1 01/12/2013 1
1 2 06/24/2013 0
1 3 08/12/2013 1
2 1 02/10/2013 0
2 2 01/05/2014 1
2 3 03/06/2014 1
3 1 02/11/2011 1
3 2 01/12/2012 0
4 1 03/21/2010 0
4 2 04/06/2010 0
4 3 09/05/2015 1
4 4 09/11/2016 0
;
run;

data want;
   set have;
   by patient;
   retain found 0;
   if first.patient then found=0;
   if index=1 and found then index=0;
   if index=1 and not found then found=1;
drop found;
 run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Mar 2024 05:10:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-value-by-date/m-p/920227#M362432</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-03-14T05:10:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to select value by date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-value-by-date/m-p/920231#M362434</link>
      <description>&lt;P&gt;Make a NEW dataset with a NEW variable that has ONE observation per patient.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data index_date;
  set have;
  where index=1;
  by patient;
  if first.patient;
  keep patient adm_date;
  rename adm_date=index_date;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That way if you need to combine with the original dataset you will not have any name conflicts.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  merge index_date have;
  by patient;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Mar 2024 03:06:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-value-by-date/m-p/920231#M362434</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-03-14T03:06:48Z</dc:date>
    </item>
  </channel>
</rss>

