<?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: how to use var_: in 'if then' statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-var-in-if-then-statement/m-p/681488#M206133</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/215669"&gt;@nirsan&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hi, It worked. Can you please suggest what will be the code if I want to check the following condition?&lt;BR /&gt;If var_: not in (5) then flag=1;&lt;BR /&gt;if hlt_: not in ('100897') then flag=1;&lt;BR /&gt;&lt;BR /&gt;Thank you!&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That is&amp;nbsp;&lt;STRONG&gt;so&lt;/STRONG&gt; trivial that you can easily find the answer on your own. Just start the tool between your ears.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hint: negate the whole condition.&lt;/P&gt;</description>
    <pubDate>Thu, 03 Sep 2020 20:05:55 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-09-03T20:05:55Z</dc:date>
    <item>
      <title>how to use var_: in 'if then' statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-var-in-if-then-statement/m-p/681465#M206127</link>
      <description>&lt;P&gt;Hi all, I have some variables named like this var_1, var_2, var_3.....var_50. Right now it is up to var_50, but anytime if a new case is added to the data, it can be var_51, var_52 etc. So, I use the term var_: when I run frequency or crosstabs to avoid repeated&amp;nbsp; codes and to avoid writing new codes whenever&amp;nbsp; a new case is added. But whenever I use 'var_:' in 'if then statement', it does not work. Any suggestion? One thing to mention that var_1 is a neumaric variable but I but similar character variable too (eg. hlt_1, hlt_2, hlt_3 etc.) with which I have the same problem.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here is an example of code that I am using:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;If var_: in (5) then flag=1;&lt;/P&gt;&lt;P&gt;if hlt_: in ('100897') then flag=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 03 Sep 2020 19:09:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-var-in-if-then-statement/m-p/681465#M206127</guid>
      <dc:creator>nirsan</dc:creator>
      <dc:date>2020-09-03T19:09:13Z</dc:date>
    </item>
    <item>
      <title>Re: how to use var_: in 'if then' statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-var-in-if-then-statement/m-p/681469#M206129</link>
      <description>&lt;P&gt;You cannot use multiple variables on the left side of the IN operator, so you will have to change the expression, e.g. using WHICHN or WHICHC, e.g.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;If whichn(5,of var_:) then flag=1;
if whichc('100897',of hlt_:) then flag=1;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Sep 2020 19:40:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-var-in-if-then-statement/m-p/681469#M206129</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-09-03T19:40:11Z</dc:date>
    </item>
    <item>
      <title>Re: how to use var_: in 'if then' statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-var-in-if-then-statement/m-p/681483#M206131</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/215669"&gt;@nirsan&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alternatively, you can use the IN operator with an array:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
array var_[50];
array hlt_[50];
if 5 in var_ then flag1=1;
if '100897' in hlt_ then flag2=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To avoid the hardcoded array dimensions (50) you may want to replace the two ARRAY statements by&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array var_[*] var_:;
array hlt_[*] hlt_:;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note, however, that with this array definition (in general) the numeric suffix of a variable matches the corresponding array index only if the variables are ordered by the suffix in the dataset. Otherwise, for example, &lt;FONT face="courier new,courier"&gt;var_[3]&lt;/FONT&gt; could be &lt;FONT face="courier new,courier"&gt;var_2&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/215669"&gt;@nirsan&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;(...) Right now it is up to var_50, but anytime if a new case is added to the data, it can be var_51, var_52 etc. (...)&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That's why in many cases a "long" (vertical) data structure is preferable where a single variable, say, &lt;FONT face="courier new,courier"&gt;var&lt;/FONT&gt; holds the values of &lt;FONT face="courier new,courier"&gt;var_1&lt;/FONT&gt;, &lt;FONT face="courier new,courier"&gt;var_2&lt;/FONT&gt;, ... in different observations. Adding "a new case" then just means adding new &lt;EM&gt;observations&lt;/EM&gt;&amp;nbsp;(which is a routine operation), while the data &lt;EM&gt;structure&lt;/EM&gt; remains unchanged.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Sep 2020 20:07:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-var-in-if-then-statement/m-p/681483#M206131</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-09-03T20:07:53Z</dc:date>
    </item>
    <item>
      <title>Re: how to use var_: in 'if then' statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-var-in-if-then-statement/m-p/681484#M206132</link>
      <description>&lt;P&gt;Hi, It worked.&amp;nbsp;Thank you very much.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Sep 2020 20:27:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-var-in-if-then-statement/m-p/681484#M206132</guid>
      <dc:creator>nirsan</dc:creator>
      <dc:date>2020-09-03T20:27:08Z</dc:date>
    </item>
    <item>
      <title>Re: how to use var_: in 'if then' statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-var-in-if-then-statement/m-p/681488#M206133</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/215669"&gt;@nirsan&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hi, It worked. Can you please suggest what will be the code if I want to check the following condition?&lt;BR /&gt;If var_: not in (5) then flag=1;&lt;BR /&gt;if hlt_: not in ('100897') then flag=1;&lt;BR /&gt;&lt;BR /&gt;Thank you!&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That is&amp;nbsp;&lt;STRONG&gt;so&lt;/STRONG&gt; trivial that you can easily find the answer on your own. Just start the tool between your ears.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hint: negate the whole condition.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Sep 2020 20:05:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-var-in-if-then-statement/m-p/681488#M206133</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-03T20:05:55Z</dc:date>
    </item>
  </channel>
</rss>

