<?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: Finding Totals of Array Subset in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Finding-Totals-of-Array-Subset/m-p/618817#M19280</link>
    <description>&lt;P&gt;So Jun09 represents 01Jun2009, correct?&lt;/P&gt;</description>
    <pubDate>Tue, 21 Jan 2020 10:34:48 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2020-01-21T10:34:48Z</dc:date>
    <item>
      <title>Finding Totals of Array Subset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Finding-Totals-of-Array-Subset/m-p/618813#M19277</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a data set as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; Date1 Dose1&amp;nbsp; Date2 Dose2&amp;nbsp; Date3 Dose3&amp;nbsp; Date4 Dose4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;01&amp;nbsp; Jun09&amp;nbsp; &amp;nbsp;15&amp;nbsp; &amp;nbsp; &amp;nbsp;Jun09&amp;nbsp; &amp;nbsp; 12&amp;nbsp; &amp;nbsp; &amp;nbsp; Sep09&amp;nbsp; &amp;nbsp; 17&amp;nbsp; &amp;nbsp; &amp;nbsp; Jan10&amp;nbsp; &amp;nbsp;20&lt;/P&gt;&lt;P&gt;02&amp;nbsp; Mar05&amp;nbsp; &amp;nbsp;11&amp;nbsp; &amp;nbsp; &amp;nbsp;Nov05&amp;nbsp; &amp;nbsp;18&amp;nbsp; &amp;nbsp; &amp;nbsp; Nov05&amp;nbsp; &amp;nbsp; 15&lt;/P&gt;&lt;P&gt;03&amp;nbsp; Jan10&amp;nbsp; &amp;nbsp;13&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;04&amp;nbsp; Apr11&amp;nbsp; &amp;nbsp; 16&amp;nbsp; &amp;nbsp; &amp;nbsp;Aug12&amp;nbsp; &amp;nbsp; 17&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;I need to find a total dose for each ID, but if the date is the same then only the highest dose should be counted, i.e.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; Date1 Dose1&amp;nbsp; Date2 Dose2&amp;nbsp; Date3 Dose3&amp;nbsp; Date4 Dose4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Total Dose&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;01&amp;nbsp; Jun09&amp;nbsp; &amp;nbsp;15&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;FONT color="#FF0000"&gt;Jun09&amp;nbsp; &amp;nbsp; 12&lt;/FONT&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Sep09&amp;nbsp; &amp;nbsp; 17&amp;nbsp; &amp;nbsp; &amp;nbsp; Jan10&amp;nbsp; &amp;nbsp;20&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;52&lt;/P&gt;&lt;P&gt;02&amp;nbsp; Mar05&amp;nbsp; &amp;nbsp;11&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;FONT color="#FF0000"&gt;Nov05&amp;nbsp; &amp;nbsp;15&lt;/FONT&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Nov05&amp;nbsp; &amp;nbsp; 18&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 29&lt;/P&gt;&lt;P&gt;03&amp;nbsp; Jan10&amp;nbsp; &amp;nbsp;13&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; &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; &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;13&lt;/P&gt;&lt;P&gt;04&amp;nbsp; Apr11&amp;nbsp; &amp;nbsp; 16&amp;nbsp; &amp;nbsp; &amp;nbsp;Aug12&amp;nbsp; &amp;nbsp; 17&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; &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; &amp;nbsp; &amp;nbsp; &amp;nbsp;33&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So far I have tried using arrays to create an indicator for whether the dates are the same, and then wanted to use this to find the maximum value but i haven't been table to figure out how to find a maximum of a subset of the data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be appreciate!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Cydney&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jan 2020 10:22:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Finding-Totals-of-Array-Subset/m-p/618813#M19277</guid>
      <dc:creator>CydneyLB</dc:creator>
      <dc:date>2020-01-21T10:22:58Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Totals of Array Subset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Finding-Totals-of-Array-Subset/m-p/618814#M19278</link>
      <description>&lt;P&gt;Are the date variables numeric or character?&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jan 2020 10:29:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Finding-Totals-of-Array-Subset/m-p/618814#M19278</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-01-21T10:29:36Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Totals of Array Subset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Finding-Totals-of-Array-Subset/m-p/618815#M19279</link>
      <description>&lt;P&gt;They are numeric&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jan 2020 10:30:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Finding-Totals-of-Array-Subset/m-p/618815#M19279</guid>
      <dc:creator>CydneyLB</dc:creator>
      <dc:date>2020-01-21T10:30:28Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Totals of Array Subset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Finding-Totals-of-Array-Subset/m-p/618817#M19280</link>
      <description>&lt;P&gt;So Jun09 represents 01Jun2009, correct?&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jan 2020 10:34:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Finding-Totals-of-Array-Subset/m-p/618817#M19280</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-01-21T10:34:48Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Totals of Array Subset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Finding-Totals-of-Array-Subset/m-p/618819#M19281</link>
      <description>&lt;P&gt;Yes it does sorry i didn't include the days because they only need to be the same month not the same day, but yes you could say they are all on the 1st&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jan 2020 10:36:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Finding-Totals-of-Array-Subset/m-p/618819#M19281</guid>
      <dc:creator>CydneyLB</dc:creator>
      <dc:date>2020-01-21T10:36:37Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Totals of Array Subset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Finding-Totals-of-Array-Subset/m-p/618834#M19284</link>
      <description>&lt;P&gt;Transpose to long, as it is much easier to find maximum/minimum/sum etc:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines truncover;
input ID Date1 :monyy5. Dose1 Date2 :monyy5. Dose2 Date3 :monyy5. Dose3 Date4 :monyy5. Dose4;
format date: yymmn6.;
datalines;
01  Jun09   15     Jun09    12      Sep09    17      Jan10   20
02  Mar05   11     Nov05   18      Nov05    15
03  Jan10   13     
04  Apr11    16     Aug12    17
;

proc transpose data=have out=trans1;
by id;
var date: dose:;
run;

data trans2;
set trans1;
where col1 ne .;
if substr(_name_,1,4) = "Date"
then date = col1;
else dose = col1;
event = input(compress(_name_,'','kd'),best.);
format date yymmn6.;
run;

data trans;
merge
  trans2 (keep=id event date where=(date ne .))
  trans2 (keep=id event dose where=(dose ne .))
;
by id event;
drop event;
run;

proc sort data=trans;
by id date dose;
run;

data want;
set trans;
by id date;
if last.date;
run;

proc report data=want;
column id date dose;
define id /group;
define date /display;
define dose /analysis sum;
break after id/ summarize;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt; ID    date       dose
  1  200906         15
     200909         17
     201001         20
  1                 52
  2  200503         11
     200511         18
  2                 29
  3  201001         13
  3                 13
  4  201104         16
     201208         17
  4                 33
&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Jan 2020 11:54:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Finding-Totals-of-Array-Subset/m-p/618834#M19284</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-01-21T11:54:06Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Totals of Array Subset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Finding-Totals-of-Array-Subset/m-p/618879#M19290</link>
      <description>&lt;P&gt;Thank you very much Kurt, with a bit of moving around this worked perfectly!&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jan 2020 15:29:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Finding-Totals-of-Array-Subset/m-p/618879#M19290</guid>
      <dc:creator>CydneyLB</dc:creator>
      <dc:date>2020-01-21T15:29:51Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Totals of Array Subset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Finding-Totals-of-Array-Subset/m-p/618881#M19291</link>
      <description>&lt;P&gt;It should be easy enough to walk through a set of two arrays:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   array date {4};
   array dose {4};
   total_dose = dose1;
   do k=2 to 4;
      if date{k} ne date{k-1} then total_dose + dose{k};
      else do;
         if dose{k} &amp;gt; dose{k-1} then total_dose + (dose{k} - dose{k-1});
      end;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that this does not necessarily address what happens when there are three doses on the same date.&amp;nbsp; That can be done, but requires a little more work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also note, this is untested code.&amp;nbsp; So you need to test it out and report back whether it is successful.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jan 2020 15:42:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Finding-Totals-of-Array-Subset/m-p/618881#M19291</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-01-21T15:42:15Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Totals of Array Subset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Finding-Totals-of-Array-Subset/m-p/619010#M19314</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/270429"&gt;@CydneyLB&lt;/a&gt;: You already have a proc report solution that apparently meets your need, but here is a single datastep solution that I think is easier to modify and creates the Total_Dose variable in the dataset. It uses the qsort macro that Paul Dorfman proposed some years ago:&lt;/P&gt;
&lt;PRE&gt;data have;
  infile datalines truncover;
  input ID Date1 :monyy5. Dose1 Date2 :monyy5. Dose2 Date3 :monyy5. Dose3 Date4 :monyy5. Dose4;
  format date: yymmn6.;
  datalines;
01  Jun09   12     Jun09    15      Sep09    17      Jan10   20
02  Mar05   11     Nov05   15       Nov05    18
03  Jan10   13     Jan10   10       Jan10    12
04  Apr11    16     Aug12    17
;
run;

filename qs url 'https://raw.githubusercontent.com/art297/qsort/master/qsort.sas';
%include qs ;


data want (drop=t_:);
  set have;
  array t_dates(4);
  array t_doses(4);
  array dates(4) date:;
  array doses(4) dose:;
  do t_i=1 to 4;
    t_dates(t_i)=dates(t_i);
    t_doses(t_i)=doses(t_i);
  end;
  %Qsort (Arr=t_dates t_doses, By=t_doses,seq=d);
  %Qsort (Arr=t_dates t_doses, By=t_dates);
  
  do t_i=2 to 4;
    if t_dates(t_i) eq t_dates(t_i-1) then call missing(t_doses(t_i));
  end;
  Total_Dose=sum(of t_doses(*));
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jan 2020 00:54:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Finding-Totals-of-Array-Subset/m-p/619010#M19314</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2020-01-22T00:54:29Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Totals of Array Subset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Finding-Totals-of-Array-Subset/m-p/619780#M19446</link>
      <description>&lt;P&gt;Hi Astounding, thank you for the solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is super easy and works really well for most of the observations! However there are a few people who have more than two doses on the same day (the maximum is 4). How would you go about extending this for multiple doses on the same day?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Cydney&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jan 2020 09:26:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Finding-Totals-of-Array-Subset/m-p/619780#M19446</guid>
      <dc:creator>CydneyLB</dc:creator>
      <dc:date>2020-01-24T09:26:09Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Totals of Array Subset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Finding-Totals-of-Array-Subset/m-p/619786#M19447</link>
      <description>&lt;P&gt;Hi Art,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for responding another good solution. This works great for looking if the doses were on the same day, however if i edit it to look at doses within 60 days of&amp;nbsp; each other I cant seem to get the code to work?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Cydney&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jan 2020 10:00:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Finding-Totals-of-Array-Subset/m-p/619786#M19447</guid>
      <dc:creator>CydneyLB</dc:creator>
      <dc:date>2020-01-24T10:00:23Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Totals of Array Subset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Finding-Totals-of-Array-Subset/m-p/619819#M19452</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/270429"&gt;@CydneyLB&lt;/a&gt;&amp;nbsp;: Please provide an example dataset that shows a case where the code doesn't work and the result you expect from that data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jan 2020 14:01:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Finding-Totals-of-Array-Subset/m-p/619819#M19452</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2020-01-24T14:01:43Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Totals of Array Subset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Finding-Totals-of-Array-Subset/m-p/619828#M19456</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13711"&gt;@art297&lt;/a&gt;&amp;nbsp;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using an example very similar to the one above:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; Date1 Dose1&amp;nbsp; Date2 Dose2&amp;nbsp; Date3 Dose3&amp;nbsp; Date4 Dose4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;01&amp;nbsp; Jun09&amp;nbsp; &amp;nbsp;15&amp;nbsp; &amp;nbsp; &amp;nbsp;Jun09&amp;nbsp; &amp;nbsp; 12&amp;nbsp; &amp;nbsp; &amp;nbsp; Sep09&amp;nbsp; &amp;nbsp; 17&amp;nbsp; &amp;nbsp; &amp;nbsp; Jan10&amp;nbsp; &amp;nbsp;20&lt;/P&gt;&lt;P&gt;02&amp;nbsp; Mar05&amp;nbsp; &amp;nbsp;11&amp;nbsp; &amp;nbsp; &amp;nbsp;Nov05&amp;nbsp; &amp;nbsp;15&amp;nbsp; &amp;nbsp; &amp;nbsp;Dec05&amp;nbsp; &amp;nbsp; 18&lt;/P&gt;&lt;P&gt;03&amp;nbsp; Jan10&amp;nbsp; &amp;nbsp;13&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;04&amp;nbsp; Apr11&amp;nbsp; &amp;nbsp; 16&amp;nbsp; &amp;nbsp; &amp;nbsp;Aug12&amp;nbsp; &amp;nbsp; 17&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to find a total dose for each ID, but if the date is within 60 days of another dose then only the highest dose should be counted, i.e.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; Date1 Dose1&amp;nbsp; Date2 Dose2&amp;nbsp; Date3 Dose3&amp;nbsp; Date4 Dose4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Total Dose&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;01&amp;nbsp; Jun09&amp;nbsp; &amp;nbsp;15&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;FONT color="#FF0000"&gt;Jun09&amp;nbsp; &amp;nbsp; 12&lt;/FONT&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Sep09&amp;nbsp; &amp;nbsp; 17&amp;nbsp; &amp;nbsp; &amp;nbsp; Jan10&amp;nbsp; &amp;nbsp;20&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;52&lt;/P&gt;&lt;P&gt;02&amp;nbsp; Mar05&amp;nbsp; &amp;nbsp;11&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;FONT color="#FF0000"&gt;Nov05&amp;nbsp; &amp;nbsp;15&lt;/FONT&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Dec05&amp;nbsp; &amp;nbsp; 18&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 29&lt;/P&gt;&lt;P&gt;03&amp;nbsp; Jan10&amp;nbsp; &amp;nbsp;13&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; &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; &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;13&lt;/P&gt;&lt;P&gt;04&amp;nbsp; Apr11&amp;nbsp; &amp;nbsp; 16&amp;nbsp; &amp;nbsp; &amp;nbsp;Aug12&amp;nbsp; &amp;nbsp; 17&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; &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; &amp;nbsp; &amp;nbsp; &amp;nbsp;33&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;Using your code I tried to adjust the condition as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover;
  input ID Date1 :monyy5. Dose1 Date2 :monyy5. Dose2 Date3 :monyy5. Dose3 Date4 :monyy5. Dose4;
  format date: yymmn6.;
  datalines;
01  Jun09   12     Jun09    15      Sep09    17      Jan10   20
02  Mar05   11     Nov05   15       Nov05    18
03  Jan10   13     Jan10   10       Jan10    12
04  Apr11    16     Aug12    17
;
run;

filename qs url 'https://raw.githubusercontent.com/art297/qsort/master/qsort.sas';
%include qs ;


data want (drop=t_:);
  set have;
  array t_dates(4);
  array t_doses(4);
  array dates(4) date:;
  array doses(4) dose:;
  do t_i=1 to 4;
    t_dates(t_i)=dates(t_i);
    t_doses(t_i)=doses(t_i);
  end;
  %Qsort (Arr=t_dates t_doses, By=t_doses,seq=d);
  %Qsort (Arr=t_dates t_doses, By=t_dates);
  
  do t_i=2 to 4;
    if &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;t_dates(t_i) - t_dates(t_i-1) &amp;lt; 60&lt;/STRONG&gt;&lt;/FONT&gt; then call missing(t_doses(t_i));
  end;
  Total_Dose=sum(of t_doses(*));
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However it gave the results:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; Date1 Dose1&amp;nbsp; Date2 Dose2&amp;nbsp; Date3 Dose3&amp;nbsp; Date4 Dose4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Total Dose&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;01&amp;nbsp; Jun09&amp;nbsp; &amp;nbsp;15&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;FONT color="#000000"&gt;Jun09&amp;nbsp; &amp;nbsp; 12&lt;/FONT&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Sep09&amp;nbsp; &amp;nbsp; 17&amp;nbsp; &amp;nbsp; &amp;nbsp; Jan10&amp;nbsp; &amp;nbsp;20&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;52&lt;/P&gt;&lt;P&gt;02&amp;nbsp; Mar05&amp;nbsp; &amp;nbsp;11&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;FONT color="#000000"&gt;Nov05&amp;nbsp; &amp;nbsp;15&amp;nbsp;&lt;/FONT&gt; &amp;nbsp; &amp;nbsp; Dec05&amp;nbsp; &amp;nbsp; 18&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 18&lt;/P&gt;&lt;P&gt;03&amp;nbsp; Jan10&amp;nbsp; &amp;nbsp;13&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; &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; &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; .&lt;/P&gt;&lt;P&gt;04&amp;nbsp; Apr11&amp;nbsp; &amp;nbsp; 16&amp;nbsp; &amp;nbsp; &amp;nbsp;Aug12&amp;nbsp; &amp;nbsp; 17&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; &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; &amp;nbsp; &amp;nbsp; &amp;nbsp;17&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Cydney&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jan 2020 14:46:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Finding-Totals-of-Array-Subset/m-p/619828#M19456</guid>
      <dc:creator>CydneyLB</dc:creator>
      <dc:date>2020-01-24T14:46:39Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Totals of Array Subset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Finding-Totals-of-Array-Subset/m-p/619869#M19459</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/270429"&gt;@CydneyLB&lt;/a&gt;&amp;nbsp;: What totals would you want given the following two records:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;01  Jun09   15     Jul09    12    Aug09    17      Sep09    20                       ?
01  Dec18   15     Feb19    12    Apr19    17      Jun19    20                       ?
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jan 2020 17:24:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Finding-Totals-of-Array-Subset/m-p/619869#M19459</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2020-01-24T17:24:25Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Totals of Array Subset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Finding-Totals-of-Array-Subset/m-p/620002#M19480</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/270429"&gt;@CydneyLB&lt;/a&gt;: You didn't answer my question but (I think), regardless of your answer, here is code that I think accomplishes your latest modification of the criteria. It incorporates both one %qsort as well as traversing the arrays with two do loops:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover;
  input ID Date1 :date9. Dose1 Date2 :date9. Dose2 Date3 :date9. Dose3 Date4 :date9. Dose4;
  format date: date9.;
  datalines;
01  1Jun2009   15     1Jun2009    12      1Sep2009    17    1Jan2010    20
02  5Mar2005   11     4Nov2005    15      20Dec2005   18
03  16Jan2010  13
04  14Apr2011  16     12Aug2012   17
05  1Jun2009   15     1Jul2009    12    1Aug2009    17      1Sep2009    20
06  1Dec2018   15     1Feb2019    17    1Apr2019    16      1Jun2019    20
;
run;

filename qs url 'https://raw.githubusercontent.com/art297/qsort/master/qsort.sas';
%include qs ;


data want (drop=t_:);
  set have;
  array t_dates(4);
  array t_doses(4);
  array dates(4) date:;
  array doses(4) dose:;
  do t_i=1 to 4;
    t_dates(t_i)=dates(t_i);
    t_doses(t_i)=doses(t_i);
  end;
  %Qsort (Arr=t_dates t_doses, By=t_doses,seq=d);
  
  do t_i=1 to 3;
    do t_j=t_i+1 to 4;
      if abs(intck('days', t_dates(t_i), t_dates(t_j), 'continuous')) le 60 then call missing(t_doses(t_j));
   end;
  end;
  Total_Dose=sum(of t_doses(*));
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Jan 2020 15:58:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Finding-Totals-of-Array-Subset/m-p/620002#M19480</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2020-01-25T15:58:26Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Totals of Array Subset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Finding-Totals-of-Array-Subset/m-p/620125#M19494</link>
      <description>&lt;P&gt;Hi Art,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry I didn't get a chance to answer your question [I am only at work Monday to Friday]. In the first case the total should be 35 and in the second case 52 (since as your code picked up there is more than 60 days between 1st April and 1st June)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your help!&lt;/P&gt;&lt;P&gt;Cydney&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jan 2020 09:31:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Finding-Totals-of-Array-Subset/m-p/620125#M19494</guid>
      <dc:creator>CydneyLB</dc:creator>
      <dc:date>2020-01-27T09:31:06Z</dc:date>
    </item>
  </channel>
</rss>

