<?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: Recoding multiple variables with three categories at once in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Recoding-multiple-variables-with-three-categories-at-once/m-p/527840#M143972</link>
    <description>&lt;P&gt;1. Do not write all upper case code, that's hard to read&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. This might help:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do I&amp;nbsp;= 1 to 5;
&amp;nbsp; if&amp;nbsp;VARS{I}&amp;nbsp;=2 then&amp;nbsp;VARS{I} = 0;&amp;nbsp;
  if&amp;nbsp;VARS{I}&amp;nbsp;=3 then&amp;nbsp;VARS{I} = .;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 16 Jan 2019 20:50:16 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2019-01-16T20:50:16Z</dc:date>
    <item>
      <title>Recoding multiple variables with three categories at once</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recoding-multiple-variables-with-three-categories-at-once/m-p/527839#M143971</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to recode a number of variables with three categories 1=Yes, 2=No and 3=N/A as 1=Yes, 0=No and 3=. (i.e. missing). I've tried using the following code, but this changes both 2 and 3 to 0.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ARRAY VARS{5} g3_1 g3_2 g3_3 g3_4 g3_5;&lt;BR /&gt;DO _N_ = 1 TO 5;&lt;BR /&gt;IF VARS{_N_} NE 1 THEN VARS{_N_} = 0;&lt;BR /&gt;END;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Help please. Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 16 Jan 2019 20:41:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recoding-multiple-variables-with-three-categories-at-once/m-p/527839#M143971</guid>
      <dc:creator>aowais</dc:creator>
      <dc:date>2019-01-16T20:41:03Z</dc:date>
    </item>
    <item>
      <title>Re: Recoding multiple variables with three categories at once</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recoding-multiple-variables-with-three-categories-at-once/m-p/527840#M143972</link>
      <description>&lt;P&gt;1. Do not write all upper case code, that's hard to read&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. This might help:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do I&amp;nbsp;= 1 to 5;
&amp;nbsp; if&amp;nbsp;VARS{I}&amp;nbsp;=2 then&amp;nbsp;VARS{I} = 0;&amp;nbsp;
  if&amp;nbsp;VARS{I}&amp;nbsp;=3 then&amp;nbsp;VARS{I} = .;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Jan 2019 20:50:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recoding-multiple-variables-with-three-categories-at-once/m-p/527840#M143972</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-01-16T20:50:16Z</dc:date>
    </item>
    <item>
      <title>Re: Recoding multiple variables with three categories at once</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recoding-multiple-variables-with-three-categories-at-once/m-p/527841#M143973</link>
      <description>&lt;P&gt;I have to assume that you mean you want to change the value of the variable from 2 to 0 and 3 to missing. Your code shows nothing about yes. no or n/a. If you have format that displays that text for the values you will need a different format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
   set have; 
   ARRAY VARS{5} g3_1 g3_2 g3_3 g3_4 g3_5;
   DO _N_ = 1 TO dim(vars);
      if vars[i]=2 then vars[i]=0;
      else if vars[i]=3 then vars[i]=.;
   END ;
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Jan 2019 20:53:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recoding-multiple-variables-with-three-categories-at-once/m-p/527841#M143973</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-01-16T20:53:26Z</dc:date>
    </item>
    <item>
      <title>Re: Recoding multiple variables with three categories at once</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recoding-multiple-variables-with-three-categories-at-once/m-p/527845#M143977</link>
      <description>&lt;P&gt;Thank you. Point noted about upper case.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I try your suggestion, it works for the first two variables, but for the last three, all values end up missing...&lt;/P&gt;</description>
      <pubDate>Wed, 16 Jan 2019 20:59:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recoding-multiple-variables-with-three-categories-at-once/m-p/527845#M143977</guid>
      <dc:creator>aowais</dc:creator>
      <dc:date>2019-01-16T20:59:37Z</dc:date>
    </item>
    <item>
      <title>Re: Recoding multiple variables with three categories at once</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recoding-multiple-variables-with-three-categories-at-once/m-p/527851#M143979</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/255712"&gt;@aowais&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you. Point noted about upper case.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I try your suggestion, it works for the first two variables, but for the last three, all values end up missing...&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Example input and output data. This sounds like a data issue and you have not shared any actual values.&lt;/P&gt;
&lt;P&gt;Also show your code. A common mistake is to use the code structure of&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;lt;code that modifies values&amp;gt;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;The first pass through the data means that you have &lt;STRONG&gt;replaced&lt;/STRONG&gt; the original values and are now further modifying the incorrectly coded values from the first pass through the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does your log show any warnings?&lt;/P&gt;</description>
      <pubDate>Wed, 16 Jan 2019 21:12:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recoding-multiple-variables-with-three-categories-at-once/m-p/527851#M143979</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-01-16T21:12:03Z</dc:date>
    </item>
    <item>
      <title>Re: Recoding multiple variables with three categories at once</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recoding-multiple-variables-with-three-categories-at-once/m-p/527871#M143992</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt; it works for the first two variables, but for the last three, all values end up missing...&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the values are the same and the logic is&amp;nbsp;the same, then the result is the same.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Check your data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A more flexible logic might also help:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do I = 1 to 5;
  if      VARS{I} = 1 then ; 
  else if VARS{I} = 2 then VARS{I} = 0; 
  else                     VARS{I} = .;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Jan 2019 22:13:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recoding-multiple-variables-with-three-categories-at-once/m-p/527871#M143992</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-01-16T22:13:43Z</dc:date>
    </item>
    <item>
      <title>Re: Recoding multiple variables with three categories at once</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recoding-multiple-variables-with-three-categories-at-once/m-p/528302#M144171</link>
      <description>&lt;P&gt;Thank you! This worked!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jan 2019 14:17:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recoding-multiple-variables-with-three-categories-at-once/m-p/528302#M144171</guid>
      <dc:creator>aowais</dc:creator>
      <dc:date>2019-01-18T14:17:58Z</dc:date>
    </item>
  </channel>
</rss>

