<?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: IF then statements re-coding string into numeric in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/IF-then-statements-re-coding-string-into-numeric/m-p/594530#M170823</link>
    <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp; SAS has an operator that will compare a single&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;variable&amp;nbsp;&lt;/STRONG&gt;&lt;SPAN&gt;to a list of values but not one that compares a list of variables to a single value.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;That's what WHICHC and WHICHN are, they look for a value in a list of variables.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 07 Oct 2019 19:24:21 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-10-07T19:24:21Z</dc:date>
    <item>
      <title>IF then statements re-coding string into numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-then-statements-re-coding-string-into-numeric/m-p/594487#M170802</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;This simple if then statement I am trying to use to re-code string variables X_1 X_2 and X_3 ("fever" can show up in any of the 3 X variables but not ever in all of them)&amp;nbsp; into a numeric Fever=1 is not working and I do not understand why.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if X_1 = "Fever" then do Fever=1;&lt;BR /&gt;end;&lt;BR /&gt;else do;&lt;BR /&gt;if X_2 = "Fever" then Fever=1;&lt;BR /&gt;if X_3 = "Fever" then Fever=1;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried if (x_1 or X_2 or X_3) = "fever" then do Fever=1;&lt;/P&gt;&lt;P&gt;but this does not seem to work due to the fact that X is not numeric?&lt;/P&gt;&lt;P&gt;What to do in this case ?&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2019 16:16:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-then-statements-re-coding-string-into-numeric/m-p/594487#M170802</guid>
      <dc:creator>Mscarboncopy</dc:creator>
      <dc:date>2019-10-07T16:16:49Z</dc:date>
    </item>
    <item>
      <title>Re: IF then statements re-coding string into numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-then-statements-re-coding-string-into-numeric/m-p/594489#M170804</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; 

if X_1 = "Fever" then  Fever=1;
else if X_2 = "Fever" then Fever=1;
else if X_3 = "Fever" then Fever=1;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;or&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if whichc('FEVER', of X_1-X_3)&amp;gt;0 then Fever = 1;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Either of those should work. If not, please post your full log from running each.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/210474"&gt;@Mscarboncopy&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;This simple if then statement I am trying to use to re-code string variables X_1 X_2 and X_3 ("fever" can show up in any of the 3 X variables but not ever in all of them)&amp;nbsp; into a numeric Fever=1 is not working and I do not understand why.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if X_1 = "Fever" then do Fever=1;&lt;BR /&gt;end;&lt;BR /&gt;else do;&lt;BR /&gt;if X_2 = "Fever" then Fever=1;&lt;BR /&gt;if X_3 = "Fever" then Fever=1;&lt;BR /&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried if (x_1 or X_2 or X_3) = "fever" then do Fever=1;&lt;/P&gt;
&lt;P&gt;but this does not seem to work due to the fact that X is not numeric?&lt;/P&gt;
&lt;P&gt;What to do in this case ?&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2019 16:24:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-then-statements-re-coding-string-into-numeric/m-p/594489#M170804</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-10-07T16:24:02Z</dc:date>
    </item>
    <item>
      <title>Re: IF then statements re-coding string into numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-then-statements-re-coding-string-into-numeric/m-p/594491#M170805</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/210474"&gt;@Mscarboncopy&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;This simple if then statement I am trying to use to re-code string variables X_1 X_2 and X_3 ("fever" can show up in any of the 3 X variables but not ever in all of them)&amp;nbsp; into a numeric Fever=1 is not working and I do not understand why.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if X_1 = "Fever" then do Fever=1;&lt;BR /&gt;end;&lt;BR /&gt;else do;&lt;BR /&gt;if X_2 = "Fever" then Fever=1;&lt;BR /&gt;if X_3 = "Fever" then Fever=1;&lt;BR /&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried if (x_1 or X_2 or X_3) = "fever" then do Fever=1;&lt;/P&gt;
&lt;P&gt;but this does not seem to work due to the fact that X is not numeric?&lt;/P&gt;
&lt;P&gt;What to do in this case ?&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Try&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;if x_1= "Fever" or X_2= "Fever" or X_3= "Fever"  then  Fever=1;
&lt;/PRE&gt;
&lt;P&gt;SAS has an operator that will compare a single &lt;STRONG&gt;variable&lt;/STRONG&gt; to a list of values but not one that compares a list of variables to a single value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The "DO" was also not needed unless you have multiple statements to execute when you find "Fever". Then you also would need an END to close the Do block.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also make sure your case is consistent, your example code showed "fever" in the last code but "Fever" in the first bits.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2019 16:26:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-then-statements-re-coding-string-into-numeric/m-p/594491#M170805</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-10-07T16:26:37Z</dc:date>
    </item>
    <item>
      <title>Re: IF then statements re-coding string into numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-then-statements-re-coding-string-into-numeric/m-p/594494#M170807</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/210474"&gt;@Mscarboncopy&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another option: Use an array and the IN operator.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id (x_1-x_3) (:$30.);
cards;
1 Fever Fatigue Headache
2 Nausea Headache Rash
3 Headache Fever Fatigue 
4 Nausea Headache Fever
;

data want;
set have;
array x_[3];
Fever='Fever' in x_;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 07 Oct 2019 16:35:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-then-statements-re-coding-string-into-numeric/m-p/594494#M170807</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-10-07T16:35:51Z</dc:date>
    </item>
    <item>
      <title>Re: IF then statements re-coding string into numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-then-statements-re-coding-string-into-numeric/m-p/594504#M170814</link>
      <description>&lt;P&gt;Thank you so much! The array did work and it will help me a lot, since I have others to rename.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2019 17:16:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-then-statements-re-coding-string-into-numeric/m-p/594504#M170814</guid>
      <dc:creator>Mscarboncopy</dc:creator>
      <dc:date>2019-10-07T17:16:19Z</dc:date>
    </item>
    <item>
      <title>Re: IF then statements re-coding string into numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-then-statements-re-coding-string-into-numeric/m-p/594505#M170815</link>
      <description>&lt;P&gt;thank you this also works but I think I will do the array because&amp;nbsp; I have others to rename.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2019 17:17:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-then-statements-re-coding-string-into-numeric/m-p/594505#M170815</guid>
      <dc:creator>Mscarboncopy</dc:creator>
      <dc:date>2019-10-07T17:17:34Z</dc:date>
    </item>
    <item>
      <title>Re: IF then statements re-coding string into numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-then-statements-re-coding-string-into-numeric/m-p/594506#M170816</link>
      <description>&lt;P&gt;Thank you. It worked as well.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I went with the array.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2019 17:21:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-then-statements-re-coding-string-into-numeric/m-p/594506#M170816</guid>
      <dc:creator>Mscarboncopy</dc:creator>
      <dc:date>2019-10-07T17:21:21Z</dc:date>
    </item>
    <item>
      <title>Re: IF then statements re-coding string into numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-then-statements-re-coding-string-into-numeric/m-p/594530#M170823</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp; SAS has an operator that will compare a single&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;variable&amp;nbsp;&lt;/STRONG&gt;&lt;SPAN&gt;to a list of values but not one that compares a list of variables to a single value.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;That's what WHICHC and WHICHN are, they look for a value in a list of variables.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2019 19:24:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-then-statements-re-coding-string-into-numeric/m-p/594530#M170823</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-10-07T19:24:21Z</dc:date>
    </item>
  </channel>
</rss>

