<?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: Making conditional statements across both rows and columns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Making-conditional-statements-across-both-rows-and-columns/m-p/805793#M317418</link>
    <description>&lt;P&gt;Person 1 has A and B in the same obs, why is this person kept?&lt;/P&gt;</description>
    <pubDate>Mon, 04 Apr 2022 06:56:11 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2022-04-04T06:56:11Z</dc:date>
    <item>
      <title>Making conditional statements across both rows and columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-conditional-statements-across-both-rows-and-columns/m-p/805785#M317413</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;***updated question***&lt;/P&gt;
&lt;P&gt;If there is a B in var1 occurring on the same date as an A, remove person.&lt;/P&gt;
&lt;P&gt;Person 2 is out with 1/25 rows having A and B.&lt;/P&gt;
&lt;P&gt;Person 3 is out with 3/20 rows having A and B.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry for making a mess my first try.&lt;/P&gt;
&lt;P&gt;***&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;DATA have;&lt;BR /&gt;input id date mmddyy10. var1 $;&lt;BR /&gt;format date mmddyy10.;&lt;BR /&gt;CARDS;&lt;BR /&gt;1 02/20/2016 A &lt;BR /&gt;1 02/25/2016 B&lt;BR /&gt;2 01/25/2016 A &lt;BR /&gt;2 01/25/2016 B &lt;BR /&gt;2 01/29/2016 B &lt;BR /&gt;2 02/04/2016 A&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3 03/10/2016 A&amp;nbsp; &lt;BR /&gt;3 03/20/2016 A&amp;nbsp; &lt;BR /&gt;3 03/20/2016 B&amp;nbsp; &lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;DATA want;&lt;BR /&gt;input id date mmddyy10. var1 $;&lt;BR /&gt;format date mmddyy10.;&lt;BR /&gt;CARDS;&lt;BR /&gt;1 02/20/2016 A &lt;BR /&gt;1 02/25/2016 B&lt;/P&gt;
&lt;P&gt;;&lt;BR /&gt;RUN;&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;***old question***&lt;/P&gt;
&lt;P&gt;I'm having trouble making conditional statements across rows and columns. Any help is appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If there is a B in any var 1-3 occurring on the same date as an A, remove person.&lt;/P&gt;
&lt;P&gt;Person 2 is removed because on 1/25 he has a B on his second row in var *3*.&lt;/P&gt;
&lt;P&gt;Person 3 is removed because on 3/18 he has both A and B in the vars.&lt;/P&gt;
&lt;P&gt;***&lt;/P&gt;
&lt;P&gt;***old code***&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;DATA have;&lt;BR /&gt;input id date mmddyy10. var1 $ var2 $ var3 $;&lt;BR /&gt;format date mmddyy10.;&lt;BR /&gt;CARDS;&lt;BR /&gt;1 02/20/2016 B C C &lt;BR /&gt;1 02/25/2016 A C C&lt;BR /&gt;2 01/25/2016 A B C&lt;BR /&gt;2 01/25/2016 A C B&lt;BR /&gt;2 01/29/2016 A B C&lt;BR /&gt;2 02/04/2016 A B C&lt;BR /&gt;3 03/18/2016 A C B &lt;BR /&gt;3 03/20/2016 A A C &lt;BR /&gt;3 09/06/2016 B A C&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;DATA want;&lt;BR /&gt;input id date mmddyy10. var1 $ var2 $ var3 $;&lt;BR /&gt;format date mmddyy10.;&lt;BR /&gt;CARDS;&lt;BR /&gt;1 02/20/2016 B A C &lt;BR /&gt;1 02/25/2016 A B C&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;***&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2022 07:23:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-conditional-statements-across-both-rows-and-columns/m-p/805785#M317413</guid>
      <dc:creator>Manhort</dc:creator>
      <dc:date>2022-04-04T07:23:02Z</dc:date>
    </item>
    <item>
      <title>Re: Making conditional statements across both rows and columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-conditional-statements-across-both-rows-and-columns/m-p/805793#M317418</link>
      <description>&lt;P&gt;Person 1 has A and B in the same obs, why is this person kept?&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2022 06:56:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-conditional-statements-across-both-rows-and-columns/m-p/805793#M317418</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-04-04T06:56:11Z</dc:date>
    </item>
    <item>
      <title>Re: Making conditional statements across both rows and columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-conditional-statements-across-both-rows-and-columns/m-p/805794#M317419</link>
      <description>&lt;P&gt;Person 1 should also be removed, because in both observations, there is an "A" and a "B", same as here:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;3 03/18/2016 A C B &lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2022 06:57:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-conditional-statements-across-both-rows-and-columns/m-p/805794#M317419</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-04T06:57:30Z</dc:date>
    </item>
    <item>
      <title>Re: Making conditional statements across both rows and columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-conditional-statements-across-both-rows-and-columns/m-p/805795#M317420</link>
      <description>&lt;P&gt;Your explanations are unclear.&lt;/P&gt;
&lt;P&gt;All variables have ABC in their data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&amp;gt;Person 2 is removed because on 1/25 he has a B on his second row in var 2.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;No it doesn't. There's C there (in red below).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&amp;gt;Person 3 is removed because on 3/18 he has both A and B in the vars.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Just like ID=1 ? What's the difference?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you mean B in VAR2 and A in VAR1 or VAR3 for the same date?&lt;/P&gt;
&lt;P&gt;&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/417971"&gt;@Manhort&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm having trouble making conditional statements across rows and columns. Any help is appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If there is a B in any var 1-3 occurring on the same date as an A, remove person.&lt;/P&gt;
&lt;P&gt;Person 2 is removed because on 1/25 he has a B on his second row in var 2.&lt;/P&gt;
&lt;P&gt;Person 3 is removed because on 3/18 he has both A and B in the vars.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;DATA have;&lt;BR /&gt;input id date mmddyy10. var1 $ var2 $ var3 $;&lt;BR /&gt;format date mmddyy10.;&lt;BR /&gt;CARDS;&lt;BR /&gt;1 02/20/2016 B A C &lt;BR /&gt;1 02/25/2016 A B C&lt;BR /&gt;2 01/25/2016 A B C&lt;BR /&gt;2 01/25/2016 A &lt;FONT color="#FF0000"&gt;C&lt;/FONT&gt; B&lt;BR /&gt;2 01/29/2016 A B C&lt;BR /&gt;2 02/04/2016 A B C&lt;BR /&gt;3 03/18/2016 A C B &lt;BR /&gt;3 03/20/2016 A A C &lt;BR /&gt;3 09/06/2016 B A C&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;DATA want;&lt;BR /&gt;input id date mmddyy10. var1 $ var2 $ var3 $;&lt;BR /&gt;format date mmddyy10.;&lt;BR /&gt;CARDS;&lt;BR /&gt;1 02/20/2016 B A C &lt;BR /&gt;1 02/25/2016 A B C&lt;BR /&gt;;&lt;BR /&gt;RUN;&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;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2022 06:59:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-conditional-statements-across-both-rows-and-columns/m-p/805795#M317420</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2022-04-04T06:59:35Z</dc:date>
    </item>
    <item>
      <title>Re: Making conditional statements across both rows and columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-conditional-statements-across-both-rows-and-columns/m-p/805796#M317421</link>
      <description>Apologies, I typed his rows incorrectly.</description>
      <pubDate>Mon, 04 Apr 2022 07:08:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-conditional-statements-across-both-rows-and-columns/m-p/805796#M317421</guid>
      <dc:creator>Manhort</dc:creator>
      <dc:date>2022-04-04T07:08:00Z</dc:date>
    </item>
    <item>
      <title>Re: Making conditional statements across both rows and columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-conditional-statements-across-both-rows-and-columns/m-p/805800#M317423</link>
      <description>&lt;P&gt;Then see this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
if 0 then set have; /* defines variables in PDV */
array vars {*} var1-var3;
do until (last.id);
  have_a = 0;
  have_b = 0;
  do until (last.date);
    set have;
    by id date;
    do i = 1 to dim(vars);
      if vars{i} = "A" then have_a = 1;
      if vars{i} = "B" then have_b = 1;
    end;
  end;
end;
if sum(have_a,have_b) &amp;lt; 2 then outflag = 1;
do until (last.id);
  set have;
  by id;
  if outflag then output;
end;
drop have_a have_b i outflag;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Apr 2022 07:12:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-conditional-statements-across-both-rows-and-columns/m-p/805800#M317423</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-04T07:12:14Z</dc:date>
    </item>
    <item>
      <title>Re: Making conditional statements across both rows and columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-conditional-statements-across-both-rows-and-columns/m-p/805804#M317427</link>
      <description>Sorry for submitting a mess I didn't realize. I simplified the question and the data. I feel like I was trying to do too much at one time anyway.</description>
      <pubDate>Mon, 04 Apr 2022 07:24:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-conditional-statements-across-both-rows-and-columns/m-p/805804#M317427</guid>
      <dc:creator>Manhort</dc:creator>
      <dc:date>2022-04-04T07:24:17Z</dc:date>
    </item>
    <item>
      <title>Conditions across rows of same ID.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-conditional-statements-across-both-rows-and-columns/m-p/805806#M317440</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm resubmitting a similar question that I butchered posting earlier.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's what I'm trying to do:&lt;/P&gt;
&lt;P&gt;If there is a B in var1 occurring on the same date as an A, remove that person.&lt;/P&gt;
&lt;P&gt;Person 2 is out with 1/25 rows having A and B.&lt;/P&gt;
&lt;P&gt;Person 3 is out with 3/20 rows having A and B.&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;BR /&gt;DATA have;&lt;BR /&gt;input id date mmddyy10. var1 $;&lt;BR /&gt;format date mmddyy10.;&lt;BR /&gt;CARDS;&lt;BR /&gt;1 02/20/2016 A&lt;BR /&gt;1 02/25/2016 B&lt;BR /&gt;2 01/25/2016 A&lt;BR /&gt;2 01/25/2016 B&lt;BR /&gt;2 01/29/2016 B&lt;BR /&gt;2 02/04/2016 A&lt;/P&gt;
&lt;P&gt;3 03/10/2016 A &lt;BR /&gt;3 03/20/2016 A &lt;BR /&gt;3 03/20/2016 B &lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;DATA want;&lt;BR /&gt;input id date mmddyy10. var1 $;&lt;BR /&gt;format date mmddyy10.;&lt;BR /&gt;CARDS;&lt;BR /&gt;1 02/20/2016 A&lt;BR /&gt;1 02/25/2016 B&lt;/P&gt;
&lt;P&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help is appreciated!&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2022 08:05:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-conditional-statements-across-both-rows-and-columns/m-p/805806#M317440</guid>
      <dc:creator>Manhort</dc:creator>
      <dc:date>2022-04-04T08:05:00Z</dc:date>
    </item>
    <item>
      <title>Re: Conditions across rows of same ID.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-conditional-statements-across-both-rows-and-columns/m-p/805827#M317441</link>
      <description>&lt;P&gt;I have merged your posts. It is really not necessary to re-post a question.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2022 10:50:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-conditional-statements-across-both-rows-and-columns/m-p/805827#M317441</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-04-04T10:50:47Z</dc:date>
    </item>
    <item>
      <title>Re: Conditions across rows of same ID.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-conditional-statements-across-both-rows-and-columns/m-p/805951#M317502</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt; If there is a B in var1 occurring on the same date as an A, remove that person.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Here's one way, where steps are clearly (hopefully) detailed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DELETE ;
 merge HAVE (in=A where=(VAR1='A'))
       HAVE (in=B where=(VAR1='B'))
       ;
 by ID DATE;
 if A &amp;amp; B;    * keep records marking deletion;
run;

data WANT;
 merge HAVE 
       DELETE (in=A keep=ID)
       ;
 by ID;   
 retain DELETE; 
 if first.ID then DELETE=A; * flag IDs marked for deletion;
 if not DELETE;             * keep if ID not marked for deletion; 
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Apr 2022 22:09:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-conditional-statements-across-both-rows-and-columns/m-p/805951#M317502</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2022-04-04T22:09:42Z</dc:date>
    </item>
  </channel>
</rss>

