<?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 statement in a data step for cleaning data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/if-then-statement-in-a-data-step-for-cleaning-data/m-p/544074#M150439</link>
    <description>&lt;DIV class="sasSource"&gt;if Gender = 'G' then gender 'F';&lt;/DIV&gt;&lt;DIV class="sasError"&gt;______&lt;/DIV&gt;&lt;DIV class="sasError"&gt;180&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 18 Mar 2019 18:41:18 GMT</pubDate>
    <dc:creator>Dublin187</dc:creator>
    <dc:date>2019-03-18T18:41:18Z</dc:date>
    <item>
      <title>if/then statement in a data step for cleaning data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-statement-in-a-data-step-for-cleaning-data/m-p/544065#M150436</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I have a beginner's question : In a given dataset where we need to replace some values with another one, how do we write properly the if then statement in a data step? Or do I need to use another type of statement?&lt;/P&gt;&lt;P&gt;For example I need to update / replace the incorrect values for correct ones, but the log doesn't recognized the 'then' part of the statement when I write the same variable.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if Gender = 'G' then gender  'F' ;
&lt;BR /&gt;&amp;nbsp;if salary =. then salary = 25000;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thank you very much&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2019 18:28:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-statement-in-a-data-step-for-cleaning-data/m-p/544065#M150436</guid>
      <dc:creator>Dublin187</dc:creator>
      <dc:date>2019-03-18T18:28:05Z</dc:date>
    </item>
    <item>
      <title>Re: if/then statement in a data step for cleaning data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-statement-in-a-data-step-for-cleaning-data/m-p/544068#M150437</link>
      <description>&lt;P&gt;Can you post the log and output you are getting plz&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2019 18:33:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-statement-in-a-data-step-for-cleaning-data/m-p/544068#M150437</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-03-18T18:33:46Z</dc:date>
    </item>
    <item>
      <title>Re: if/then statement in a data step for cleaning data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-statement-in-a-data-step-for-cleaning-data/m-p/544074#M150439</link>
      <description>&lt;DIV class="sasSource"&gt;if Gender = 'G' then gender 'F';&lt;/DIV&gt;&lt;DIV class="sasError"&gt;______&lt;/DIV&gt;&lt;DIV class="sasError"&gt;180&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2019 18:41:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-statement-in-a-data-step-for-cleaning-data/m-p/544074#M150439</guid>
      <dc:creator>Dublin187</dc:creator>
      <dc:date>2019-03-18T18:41:18Z</dc:date>
    </item>
    <item>
      <title>Re: if/then statement in a data step for cleaning data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-statement-in-a-data-step-for-cleaning-data/m-p/544075#M150440</link>
      <description>&lt;P&gt;You missed an =&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Correction&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if Gender = 'G' then gender= 'F';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Must have been a typo&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2019 18:42:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-statement-in-a-data-step-for-cleaning-data/m-p/544075#M150440</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-03-18T18:42:38Z</dc:date>
    </item>
    <item>
      <title>Re: if/then statement in a data step for cleaning data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-statement-in-a-data-step-for-cleaning-data/m-p/544080#M150442</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/230631"&gt;@Dublin187&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I have a beginner's question : In a given dataset where we need to replace some values with another one, how do we write properly the if then statement in a data step? Or do I need to use another type of statement?&lt;/P&gt;
&lt;P&gt;For example I need to update / replace the incorrect values for correct ones, but the log doesn't recognized the 'then' part of the statement when I write the same variable.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if Gender = 'G' then gender  'F' ;
&lt;BR /&gt;&amp;nbsp;if salary =. then salary = 25000;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you very much&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Well the first statement is missing the = to do assignment.&lt;/P&gt;
&lt;P&gt;Can you describe what you mean by "&amp;nbsp;but the log doesn't recognized the 'then' part of the statement when I write the same variable.&amp;nbsp;". This sounds like you may be getting a message in the log similar to "invalid data type" or conversion of values. If so, post the code and messages from the Log into a code box opened using the forum's {I} icon to preserve text formatting of messages or notes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another issue may arise if you have been using code similar to:&lt;/P&gt;
&lt;PRE&gt;data have;
    set have;
    if variable='something' then variable='somethingelse';

run;&lt;/PRE&gt;
&lt;P&gt;Using the&amp;nbsp; same dataset as input and output, while syntactically allowed often causes issues with results as it completely replaces the original data set and logic mistakes means that you need to go back to prior steps to use the "correct" data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another issue around character variables is that they have an assigned length. If the original variable is set to have a length of one character and you attempt to do something like:&lt;/P&gt;
&lt;PRE&gt;if gender='F' then gender='female';&lt;/PRE&gt;
&lt;P&gt;the characters past the length of the variable are discarded.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And another possible issue is that you have a numeric variable that has format applied to make it appear character for display. If that were the case then the "if" is likely requesting a comparison using a formatted value when you need to use the underlying numeric. And assigning a character value would fail.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may need to run Proc Contents on your data set and show the result of that step along with the log of the data step.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2019 18:53:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-statement-in-a-data-step-for-cleaning-data/m-p/544080#M150442</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-03-18T18:53:10Z</dc:date>
    </item>
  </channel>
</rss>

