<?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 with index recoding all cases in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/if-then-with-index-recoding-all-cases/m-p/597765#M172264</link>
    <description>&lt;P&gt;And if the conditions are mutually exclusive i.e DTP and OPV cannot occur in the same value&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use ELSE IF&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data want;
set have;
if index(vaccine, 'dtp')&amp;gt;0 then goal=90;
else if index(vaccine, 'opv')&amp;gt;0 then goal=80; 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;/*Or*/&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
if index(vaccine, 'dtp') then goal=90;
else if index(vaccine, 'opv') then goal=80; 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 18 Oct 2019 16:22:04 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2019-10-18T16:22:04Z</dc:date>
    <item>
      <title>if/then with index recoding all cases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-with-index-recoding-all-cases/m-p/597762#M172261</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset that is formatted kind of oddly (but must be in this format to output the way i need it to). Because of that, a simple if/then statement to create a different variable won't do. I have attempted to do a findw and an index of the variable I want to scan for and all that happens is the variable gets overwritten to the last if/then statement. What am I missing (seems fairly simple but i'm missing a piece somewhere). any insight helps. Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want:&lt;/P&gt;&lt;P&gt;vaccine&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mean&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;goal&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;dtp_m_w&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 98&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 90&lt;/P&gt;&lt;P&gt;dtp_m_e&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;76&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;90&lt;/P&gt;&lt;P&gt;opv_m_w&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;56&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 80&lt;/P&gt;&lt;P&gt;opv_m_w&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;75&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 80&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What i'm getting:&lt;/P&gt;&lt;P&gt;vaccine&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mean&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;goal&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;dtp_m_w&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 98&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;80&lt;/P&gt;&lt;P&gt;dtp_m_e&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;76&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 80&lt;/P&gt;&lt;P&gt;opv_m_w&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;56&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 80&lt;/P&gt;&lt;P&gt;opv_m_w&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;75&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 80&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code I've tried:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;set sample;&lt;/P&gt;&lt;P&gt;if index(vaccine, 'dtp') ne "" then do; goal=90; end;&lt;/P&gt;&lt;P&gt;if index(vaccine, 'opv') ne "" then do; goal=80; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i've also tried:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;set sample;&lt;/P&gt;&lt;P&gt;if findw(vaccine, 'dtp') ne "" then goal=90;&lt;/P&gt;&lt;P&gt;if findw(vaccine, 'opv) ne "" then goal=80;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Oct 2019 16:04:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-with-index-recoding-all-cases/m-p/597762#M172261</guid>
      <dc:creator>TPayne</dc:creator>
      <dc:date>2019-10-18T16:04:01Z</dc:date>
    </item>
    <item>
      <title>Re: if/then with index recoding all cases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-with-index-recoding-all-cases/m-p/597764#M172263</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input vaccine  $        mean;*       goal  ;
cards;
dtp_m_w            98           80
dtp_m_e             76          80
opv_m_w           56          80
opv_m_w           75          80
;

data want;
set have;
if index(vaccine, 'dtp')&amp;gt;0 then goal=90;

if index(vaccine, 'opv')&amp;gt;0 then goal=80; 

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;/*Or*/&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
if index(vaccine, 'dtp') then goal=90;
if index(vaccine, 'opv') then goal=80; 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Oct 2019 16:20:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-with-index-recoding-all-cases/m-p/597764#M172263</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-10-18T16:20:49Z</dc:date>
    </item>
    <item>
      <title>Re: if/then with index recoding all cases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-with-index-recoding-all-cases/m-p/597765#M172264</link>
      <description>&lt;P&gt;And if the conditions are mutually exclusive i.e DTP and OPV cannot occur in the same value&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use ELSE IF&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data want;
set have;
if index(vaccine, 'dtp')&amp;gt;0 then goal=90;
else if index(vaccine, 'opv')&amp;gt;0 then goal=80; 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;/*Or*/&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
if index(vaccine, 'dtp') then goal=90;
else if index(vaccine, 'opv') then goal=80; 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Oct 2019 16:22:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-with-index-recoding-all-cases/m-p/597765#M172264</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-10-18T16:22:04Z</dc:date>
    </item>
    <item>
      <title>Re: if/then with index recoding all cases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-with-index-recoding-all-cases/m-p/597805#M172288</link>
      <description>&lt;P&gt;The index function returns a number.&amp;nbsp; It can never return a blank.&amp;nbsp; So your logic using "ne" will always find a match.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Look at the way&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;compared the function results to zero.&amp;nbsp; That's the right comparison.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Oct 2019 18:26:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-with-index-recoding-all-cases/m-p/597805#M172288</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-10-18T18:26:37Z</dc:date>
    </item>
  </channel>
</rss>

