<?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: At least two options from a list of variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/At-least-two-options-from-a-list-of-variables/m-p/745813#M233869</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And if it were only "equal to"? The symbol "=" would be good enough?&lt;/P&gt;</description>
    <pubDate>Fri, 04 Jun 2021 14:47:34 GMT</pubDate>
    <dc:creator>ramgouveia</dc:creator>
    <dc:date>2021-06-04T14:47:34Z</dc:date>
    <item>
      <title>At least two options from a list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/At-least-two-options-from-a-list-of-variables/m-p/745799#M233858</link>
      <description>&lt;P&gt;I want to define a variable which it assumes a value if at least two of six variables assume a value 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it were only one variable the code should be this one:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;FORMAT GE1 $1.;
IF QI020=1 OR QI021=1 OR QI022=1 OR QI023=1 OR QI024=1 OR QI027=1 THEN GE1=1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which code should I write for as least two options validated?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your help.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jun 2021 13:27:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/At-least-two-options-from-a-list-of-variables/m-p/745799#M233858</guid>
      <dc:creator>ramgouveia</dc:creator>
      <dc:date>2021-06-04T13:27:56Z</dc:date>
    </item>
    <item>
      <title>Re: At least two options from a list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/At-least-two-options-from-a-list-of-variables/m-p/745802#M233860</link>
      <description>&lt;P&gt;IF sum(QI020=1 , QI021=1 , QI022=1 , QI023=1 , QI024=1 , QI027=1)&amp;nbsp; &amp;gt;= 2 THEN GE1=1;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Jun 2021 10:02:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/At-least-two-options-from-a-list-of-variables/m-p/745802#M233860</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-06-05T10:02:51Z</dc:date>
    </item>
    <item>
      <title>Re: At least two options from a list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/At-least-two-options-from-a-list-of-variables/m-p/745803#M233861</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Shouldn't it be like this with a &amp;gt; sign?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;IF sum(QI020, QI021, QI022, QI023, QI024, QI027) &amp;gt;= 2 THEN GE1=1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jun 2021 14:17:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/At-least-two-options-from-a-list-of-variables/m-p/745803#M233861</guid>
      <dc:creator>ramgouveia</dc:creator>
      <dc:date>2021-06-04T14:17:16Z</dc:date>
    </item>
    <item>
      <title>Re: At least two options from a list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/At-least-two-options-from-a-list-of-variables/m-p/745806#M233863</link>
      <description>&lt;P&gt;If the other values for those variables are 0 or missing use something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;IF sum( QI020,QI021,QI022,QI023,QI024,QI027) ge 2 THEN GE1=1;&lt;/LI-CODE&gt;
&lt;P&gt;If you want Ge1 to be character use ='1';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the other values can take more of a range then&lt;/P&gt;
&lt;PRE&gt;IF sum( QI020=1, QI021=1, QI022=1, QI023=1, QI024=1, QI027=1) ge 2 THEN GE1=1;&lt;/PRE&gt;
&lt;P&gt;SAS will use a value of 1 for a true comparison and 0 otherwise. So the Sum above gets the number of "true" comparison results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jun 2021 14:14:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/At-least-two-options-from-a-list-of-variables/m-p/745806#M233863</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-06-04T14:14:40Z</dc:date>
    </item>
    <item>
      <title>Re: At least two options from a list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/At-least-two-options-from-a-list-of-variables/m-p/745811#M233867</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ge 2&lt;/PRE&gt;
&lt;P&gt;Is the same to say equal or greater than 2?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jun 2021 14:39:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/At-least-two-options-from-a-list-of-variables/m-p/745811#M233867</guid>
      <dc:creator>ramgouveia</dc:creator>
      <dc:date>2021-06-04T14:39:50Z</dc:date>
    </item>
    <item>
      <title>Re: At least two options from a list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/At-least-two-options-from-a-list-of-variables/m-p/745812#M233868</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/369095"&gt;@ramgouveia&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ge 2&lt;/PRE&gt;
&lt;P&gt;Is the same to say equal or greater than 2?&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes. I tend to use the ge and le instead of &amp;gt;= or&amp;lt;=&amp;nbsp; because sometimes if you get the order wrong (typo) they can mean different things in some code&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jun 2021 14:45:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/At-least-two-options-from-a-list-of-variables/m-p/745812#M233868</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-06-04T14:45:05Z</dc:date>
    </item>
    <item>
      <title>Re: At least two options from a list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/At-least-two-options-from-a-list-of-variables/m-p/745813#M233869</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And if it were only "equal to"? The symbol "=" would be good enough?&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jun 2021 14:47:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/At-least-two-options-from-a-list-of-variables/m-p/745813#M233869</guid>
      <dc:creator>ramgouveia</dc:creator>
      <dc:date>2021-06-04T14:47:34Z</dc:date>
    </item>
    <item>
      <title>Re: At least two options from a list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/At-least-two-options-from-a-list-of-variables/m-p/745815#M233871</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/369095"&gt;@ramgouveia&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And if it were only "equal to"? The symbol "=" would be good enough?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes.&lt;/P&gt;
&lt;P&gt;Or EQ&amp;nbsp; , GT (greater than: &amp;gt; ) , LT (less than: &amp;lt;)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sometimes in specific code it may be helpful to be able to tell the difference between an "assignment" = sign or a "comparison" equal sign. Though I suspect part of the text comes from 1) ancient keyboards with fewer characters and 2) derivation from another language like FORTRAN when coding syntax decisions were made.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It might be appropriate to note that this method of counting also works with Character values or a mix because the comparisons would also return 1/0:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if sum(var1='A', var2='B', var3 in ('P' 'D' 'Q'), var5&amp;gt;7) ge 3&lt;/P&gt;
&lt;P&gt;for example.&lt;/P&gt;
&lt;P&gt;If you haven't run into the IN comparison you can provide a list of values (NOT variables) to compare and if the variable takes any of the values it returns true. The comparison would be the equivalent of : var3='P' or Var3='D' or Var3='Q'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use the MIN function instead of SUM as an alternative way of "at least one is true" : min(&amp;lt;comparison list) =1&lt;/P&gt;
&lt;P&gt;The Range function can tell if they all have the same result (all true or all false and Range will return 0)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Caution: Missing is always "less than" any value so may need to consider that when using &amp;lt; or &amp;lt;= as comparisons.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jun 2021 15:16:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/At-least-two-options-from-a-list-of-variables/m-p/745815#M233871</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-06-04T15:16:06Z</dc:date>
    </item>
    <item>
      <title>Re: At least two options from a list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/At-least-two-options-from-a-list-of-variables/m-p/745979#M233948</link>
      <description>Yes. You are right. Just correct it .</description>
      <pubDate>Sat, 05 Jun 2021 10:03:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/At-least-two-options-from-a-list-of-variables/m-p/745979#M233948</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-06-05T10:03:19Z</dc:date>
    </item>
  </channel>
</rss>

