<?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: Using SAS arrays pick a value and associated date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-arrays-pick-a-value-and-associated-date/m-p/786127#M250959</link>
    <description>&lt;P&gt;Technique when using a long dataset:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data value;
input Case Type1 $ Value1 Date1 mmddyy10. Type2 $ Value2 Date2 mmddyy10. Type3 $ Value3 Date3 mmddyy10.;
cards;
1 V 7 12/14/2021 C 12 11/13/2020 V 24 06/05/2019
2 C 8 12/15/2021 B 13 11/14/2020 C 9 06/06/2019
3 V 7 12/14/2021 V 7 11/13/2020   V 7 12/16/2021
4 C 8 12/15/2021 C 8 11/14/2020  C 8 06/06/2019
5 . 6 12/15/2021  B 13 11/14/2020 B 8 06/06/2019
;

data long;
set value;
array t {*} type:;
array v {*} value:;
array d {*} date:;
do i = 1 to dim(t);
  type = t{i};
  value = v{i};
  date = d{i};
  output;
end;
format date yymmdd10.;
keep case type value date;
run;

proc sort data=long;
by case date;
run;

data want;
do until (last.case);
  set long;
  by case;
  select (type);
    when ('V') do;
      if _type ne 'V' or (_type = 'V' and _value lt value)
      then do;
        _type = 'V';
        _value = value;
        _date = date;
      end;
    end;
    when ('C') do;
      if _type in ('B','') or (_type = 'C' and (_value gt value or _value = .))
      then do;
        _type = 'C';
        _value = value;
        _date = date;
      end;
    end;
    when ('B','') do;
      if _type in ('B','') and (_value gt value or _value = .)
      then do;
        _type = type;
        _value = value;
        _date = date;
      end;
    end;
  end;
end;
format _date yymmdd10.;
drop type value date;
rename
  _type = type
  _value = value
  _date = date
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 15 Dec 2021 09:38:35 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-12-15T09:38:35Z</dc:date>
    <item>
      <title>Using SAS arrays pick a value and associated date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-arrays-pick-a-value-and-associated-date/m-p/786037#M250906</link>
      <description>&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Update to the logic&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;data value ;&lt;BR /&gt;input Case Type1 $ Value1 Date1 mmddyy10. Type2 $ Value2 Date2 mmddyy10. Type3 $ Value3 Date3 mmddyy10.;&lt;BR /&gt;cards;&lt;BR /&gt;1 V 7 12/14/2021 C 12 11/13/2020 &lt;STRONG&gt;&lt;FONT color="#FF9900"&gt;V 24 06/05/2019&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;2 &lt;STRONG&gt;&lt;FONT color="#FF9900"&gt;C 8 12/15/2021&lt;/FONT&gt;&lt;/STRONG&gt; B 13 11/14/2020 C 9 06/06/2019&lt;BR /&gt;3 V 7 12/14/2021 &lt;FONT color="#FF9900"&gt;&lt;STRONG&gt;V 7 11/13/2020&lt;/STRONG&gt;&lt;/FONT&gt;&amp;nbsp; &amp;nbsp;V 7 12/16/2021&lt;BR /&gt;4 C 8 12/15/2021 C 8 11/14/2020&amp;nbsp;&amp;nbsp;&lt;FONT color="#FF9900"&gt;&lt;STRONG&gt;C 8 06/06/2019&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;5 &lt;STRONG&gt;&lt;FONT color="#FF9900"&gt;. 6 12/15/2021&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp; B 13 11/14/2020 B 8 06/06/2019&lt;BR /&gt;;&lt;BR /&gt;/*REVISED LOGIC&lt;BR /&gt;CASE#1 Regardless of other Types, select V with highest Value and associated Date&lt;BR /&gt;CASE#2 If V type doesn't exist, then pick C type with the lowest Value and associated Date&lt;BR /&gt;CASE#3 and CASE#4 If same types exist with same values (for example only C or only V WITH VALUE OF 7), then pick the Value with oldest Date&lt;BR /&gt;CASE#5 If V or C don't exist but type is blank or B, then pick the lowest Value and associated Date*/;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;Orange colored ones need to be in Value_New and Date_New&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;_________________________________________________________________________________________________________________&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using SAS arrays and do loop, I am trying to create new two columns Value_New and Date_New. The logic :&amp;nbsp;&lt;/P&gt;&lt;P&gt;If type is V, then pick&amp;nbsp; the highest value and Date associated with that V&lt;BR /&gt;If only type C exists, than take the lowest value and Date associated with that C&lt;BR /&gt;For any type, if there is only one type (only V or only C), and if values are equal, than take the one with earliest date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Case&lt;/TD&gt;&lt;TD&gt;Type1&lt;/TD&gt;&lt;TD&gt;Value1&lt;/TD&gt;&lt;TD&gt;Date1&lt;/TD&gt;&lt;TD&gt;Type2&lt;/TD&gt;&lt;TD&gt;Value2&lt;/TD&gt;&lt;TD&gt;Date2&lt;/TD&gt;&lt;TD&gt;Type3&lt;/TD&gt;&lt;TD&gt;Value3&lt;/TD&gt;&lt;TD&gt;Date3&lt;/TD&gt;&lt;TD&gt;Value_New&lt;/TD&gt;&lt;TD&gt;Date_New&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;V&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;12/14/2021&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;TD&gt;11/13/2020&lt;/TD&gt;&lt;TD&gt;V&lt;/TD&gt;&lt;TD&gt;24&lt;/TD&gt;&lt;TD&gt;6/5/2019&lt;/TD&gt;&lt;TD&gt;24&lt;/TD&gt;&lt;TD&gt;6/5/2019&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;12/15/2021&lt;/TD&gt;&lt;TD&gt;V&lt;/TD&gt;&lt;TD&gt;13&lt;/TD&gt;&lt;TD&gt;11/14/2020&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;6/6/2019&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;6/6/2019&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Wed, 15 Dec 2021 04:01:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SAS-arrays-pick-a-value-and-associated-date/m-p/786037#M250906</guid>
      <dc:creator>sasuser123</dc:creator>
      <dc:date>2021-12-15T04:01:08Z</dc:date>
    </item>
    <item>
      <title>Re: Using SAS arrays pick a value and associated date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-arrays-pick-a-value-and-associated-date/m-p/786043#M250909</link>
      <description>&lt;P&gt;I don't think your rules are complete.&lt;/P&gt;
&lt;P&gt;What do want as the answer when there are both V and C types?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Wouldn't this whole operation be a lot easier if you had a separated observation for each TYPE/VALUE/DATE combination?&lt;/P&gt;</description>
      <pubDate>Tue, 14 Dec 2021 18:39:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SAS-arrays-pick-a-value-and-associated-date/m-p/786043#M250909</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-12-14T18:39:58Z</dc:date>
    </item>
    <item>
      <title>Re: Using SAS arrays pick a value and associated date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-arrays-pick-a-value-and-associated-date/m-p/786045#M250910</link>
      <description>&lt;P&gt;Your rules and data don't align.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/73681"&gt;@sasuser123&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Using SAS arrays and do loop, I am trying to create new two columns Value_New and Date_New. The logic :&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;If type is V, then pick&amp;nbsp; the highest value and Date associated with that V&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;If only type C exists, than take the lowest value and Date associated with that C&lt;BR /&gt;For any type, if there is only one type (only V or only C), and if values are equal, than take the one with earliest date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="48.3594px" height="30px"&gt;Case&lt;/TD&gt;
&lt;TD width="54.5938px" height="30px"&gt;&lt;FONT color="#FF9900"&gt;Type1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="59.6406px" height="30px"&gt;&lt;FONT color="#FF9900"&gt;Value1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="91.0781px" height="30px"&gt;&lt;FONT color="#FF9900"&gt;Date1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="54.5938px" height="30px"&gt;&lt;FONT color="#FF9900"&gt;Type2&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="59.6406px" height="30px"&gt;&lt;FONT color="#FF9900"&gt;Value2&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="89.8906px" height="30px"&gt;&lt;FONT color="#FF9900"&gt;Date2&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="54.5938px" height="30px"&gt;&lt;FONT color="#FF9900"&gt;Type3&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="59.6406px" height="30px"&gt;&lt;FONT color="#FF9900"&gt;Value3&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="73.2812px" height="30px"&gt;&lt;FONT color="#FF9900"&gt;Date3&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="114.594px" height="30px"&gt;&lt;STRONG&gt;&lt;FONT color="#000000"&gt;Value_New&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="87.4844px" height="30px"&gt;&lt;STRONG&gt;&lt;FONT color="#000000"&gt;Date_New&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="48.3594px" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="54.5938px" height="30px"&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;V&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="59.6406px" height="30px"&gt;&lt;FONT color="#FF9900"&gt;7&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="91.0781px" height="30px"&gt;&lt;FONT color="#FF9900"&gt;12/14/2021&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="54.5938px" height="30px"&gt;&lt;FONT color="#FF9900"&gt;C&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="59.6406px" height="30px"&gt;&lt;FONT color="#FF9900"&gt;12&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="89.8906px" height="30px"&gt;&lt;FONT color="#FF9900"&gt;11/13/2020&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="54.5938px" height="30px"&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;V&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="59.6406px" height="30px"&gt;&lt;FONT color="#FF9900"&gt;24&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="73.2812px" height="30px"&gt;&lt;FONT color="#FF9900"&gt;6/5/2019&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="114.594px" height="30px"&gt;&lt;STRONG&gt;&lt;FONT color="#000000"&gt;24&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="87.4844px" height="30px"&gt;&lt;STRONG&gt;&lt;FONT color="#000000"&gt;6/5/2019&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="48.3594px" height="30px"&gt;2&lt;/TD&gt;
&lt;TD width="54.5938px" height="30px"&gt;&lt;FONT color="#FF9900"&gt;C&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="59.6406px" height="30px"&gt;&lt;FONT color="#FF9900"&gt;8&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="91.0781px" height="30px"&gt;&lt;FONT color="#FF9900"&gt;12/15/2021&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="54.5938px" height="30px"&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;V&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="59.6406px" height="30px"&gt;&lt;FONT color="#FF9900"&gt;13&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="89.8906px" height="30px"&gt;&lt;FONT color="#FF9900"&gt;11/14/2020&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="54.5938px" height="30px"&gt;&lt;FONT color="#FF9900"&gt;C&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="59.6406px" height="30px"&gt;&lt;FONT color="#FF9900"&gt;8&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="73.2812px" height="30px"&gt;&lt;FONT color="#FF9900"&gt;6/6/2019&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="114.594px" height="30px"&gt;&lt;STRONG&gt;&lt;FONT color="#000000"&gt;&lt;FONT color="#FF0000"&gt;&lt;FONT color="#000000"&gt;8&lt;/FONT&gt; &amp;lt;- not max?&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="87.4844px" height="30px"&gt;&lt;STRONG&gt;&lt;FONT color="#000000"&gt;6/6/2019&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Both rows have a V but you take the minimum in the second case? I agree with others that a long format is more usuable here rather than a wide format but we do need clarification on the logic first.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a rough idea to get you started but I wouldn't recommend this approach.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have (drop = value_new date_new);
infile cards dlm='09'x;
informat case 8. type1 - type3 $8. Value1-Value3 Value_new 8. Date1-Date3 Date_new mmddyy10. ;
format case 8. type1 - type3 $8. Value1-Value3 Value_new 8. Date1-Date3 Date_new mmddyy10. ;
input Case	Type1	Value1	Date1	Type2	Value2	Date2	Type3	Value3	Date3	Value_New	Date_New;
cards;
1	V	7	12/14/2021	C	12	11/13/2020	V	24	6/5/2019	24	6/5/2019
2	C	8	12/15/2021	V	13	11/14/2020	C	8	6/6/2019	8	6/6/2019
3	V	7	12/14/2021	V	12	11/13/2020	V	24	6/5/2019	24	6/5/2019
4	C	8	12/15/2021	C	13	11/14/2020	C	8	6/6/2019	8	6/6/2019
;;;;
run;

proc print data=have;run;

data want;
set have;
array _val(3) value1-value3;
array _date(3) date1-date3;
array _type(3) type1-type3;

C_Found = 0; V_Found=0;
if whichc('V', of _type(*))&amp;gt;0 then V_Found = 1;
if whichc('C', of _type(*))&amp;gt;0 then C_Found = 1;


if V_FOUND then do;
value_new = max(of _val(*));
date_new = _date(whichn(value_new, of _val(*)));
end;
*have both V/C;
else do;
value_new = min(of _val(*));
date_new = _date(whichn(value_new, of _val(*)));
end;

format date_new mmddyys10.;

run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Dec 2021 18:54:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SAS-arrays-pick-a-value-and-associated-date/m-p/786045#M250910</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-12-14T18:54:06Z</dc:date>
    </item>
    <item>
      <title>Re: Using SAS arrays pick a value and associated date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-arrays-pick-a-value-and-associated-date/m-p/786090#M250938</link>
      <description>&lt;P&gt;Thanks, this code is very helpful, I run it and identified additional info. I&amp;nbsp; realized that there are blank and B types that I didn't include in the original post.&amp;nbsp; V type is priority and need to have the highest value of V type.&amp;nbsp; If V type doesn't exist, than I need C type with the lowest value of type C.&amp;nbsp; When C or V don't exist then I can take any types with lowest value.&amp;nbsp; When types are same and values are same, such as all types are C and values=8, then I need the one with the oldest date.&amp;nbsp; I hope this makes sense.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Dec 2021 04:18:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SAS-arrays-pick-a-value-and-associated-date/m-p/786090#M250938</guid>
      <dc:creator>sasuser123</dc:creator>
      <dc:date>2021-12-15T04:18:00Z</dc:date>
    </item>
    <item>
      <title>Re: Using SAS arrays pick a value and associated date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-arrays-pick-a-value-and-associated-date/m-p/786092#M250940</link>
      <description>Have you tried modifying the code to account for those?</description>
      <pubDate>Wed, 15 Dec 2021 04:25:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SAS-arrays-pick-a-value-and-associated-date/m-p/786092#M250940</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-12-15T04:25:25Z</dc:date>
    </item>
    <item>
      <title>Re: Using SAS arrays pick a value and associated date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-arrays-pick-a-value-and-associated-date/m-p/786096#M250944</link>
      <description>&lt;P&gt;Yes, I modified the code but it stopped picking the highest value for V and doesn't pick the oldest date if types and values are same.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set value;&lt;BR /&gt;array _val(3) value1-value3;&lt;BR /&gt;array _date(3) date1-date3;&lt;BR /&gt;array _type(3) type1-type3;&lt;/P&gt;&lt;P&gt;C_Found = 0; V_Found=0;b_Found = 0;&lt;BR /&gt;if whichc('V', of _type(*))&amp;gt;0 then V_Found = 1;&lt;BR /&gt;if whichc('C', of _type(*))&amp;gt;0 then C_Found = 1;&lt;BR /&gt;if whichc(' ', of _type(*))&amp;gt;0 then B_Found = 1;&lt;BR /&gt;if whichc('B', of _type(*))&amp;gt;0 then B_Found = 1;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;if V_FOUND=1 then do;&lt;BR /&gt;value_new = max(of _val(*));&lt;BR /&gt;date_new = _date(whichn(value_new, of _val(*)));&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;if C_FOUND=1 then do;&lt;BR /&gt;value_new = min(of _val(*));&lt;BR /&gt;date_new = _date(whichn(value_new, of _val(*)));&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;else do;&lt;BR /&gt;value_new = min(of _val(*));&lt;BR /&gt;date_new = _date(whichn(value_new, of _val(*)));&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;format date_new mmddyys10.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Dec 2021 04:41:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SAS-arrays-pick-a-value-and-associated-date/m-p/786096#M250944</guid>
      <dc:creator>sasuser123</dc:creator>
      <dc:date>2021-12-15T04:41:38Z</dc:date>
    </item>
    <item>
      <title>Re: Using SAS arrays pick a value and associated date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-arrays-pick-a-value-and-associated-date/m-p/786127#M250959</link>
      <description>&lt;P&gt;Technique when using a long dataset:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data value;
input Case Type1 $ Value1 Date1 mmddyy10. Type2 $ Value2 Date2 mmddyy10. Type3 $ Value3 Date3 mmddyy10.;
cards;
1 V 7 12/14/2021 C 12 11/13/2020 V 24 06/05/2019
2 C 8 12/15/2021 B 13 11/14/2020 C 9 06/06/2019
3 V 7 12/14/2021 V 7 11/13/2020   V 7 12/16/2021
4 C 8 12/15/2021 C 8 11/14/2020  C 8 06/06/2019
5 . 6 12/15/2021  B 13 11/14/2020 B 8 06/06/2019
;

data long;
set value;
array t {*} type:;
array v {*} value:;
array d {*} date:;
do i = 1 to dim(t);
  type = t{i};
  value = v{i};
  date = d{i};
  output;
end;
format date yymmdd10.;
keep case type value date;
run;

proc sort data=long;
by case date;
run;

data want;
do until (last.case);
  set long;
  by case;
  select (type);
    when ('V') do;
      if _type ne 'V' or (_type = 'V' and _value lt value)
      then do;
        _type = 'V';
        _value = value;
        _date = date;
      end;
    end;
    when ('C') do;
      if _type in ('B','') or (_type = 'C' and (_value gt value or _value = .))
      then do;
        _type = 'C';
        _value = value;
        _date = date;
      end;
    end;
    when ('B','') do;
      if _type in ('B','') and (_value gt value or _value = .)
      then do;
        _type = type;
        _value = value;
        _date = date;
      end;
    end;
  end;
end;
format _date yymmdd10.;
drop type value date;
rename
  _type = type
  _value = value
  _date = date
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Dec 2021 09:38:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SAS-arrays-pick-a-value-and-associated-date/m-p/786127#M250959</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-12-15T09:38:35Z</dc:date>
    </item>
  </channel>
</rss>

