<?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 Statement with multiple variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/IF-Statement-with-multiple-variables/m-p/466658#M119090</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a survey dataset includes a scale from 0 to 3. Three is the most, One is the least. However for certain questions in the dataset, the answers are wrongly recorded with the assumption that 0 is most and 3 is least. There are ultimately 15 variables that have the wrong answer, and I have to correct them.&amp;nbsp;&lt;/P&gt;&lt;P&gt;So far I have a basic if then statements to correct the scores for one variable called Q2V1. (Question 2, Visit 1). But I want to include all the other Question variables in the same statement if possible.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Data CorrectedQuestion;
Set Survey;
if Q2V1, = 0 then Q2V1 = 3;
if Q2V1 = 1 then Q2V1 = 2;
if Q2V1 = 2 then Q2V1 = 1;
if Q2V1 = 3 then Q2V1 = 0;
if Q2V1 = -99 then Q2V1 = .; &lt;/PRE&gt;&lt;P&gt;Essentially, I want to say, if any of these variables = x , then any of these variables = y.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;-E&lt;/P&gt;</description>
    <pubDate>Thu, 31 May 2018 22:38:47 GMT</pubDate>
    <dc:creator>Errant</dc:creator>
    <dc:date>2018-05-31T22:38:47Z</dc:date>
    <item>
      <title>IF Statement with multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-Statement-with-multiple-variables/m-p/466658#M119090</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a survey dataset includes a scale from 0 to 3. Three is the most, One is the least. However for certain questions in the dataset, the answers are wrongly recorded with the assumption that 0 is most and 3 is least. There are ultimately 15 variables that have the wrong answer, and I have to correct them.&amp;nbsp;&lt;/P&gt;&lt;P&gt;So far I have a basic if then statements to correct the scores for one variable called Q2V1. (Question 2, Visit 1). But I want to include all the other Question variables in the same statement if possible.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Data CorrectedQuestion;
Set Survey;
if Q2V1, = 0 then Q2V1 = 3;
if Q2V1 = 1 then Q2V1 = 2;
if Q2V1 = 2 then Q2V1 = 1;
if Q2V1 = 3 then Q2V1 = 0;
if Q2V1 = -99 then Q2V1 = .; &lt;/PRE&gt;&lt;P&gt;Essentially, I want to say, if any of these variables = x , then any of these variables = y.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;-E&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 22:38:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-Statement-with-multiple-variables/m-p/466658#M119090</guid>
      <dc:creator>Errant</dc:creator>
      <dc:date>2018-05-31T22:38:47Z</dc:date>
    </item>
    <item>
      <title>Re: IF Statement with multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-Statement-with-multiple-variables/m-p/466664#M119093</link>
      <description>&lt;P&gt;The tool for repeating the same operations with multiple variables is array processing. An array is a way to reference each variable using an index value and a list of the variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Data CorrectedQuestion;
   Set Survey;
   array q Q2V1 ; /*list of other variables to process the same way goes after Q2v1*/
   do i=1 to dim(q);
      if Q[i], = 0 then Q[i] = 3;
      if Q[i] = 1 then Q[i] = 2;
      if Q[i] = 2 then Q[i] = 1;
      if Q[i] = 3 then Q[i] = 0;
      if Q[i] = -99 then Q[i] = .; 
   end;
   drop i;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;List all of the variables with spaces between them for the variables you want after the "array q". Q is the name of the array and elements are addressed using q[1] to reference the first assigned variable or a variable holding numbers within the range of the number of variables assigned to the array.&lt;/P&gt;
&lt;P&gt;The variable I is the index, the function dim returns the number of elements that have been assigned to the array q.&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 22:47:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-Statement-with-multiple-variables/m-p/466664#M119093</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-05-31T22:47:21Z</dc:date>
    </item>
    <item>
      <title>Re: IF Statement with multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-Statement-with-multiple-variables/m-p/466667#M119094</link>
      <description>&lt;P&gt;You can use an array here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data correctedQuestions;
set Survey;

array quest(*) list of variables to be corrected here;

do i=1 to dim(quest); *loop over questions;

    if quest(i) = -99 then quest(i) = .;
    else quest(i) = 3 - quest(i); *can avoid if/else with formula;

end;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/212633"&gt;@Errant&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a survey dataset includes a scale from 0 to 3. Three is the most, One is the least. However for certain questions in the dataset, the answers are wrongly recorded with the assumption that 0 is most and 3 is least. There are ultimately 15 variables that have the wrong answer, and I have to correct them.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So far I have a basic if then statements to correct the scores for one variable called Q2V1. (Question 2, Visit 1). But I want to include all the other Question variables in the same statement if possible.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Data CorrectedQuestion;
Set Survey;
if Q2V1, = 0 then Q2V1 = 3;
if Q2V1 = 1 then Q2V1 = 2;
if Q2V1 = 2 then Q2V1 = 1;
if Q2V1 = 3 then Q2V1 = 0;
if Q2V1 = -99 then Q2V1 = .; &lt;/PRE&gt;
&lt;P&gt;Essentially, I want to say, if any of these variables = x , then any of these variables = y.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;-E&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 22:57:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-Statement-with-multiple-variables/m-p/466667#M119094</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-05-31T22:57:04Z</dc:date>
    </item>
    <item>
      <title>Re: IF Statement with multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-Statement-with-multiple-variables/m-p/466668#M119095</link>
      <description>&lt;P&gt;It worked perfectly, thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 22:59:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-Statement-with-multiple-variables/m-p/466668#M119095</guid>
      <dc:creator>Errant</dc:creator>
      <dc:date>2018-05-31T22:59:29Z</dc:date>
    </item>
    <item>
      <title>Re: IF Statement with multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-Statement-with-multiple-variables/m-p/466706#M119123</link>
      <description>&lt;P&gt;No it didn't.&amp;nbsp; It ran without errors, and it gave you the same incorrect result as your original program.&amp;nbsp; You need to either add the word "else" or else switch to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;'s solution.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With the logic you started with, you will change all the "0" values to "3", and then change them back to "0" again.&amp;nbsp; Take a look at the final result you get ... no instances of "2", and no instances of "3".&amp;nbsp; Doesn't that look wrong?&lt;/P&gt;</description>
      <pubDate>Fri, 01 Jun 2018 02:35:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-Statement-with-multiple-variables/m-p/466706#M119123</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-06-01T02:35:00Z</dc:date>
    </item>
    <item>
      <title>Re: IF Statement with multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-Statement-with-multiple-variables/m-p/466719#M119129</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/212633"&gt;@Errant&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Recoding values is often done using Formats.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  value recodeItems
    0 = 3
    1 = 2
    2 = 1
    3 = 0
    other=.
  ;
run;

Data CorrectedQuestion(drop=_:);
   Set Survey;
   array q Q2V1 ; /*list of other variables to process the same way goes after Q2v1*/
   do _i=1 to dim(q);
      q[_i]=put(q[_i],recodeItems.);
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 Jun 2018 03:24:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-Statement-with-multiple-variables/m-p/466719#M119129</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-06-01T03:24:12Z</dc:date>
    </item>
    <item>
      <title>Re: IF Statement with multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-Statement-with-multiple-variables/m-p/467018#M119187</link>
      <description>&lt;P&gt;Thank you, this fully corrected the conversion problem.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Jun 2018 20:12:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-Statement-with-multiple-variables/m-p/467018#M119187</guid>
      <dc:creator>Errant</dc:creator>
      <dc:date>2018-06-01T20:12:31Z</dc:date>
    </item>
  </channel>
</rss>

