<?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: make new variable that is true if any options in a group are true in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/make-new-variable-that-is-true-if-any-options-in-a-group-are/m-p/841029#M332533</link>
    <description>&lt;P&gt;And RANGE = 0 tells you that all the variables have the same value or missing. May all be true or all false but all the same.&lt;/P&gt;</description>
    <pubDate>Wed, 26 Oct 2022 20:43:45 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2022-10-26T20:43:45Z</dc:date>
    <item>
      <title>make new variable that is true if any options in a group are true</title>
      <link>https://communities.sas.com/t5/SAS-Programming/make-new-variable-that-is-true-if-any-options-in-a-group-are/m-p/841012#M332518</link>
      <description>&lt;P&gt;I have a feeling that I might be missing something simple, but I am having a difficult time figuring this out.&lt;/P&gt;&lt;P&gt;I have a dataset that looks something like this and what I am trying to do is create a new variable that is true if any of Var1 is true by each ID.&amp;nbsp; For example I am for this new variable to be true for all 11 rows and 12 rows. I have been trying to make this work using a do loop, but have not been able to quite get that to work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data example&lt;/P&gt;&lt;P&gt;input ID Var1&lt;/P&gt;&lt;P&gt;Datalines;&lt;/P&gt;&lt;P&gt;11 1&lt;/P&gt;&lt;P&gt;11 0&lt;/P&gt;&lt;P&gt;11 0&lt;/P&gt;&lt;P&gt;11 0&lt;/P&gt;&lt;P&gt;12 1&lt;/P&gt;&lt;P&gt;12 1&lt;/P&gt;&lt;P&gt;12 1&lt;/P&gt;&lt;P&gt;12 0&lt;/P&gt;&lt;P&gt;13 0&lt;/P&gt;&lt;P&gt;13 0&lt;/P&gt;&lt;P&gt;14 0&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Essentially I am looking for an output that looks a bit like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data goal&lt;/P&gt;&lt;P&gt;input ID Var1 group&lt;/P&gt;&lt;P&gt;Datalines;&lt;/P&gt;&lt;P&gt;11 1 1&lt;/P&gt;&lt;P&gt;11 0 1&lt;/P&gt;&lt;P&gt;11 0 1&lt;/P&gt;&lt;P&gt;11 0 1&lt;/P&gt;&lt;P&gt;12 1 1&lt;/P&gt;&lt;P&gt;12 1 1&lt;/P&gt;&lt;P&gt;12 1 1&lt;/P&gt;&lt;P&gt;12 0 1&lt;/P&gt;&lt;P&gt;13 0 0&lt;/P&gt;&lt;P&gt;13 0 0&lt;/P&gt;&lt;P&gt;14 0 0&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas?&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2022 19:54:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/make-new-variable-that-is-true-if-any-options-in-a-group-are/m-p/841012#M332518</guid>
      <dc:creator>smoore3790</dc:creator>
      <dc:date>2022-10-26T19:54:29Z</dc:date>
    </item>
    <item>
      <title>Re: make new variable that is true if any options in a group are true</title>
      <link>https://communities.sas.com/t5/SAS-Programming/make-new-variable-that-is-true-if-any-options-in-a-group-are/m-p/841017#M332523</link>
      <description>&lt;P&gt;The MAX() of a set of boolean values is true when ANY of them is true.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create goal as
select * , max(var1) as group
from example
group by id
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The MAX() of a set of boolean values is false when ALL of them are false.&lt;/P&gt;
&lt;P&gt;The MIN() of a set of boolean values is true when ALL of them are true.&lt;/P&gt;
&lt;P&gt;The MIN() of a set of boolean values is false when ANY of them are false.&lt;/P&gt;
&lt;P&gt;The SUM() of a set of boolean values counts how many of them that are true.&lt;/P&gt;
&lt;P&gt;The MEAN() of a set of boolean values is the percent of them that are true.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2022 20:04:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/make-new-variable-that-is-true-if-any-options-in-a-group-are/m-p/841017#M332523</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-10-26T20:04:41Z</dc:date>
    </item>
    <item>
      <title>Re: make new variable that is true if any options in a group are true</title>
      <link>https://communities.sas.com/t5/SAS-Programming/make-new-variable-that-is-true-if-any-options-in-a-group-are/m-p/841029#M332533</link>
      <description>&lt;P&gt;And RANGE = 0 tells you that all the variables have the same value or missing. May all be true or all false but all the same.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2022 20:43:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/make-new-variable-that-is-true-if-any-options-in-a-group-are/m-p/841029#M332533</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-10-26T20:43:45Z</dc:date>
    </item>
    <item>
      <title>Re: make new variable that is true if any options in a group are true</title>
      <link>https://communities.sas.com/t5/SAS-Programming/make-new-variable-that-is-true-if-any-options-in-a-group-are/m-p/841033#M332537</link>
      <description>&lt;P&gt;Here is a do(w) loop approach&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data example;
input ID Var1;
Datalines;
11 1
11 0
11 0
11 0
12 1
12 1
12 1
12 0
13 0
13 0
14 0
;

data goal;
   _iorc_ = 0;
   do until (last.ID);
      set example;
      by ID;
      if Var1 then _iorc_ = 1;
   end;

   do until (last.ID);
      set example;
      by ID;
      group = _iorc_;
      output;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Oct 2022 20:57:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/make-new-variable-that-is-true-if-any-options-in-a-group-are/m-p/841033#M332537</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-10-26T20:57:35Z</dc:date>
    </item>
    <item>
      <title>Re: make new variable that is true if any options in a group are true</title>
      <link>https://communities.sas.com/t5/SAS-Programming/make-new-variable-that-is-true-if-any-options-in-a-group-are/m-p/841035#M332539</link>
      <description>Thanks so much for the help this worked perfectly!</description>
      <pubDate>Wed, 26 Oct 2022 21:06:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/make-new-variable-that-is-true-if-any-options-in-a-group-are/m-p/841035#M332539</guid>
      <dc:creator>smoore3790</dc:creator>
      <dc:date>2022-10-26T21:06:12Z</dc:date>
    </item>
  </channel>
</rss>

