<?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: Why doesn't the colon work for multiple variables in IF statements? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Why-doesn-t-the-colon-work-for-multiple-variables-in-IF/m-p/693694#M211562</link>
    <description>&lt;P&gt;Using the wildcard creates a&amp;nbsp;&lt;EM&gt;list&lt;/EM&gt; of variables, which means you can use it in all places where a&amp;nbsp;&lt;EM&gt;list&lt;/EM&gt; of variables is syntactically correct.&lt;/P&gt;
&lt;P&gt;A condition does not accept a list of variables, therefore you can't use the wildcard there.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if var1 var2 var3 = x&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is quite obviously not correct and not translatable for the data step compiler.&lt;/P&gt;
&lt;P&gt;Either use an array through which you can loop, or a function that accepts lists through the of: operator.&lt;/P&gt;</description>
    <pubDate>Fri, 23 Oct 2020 10:03:11 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-10-23T10:03:11Z</dc:date>
    <item>
      <title>Why doesn't the colon work for multiple variables in IF statements?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-doesn-t-the-colon-work-for-multiple-variables-in-IF/m-p/693663#M211559</link>
      <description>&lt;P&gt;I was reading some code today at work that someone else had written, and it looks something like this code below (I've used the SASHELP.BASEBALL table as example instead of my work data set). They've got several variables that start with the same characters and then various and/or conditions. This example is simplified, but in my work example it contains about 15 if/else statements and I wanted to make the code more concise.&lt;/P&gt;
&lt;P&gt;I know that the colon can be used to easily drop several variables starting with the same characters (for example, I can use drop n: to drop all the variables in the Baseball data set that start with n, and the set statement also allows users to set several tables starting with the same letters and using colon). I would have thought SAS would allow me to use the same colon method on the variables after the if, for example, if cr: &amp;gt;=200 then group='High', but it doesn't allow it. I know you can use cr: in an array. Is that the best way to tidy up many columns that start the same characters, or should I be trying something else? Thanks for your ideas.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set SASHELP.BASEBALL;
if crHits &amp;gt;= 200 and crHome &amp;gt;= 200 and crRuns &amp;gt;= 200 or crRbi&amp;gt;=200 then group='High';
else if crHits &amp;gt;= 100 or (crHome &amp;gt;= 100 and crRuns &amp;gt;= 100) then group='Med';
drop n: ; 
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Oct 2020 06:28:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-doesn-t-the-colon-work-for-multiple-variables-in-IF/m-p/693663#M211559</guid>
      <dc:creator>Buzzy_Bee</dc:creator>
      <dc:date>2020-10-23T06:28:01Z</dc:date>
    </item>
    <item>
      <title>Re: Why doesn't the colon work for multiple variables in IF statements?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-doesn-t-the-colon-work-for-multiple-variables-in-IF/m-p/693689#M211561</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/339434"&gt;@Buzzy_Bee&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think the interpretation of a hypothetical condition like "&lt;FONT face="courier new,courier"&gt;cr: &amp;gt;=200&lt;/FONT&gt;" would not be clear. Would it mean for the variables with names starting with "&lt;FONT face="courier new,courier"&gt;cr&lt;/FONT&gt;" that &lt;EM&gt;all&lt;/EM&gt; of them are &amp;gt;=200 or &lt;EM&gt;at least one&lt;/EM&gt; of them?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that neither of these two interpretations would be applicable to your example IF conditions: Your AND/OR combinations are logically different from both interpretations. Moreover, the variable list &lt;FONT face="courier new,courier"&gt;cr:&lt;/FONT&gt;&amp;nbsp;would include existing variables such as &lt;FONT face="courier new,courier"&gt;CrAtBat&lt;/FONT&gt;&amp;nbsp;or&amp;nbsp;&lt;FONT face="courier new,courier"&gt;CrBB&lt;/FONT&gt; which are not considered in your conditions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In addition to arrays you can use variable lists (like &lt;FONT face="courier new,courier"&gt;cr:&lt;/FONT&gt;, &lt;FONT face="courier new,courier"&gt;a1-a10&lt;/FONT&gt; or &lt;FONT face="courier new,courier"&gt;name--weight&lt;/FONT&gt;) in SAS functions. For example, if, like in SASHELP.BASEBALL, no missing values are present in the variables involved, you could abbreviate the first IF condition to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;max(min(of crHits--crRuns),crRbi) &amp;gt;= 200&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In the (potential) presence of missing values&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;max(ordinal(1, of crHits--crRuns),crRbi) &amp;gt;= 200&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;would ensure that missings among &lt;FONT face="courier new,courier"&gt;crHits, crHome&lt;/FONT&gt;&amp;nbsp;and&amp;nbsp;&lt;FONT face="courier new,courier"&gt;crRuns&lt;/FONT&gt; are not ignored when the minimum is determined.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Oct 2020 09:52:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-doesn-t-the-colon-work-for-multiple-variables-in-IF/m-p/693689#M211561</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-10-23T09:52:32Z</dc:date>
    </item>
    <item>
      <title>Re: Why doesn't the colon work for multiple variables in IF statements?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-doesn-t-the-colon-work-for-multiple-variables-in-IF/m-p/693694#M211562</link>
      <description>&lt;P&gt;Using the wildcard creates a&amp;nbsp;&lt;EM&gt;list&lt;/EM&gt; of variables, which means you can use it in all places where a&amp;nbsp;&lt;EM&gt;list&lt;/EM&gt; of variables is syntactically correct.&lt;/P&gt;
&lt;P&gt;A condition does not accept a list of variables, therefore you can't use the wildcard there.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if var1 var2 var3 = x&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is quite obviously not correct and not translatable for the data step compiler.&lt;/P&gt;
&lt;P&gt;Either use an array through which you can loop, or a function that accepts lists through the of: operator.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Oct 2020 10:03:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-doesn-t-the-colon-work-for-multiple-variables-in-IF/m-p/693694#M211562</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-23T10:03:11Z</dc:date>
    </item>
    <item>
      <title>Re: Why doesn't the colon work for multiple variables in IF statements?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-doesn-t-the-colon-work-for-multiple-variables-in-IF/m-p/693948#M211609</link>
      <description>Thanks for listing those two examples. The use of the ordinal function is a particularly nice solution.</description>
      <pubDate>Sat, 24 Oct 2020 00:44:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-doesn-t-the-colon-work-for-multiple-variables-in-IF/m-p/693948#M211609</guid>
      <dc:creator>Buzzy_Bee</dc:creator>
      <dc:date>2020-10-24T00:44:19Z</dc:date>
    </item>
  </channel>
</rss>

