<?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 THEN STATEMENT in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-STATEMENT/m-p/871558#M344308</link>
    <description>&lt;P&gt;Hi there,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two variables in my dataset that have similar information, but some times the values are not consistent. I am trying to write an if then statement&amp;nbsp; where if one of the two variables has a value of interest, then both variables should have the same consistent value. I have included a sample code below.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&amp;nbsp;&lt;/P&gt;&lt;P&gt;set want;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if var1="Apples" or var2= "Apples"&lt;/P&gt;&lt;P&gt;then var1="Apples" and var2="Apples";&amp;nbsp;&lt;/P&gt;&lt;P&gt;run;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I attempted the above code, I have "0" populated for var2, and I am unsure why this is occurring. When&amp;nbsp;I make the following correction to my code (below), it does what I want the code to do.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&amp;nbsp;&lt;/P&gt;&lt;P&gt;set want;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if var1="Apples"&lt;/P&gt;&lt;P&gt;then var2="Apples";&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if var2="Apples"&amp;nbsp;&lt;/P&gt;&lt;P&gt;then var1="Apples"&amp;nbsp;&lt;/P&gt;&lt;P&gt;run;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Though my second code worked, it is longer and I am wondering why my initial code didn't work. Does anyone have any insight on why this is occurring?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 24 Apr 2023 12:37:28 GMT</pubDate>
    <dc:creator>jnivi</dc:creator>
    <dc:date>2023-04-24T12:37:28Z</dc:date>
    <item>
      <title>IF THEN STATEMENT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-STATEMENT/m-p/871558#M344308</link>
      <description>&lt;P&gt;Hi there,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two variables in my dataset that have similar information, but some times the values are not consistent. I am trying to write an if then statement&amp;nbsp; where if one of the two variables has a value of interest, then both variables should have the same consistent value. I have included a sample code below.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&amp;nbsp;&lt;/P&gt;&lt;P&gt;set want;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if var1="Apples" or var2= "Apples"&lt;/P&gt;&lt;P&gt;then var1="Apples" and var2="Apples";&amp;nbsp;&lt;/P&gt;&lt;P&gt;run;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I attempted the above code, I have "0" populated for var2, and I am unsure why this is occurring. When&amp;nbsp;I make the following correction to my code (below), it does what I want the code to do.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&amp;nbsp;&lt;/P&gt;&lt;P&gt;set want;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if var1="Apples"&lt;/P&gt;&lt;P&gt;then var2="Apples";&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if var2="Apples"&amp;nbsp;&lt;/P&gt;&lt;P&gt;then var1="Apples"&amp;nbsp;&lt;/P&gt;&lt;P&gt;run;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Though my second code worked, it is longer and I am wondering why my initial code didn't work. Does anyone have any insight on why this is occurring?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2023 12:37:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-STATEMENT/m-p/871558#M344308</guid>
      <dc:creator>jnivi</dc:creator>
      <dc:date>2023-04-24T12:37:28Z</dc:date>
    </item>
    <item>
      <title>Re: IF THEN STATEMENT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-STATEMENT/m-p/871560#M344310</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/439729"&gt;@jnivi&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;set want;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if var1="Apples" or var2= "Apples"&lt;/P&gt;
&lt;P&gt;then var1="Apples" and var2="Apples";&amp;nbsp;&lt;/P&gt;
&lt;P&gt;run;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This code, although valid SAS code, does not do what you want. The IF part tests to see if var1='Apples' OR var2='Apples' and THEN assigns a value to VAR1. It does not assign values to VAR1 and VAR2, as your second code does.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;What value does it assign to VAR1? It is the result of the operation to the right of the first equal sign: &lt;FONT face="courier new,courier"&gt;"Apples" and var2="Apples"&lt;/FONT&gt;, which is a Boolean operation resulting in a value of either 0 or 1.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2023 12:48:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-STATEMENT/m-p/871560#M344310</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-04-24T12:48:59Z</dc:date>
    </item>
    <item>
      <title>Re: IF THEN STATEMENT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-STATEMENT/m-p/871569#M344316</link>
      <description>&lt;P&gt;You need to use the DO BOCK with IF/THEN statement to assign values in multiple variables.&lt;/P&gt;
&lt;P&gt;Eg:&lt;/P&gt;
&lt;PRE&gt;data want; &lt;BR /&gt;set have;&lt;BR /&gt;if var1="Apples" or var2= "Apples" then do;&lt;BR /&gt;var1="Apples";&lt;BR /&gt;var2="Apples"; &lt;BR /&gt;end;&lt;BR /&gt;run; &lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Apr 2023 17:38:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-STATEMENT/m-p/871569#M344316</guid>
      <dc:creator>A_Kh</dc:creator>
      <dc:date>2023-04-24T17:38:51Z</dc:date>
    </item>
    <item>
      <title>Re: IF THEN STATEMENT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-STATEMENT/m-p/871642#M344368</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/321371"&gt;@A_Kh&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;You need to use the DO BOCK with IF/THEN statement to assign values in multiple variables.&lt;/P&gt;
&lt;P&gt;Eg:&lt;/P&gt;
&lt;PRE&gt;data have; &lt;BR /&gt;if var1="Apples" or var2= "Apples" then do;&lt;BR /&gt;var1="Apples";&lt;BR /&gt;var2="Apples"; &lt;BR /&gt;end;&lt;BR /&gt;run; &lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Don't forget the SET statement. Otherwise there are no variable values.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2023 15:41:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-STATEMENT/m-p/871642#M344368</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-04-24T15:41:51Z</dc:date>
    </item>
    <item>
      <title>Re: IF THEN STATEMENT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-STATEMENT/m-p/873766#M345221</link>
      <description>&lt;P&gt;Thank you so much!! This worked !!&lt;/P&gt;</description>
      <pubDate>Thu, 04 May 2023 02:10:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-STATEMENT/m-p/873766#M345221</guid>
      <dc:creator>jnivi</dc:creator>
      <dc:date>2023-05-04T02:10:52Z</dc:date>
    </item>
  </channel>
</rss>

