<?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 If condition on multiple variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/If-condition-on-multiple-variables/m-p/640636#M190877</link>
    <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset that I transposed and I want to do an if statement across multiple columns. I have attached a dummy version of the dataset (real once is a little more extensive but same concept). I have pasted my code below that I am trying to use but i get an error (pasted below). The column names in the array will be slightly different.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks everyone&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: Array subscript out of range at line 38 column 22.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data target;
set trans;

array pre {2} $8 m_202001 m_202002;
array post {1} $8 m_202003;
array time_period {3} $8 m_202001 m_202002 m_202003;

do i=1 to dim(time_period);
	if pre[i] = '' and post[i] = '' then target = 1;
    else if pre[i] ne '' and post[i] = '' then target = 2;
	else if pre[i] = '' and post[i] ne '' then target = 3;
	else target = 4;
end;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 17 Apr 2020 08:16:31 GMT</pubDate>
    <dc:creator>Scott86</dc:creator>
    <dc:date>2020-04-17T08:16:31Z</dc:date>
    <item>
      <title>If condition on multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-condition-on-multiple-variables/m-p/640636#M190877</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset that I transposed and I want to do an if statement across multiple columns. I have attached a dummy version of the dataset (real once is a little more extensive but same concept). I have pasted my code below that I am trying to use but i get an error (pasted below). The column names in the array will be slightly different.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks everyone&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: Array subscript out of range at line 38 column 22.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data target;
set trans;

array pre {2} $8 m_202001 m_202002;
array post {1} $8 m_202003;
array time_period {3} $8 m_202001 m_202002 m_202003;

do i=1 to dim(time_period);
	if pre[i] = '' and post[i] = '' then target = 1;
    else if pre[i] ne '' and post[i] = '' then target = 2;
	else if pre[i] = '' and post[i] ne '' then target = 3;
	else target = 4;
end;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Apr 2020 08:16:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-condition-on-multiple-variables/m-p/640636#M190877</guid>
      <dc:creator>Scott86</dc:creator>
      <dc:date>2020-04-17T08:16:31Z</dc:date>
    </item>
    <item>
      <title>Re: If condition on multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-condition-on-multiple-variables/m-p/640639#M190878</link>
      <description>&lt;P&gt;&amp;nbsp;Your index, i, goes from 1 to 3 and it indexes arrays with 1 or 2 elements. As you see, that does not work.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Apr 2020 08:33:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-condition-on-multiple-variables/m-p/640639#M190878</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2020-04-17T08:33:23Z</dc:date>
    </item>
    <item>
      <title>Re: If condition on multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-condition-on-multiple-variables/m-p/640645#M190881</link>
      <description>&lt;P&gt;Because of the errors, it's impossible to determine what you are trying to accomplish.&amp;nbsp; Here's a step you can take to eliminate the errors.&amp;nbsp; But whether it accomplishes the right thing or not ... that's impossible to tell.&amp;nbsp; Perhaps it will:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The current array definitions:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array pre {2} $8 m_202001 m_202002;
array post {1} $8 m_202003;
array time_period {3} $8 m_202001 m_202002 m_202003;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Legally, you could change it to:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array pre {3} $8 m_202001 m_202002 m_202002;
array post {3} $8 m_202003 m_202003 m_202003;
array time_period {3} $8 m_202001 m_202002 m_202003;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Apr 2020 09:07:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-condition-on-multiple-variables/m-p/640645#M190881</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-04-17T09:07:04Z</dc:date>
    </item>
  </channel>
</rss>

