<?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: Counting across multiple Rows in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Counting-across-multiple-Rows/m-p/235667#M14701</link>
    <description>&lt;P&gt;Ok, given the additional complexity, I tend to agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674"&gt;@LinusH﻿&lt;/a&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, having followed the DOW loop approach so far, it is fun to adapt it to the new specifications!&amp;nbsp;&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, let's first create new test data&amp;amp;colon;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
length person 8
       drug $1;
array ondrug[365] $1;
do person=1 to 10;
  nd=int(25*ranuni(2718))+1;
  do i=1 to nd;
    drug=byte(65+int(3*ranuni(2718)));
    do _n_=1 to 365;
      ondrug[_n_]=put(int(1.05*ranuni(2718)), 1.);
    end;
    output;
  end;
end;
drop i nd;
run;

proc print data=have;
var person drug ondrug1-ondrug8;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Does this look more familiar?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so, the following, not too difficult modifications to the earlier program should do the trick:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
do until(last.person);
  set have;
  by person;
  array ondrug[365] $1;
  array ndrugs[365] $3;
  do d=1 to 365;
         if drug='A' &amp;amp; ondrug[d]='1' then substr(ndrugs[d],1,1)='1';
    else if drug='B' &amp;amp; ondrug[d]='1' then substr(ndrugs[d],2,1)='1';
    else if drug='C' &amp;amp; ondrug[d]='1' then substr(ndrugs[d],3,1)='1';
  end;
end;
do d=1 to 365;
  overlap_count=sum(overlap_count, ndrugs[d]='111');
end;
do until(last.person);
  set have;
  by person;
  output;
end;
drop d ndrugs:;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 20 Nov 2015 14:26:48 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2015-11-20T14:26:48Z</dc:date>
    <item>
      <title>Counting across multiple Rows</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Counting-across-multiple-Rows/m-p/235532#M14693</link>
      <description>&lt;P&gt;My data currently has multiple rows per person, and each of these rows contain an array that looks at whether or not the person was on a drug from 1-365. There are three different array's per person(A,B,C) since there are three classes of drugs that I am looking at.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to be able to see when one person is taking all three of them at the same time, and get a count of how many times it happends for the entire year.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;example:&amp;nbsp;&amp;nbsp; &amp;nbsp;IF &amp;nbsp;A[112]='1'&amp;nbsp;&amp;nbsp;and &amp;nbsp;B[112]= '1'&amp;nbsp;&amp;nbsp;&amp;nbsp;and C[112]='1'&amp;nbsp; then overlap_count=(1)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;since these are all on seperate rows I would need the count to work on a key level and have the overlap_count displayed on each of the rows.&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;</description>
      <pubDate>Thu, 19 Nov 2015 20:00:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Counting-across-multiple-Rows/m-p/235532#M14693</guid>
      <dc:creator>cmahrb2</dc:creator>
      <dc:date>2015-11-19T20:00:31Z</dc:date>
    </item>
    <item>
      <title>Re: Counting across multiple Rows</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Counting-across-multiple-Rows/m-p/235536#M14694</link>
      <description>Look at the RETAIN function.  Beyond that I think you'll need to post sample data and output that you want for more help.</description>
      <pubDate>Thu, 19 Nov 2015 20:07:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Counting-across-multiple-Rows/m-p/235536#M14694</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-11-19T20:07:50Z</dc:date>
    </item>
    <item>
      <title>Re: Counting across multiple Rows</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Counting-across-multiple-Rows/m-p/235547#M14696</link>
      <description>&lt;P&gt;Here's a form you can use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;do until (last.person);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; by person;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; *** calculate whatever it is you would like to calculate, making sure that the final values are the ones to be appended to each record;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;do until (last.person);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; by person;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you're looking for more examples in the literature of published papers, it's commonly called a DOW loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Nov 2015 20:44:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Counting-across-multiple-Rows/m-p/235547#M14696</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-11-19T20:44:33Z</dc:date>
    </item>
    <item>
      <title>Re: Counting across multiple Rows</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Counting-across-multiple-Rows/m-p/235576#M14697</link>
      <description>&lt;P&gt;I assume that your dataset has only one array containing 365 0-1-indicators (length $1) and that different rows of one person correspond to different classes of drugs. Hence, there should be three rows per person.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dummy data for 10 persons and drug classes 'A', 'B', 'C' could be created as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
length person 8
       drug $1;
array ondrug[365] $1;
do person=1 to 10;
  do drug='A', 'B', 'C';
    do _n_=1 to 365;
      ondrug[_n_]=put(int(1.25*ranuni(2718)), 1.);
    end;
    output;
  end;
end;
run;

proc print data=have;
var person drug ondrug1-ondrug8;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Does this look familiar?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so, you could build upon&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding﻿&lt;/a&gt;'s code template like this:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
do until(last.person);
  set have;
  by person;
  array ondrug[365] $1;
  array ndrugs[365] 3;
  do d=1 to 365;
    ndrugs[d]=sum(ndrugs[d], input(ondrug[d], 1.));
  end;
end;
do d=1 to 365;
  overlap_count=sum(overlap_count, ndrugs[d]=3);
end;
do until(last.person);
  set have;
  by person;
  output;
end;
drop d ndrugs:;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;There are indeed many interesting papers on the DOW loop:&lt;/P&gt;
&lt;P&gt;"&lt;A href="http://www2.sas.com/proceedings/sugi28/099-28.pdf" target="_blank"&gt;The DOW (not that DOW!!!) and the LOCF in Clinical Trials&lt;/A&gt;"&amp;nbsp;should be a good starting point. Further examples from the pharmaceutical area can be found in the award-winning paper "&lt;A href="http://www.lexjansen.com/phuse/2009/tu/tu01.pdf" target="_blank"&gt;Practical Uses of the DOW Loop in Pharmaceutical Programming&lt;/A&gt;." Technically more advanced is "&lt;A href="http://support.sas.com/resources/papers/proceedings09/038-2009.pdf" target="_blank"&gt;The DOW-Loop Unrolled&lt;/A&gt;."&lt;/P&gt;</description>
      <pubDate>Thu, 19 Nov 2015 22:39:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Counting-across-multiple-Rows/m-p/235576#M14697</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2015-11-19T22:39:23Z</dc:date>
    </item>
    <item>
      <title>Re: Counting across multiple Rows</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Counting-across-multiple-Rows/m-p/235650#M14699</link>
      <description>&lt;P&gt;To avoid more or less complicated&amp;nbsp;array and do-loop processing, transpose your data, so there are 365 rows per person, and one column for each drug.&lt;/P&gt;
&lt;P&gt;Then you can use a simple SQL to query your data.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Nov 2015 13:04:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Counting-across-multiple-Rows/m-p/235650#M14699</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2015-11-20T13:04:12Z</dc:date>
    </item>
    <item>
      <title>Re: Counting across multiple Rows</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Counting-across-multiple-Rows/m-p/235657#M14700</link>
      <description>Each time a person has a new drug, they are on a new line. So a person could have 10 of drug A, two of drug B and 1 of drug C for a total of 13 lines for this person. So there is the challenge. Each line has a indicator of which drug it is, but it is more complex than just one array per person.</description>
      <pubDate>Fri, 20 Nov 2015 13:27:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Counting-across-multiple-Rows/m-p/235657#M14700</guid>
      <dc:creator>cmahrb2</dc:creator>
      <dc:date>2015-11-20T13:27:22Z</dc:date>
    </item>
    <item>
      <title>Re: Counting across multiple Rows</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Counting-across-multiple-Rows/m-p/235667#M14701</link>
      <description>&lt;P&gt;Ok, given the additional complexity, I tend to agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674"&gt;@LinusH﻿&lt;/a&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, having followed the DOW loop approach so far, it is fun to adapt it to the new specifications!&amp;nbsp;&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, let's first create new test data&amp;amp;colon;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
length person 8
       drug $1;
array ondrug[365] $1;
do person=1 to 10;
  nd=int(25*ranuni(2718))+1;
  do i=1 to nd;
    drug=byte(65+int(3*ranuni(2718)));
    do _n_=1 to 365;
      ondrug[_n_]=put(int(1.05*ranuni(2718)), 1.);
    end;
    output;
  end;
end;
drop i nd;
run;

proc print data=have;
var person drug ondrug1-ondrug8;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Does this look more familiar?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so, the following, not too difficult modifications to the earlier program should do the trick:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
do until(last.person);
  set have;
  by person;
  array ondrug[365] $1;
  array ndrugs[365] $3;
  do d=1 to 365;
         if drug='A' &amp;amp; ondrug[d]='1' then substr(ndrugs[d],1,1)='1';
    else if drug='B' &amp;amp; ondrug[d]='1' then substr(ndrugs[d],2,1)='1';
    else if drug='C' &amp;amp; ondrug[d]='1' then substr(ndrugs[d],3,1)='1';
  end;
end;
do d=1 to 365;
  overlap_count=sum(overlap_count, ndrugs[d]='111');
end;
do until(last.person);
  set have;
  by person;
  output;
end;
drop d ndrugs:;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Nov 2015 14:26:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Counting-across-multiple-Rows/m-p/235667#M14701</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2015-11-20T14:26:48Z</dc:date>
    </item>
    <item>
      <title>Re: Counting across multiple Rows</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Counting-across-multiple-Rows/m-p/236174#M14710</link>
      <description>&lt;P&gt;Corresponing SQL would be something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select person, count(*) as no
   from have_transposed
   where sum(drug1, drug2, drug3) = 3
   group by&amp;nbsp;person
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Not saying it's better, but...&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Nov 2015 11:36:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Counting-across-multiple-Rows/m-p/236174#M14710</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2015-11-24T11:36:19Z</dc:date>
    </item>
  </channel>
</rss>

