<?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: When We Put Period Why If Statement Changes Whole Values If the Variable Has Character Type in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/When-We-Put-Period-Why-If-Statement-Changes-Whole-Values-If-the/m-p/276216#M55324</link>
    <description>&lt;P&gt;The dot denotes the default MISSING value for numeric variables only. With character variables, the dot is simpy a 1-byte string containing the dot.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The log of your second data step is very verbose about your mistake:&lt;/P&gt;
&lt;PRE&gt;23         Data Want;
24         Set Have;
25         If Variable=. Then Value=1600;
26         Run;

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
      25:4   
NOTE: Invalid numeric data, Variable='Istanbul' , at line 25 column 4.
Variable=Istanbul Value=1600 _ERROR_=1 _N_=2
NOTE: Invalid numeric data, Variable='Istanbul' , at line 25 column 4.
Variable=Istanbul Value=1600 _ERROR_=1 _N_=3
NOTE: There were 4 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.WANT has 4 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.00 seconds
&lt;/PRE&gt;
&lt;P&gt;SAS tries to convert your Variable to numeric, fails in observations 2 and 3, which causes a missing numeric value, represented by the dot; therefore the condition is also true. In observation 1 and 4, the empty string is correctly converted to a missing value, causing the same result, but without ERROR.&lt;/P&gt;</description>
    <pubDate>Thu, 09 Jun 2016 10:37:18 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2016-06-09T10:37:18Z</dc:date>
    <item>
      <title>When We Put Period Why If Statement Changes Whole Values If the Variable Has Character Type</title>
      <link>https://communities.sas.com/t5/SAS-Programming/When-We-Put-Period-Why-If-Statement-Changes-Whole-Values-If-the/m-p/276210#M55322</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have&amp;nbsp;a&amp;nbsp;sample code as below, which includes if statements . As we know, if the variable has character type we need to put " " after if statement, if it has numeric type&amp;nbsp;we need to put .(period) after if statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For character type variable, In the following code, "if "statement works fine when I put " " in the if statement. However, if I put .(period) in the "if" statement ,it changes the whole values .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to understand&amp;nbsp;the reason why .(period) changes the all values if variable is character&amp;nbsp;type.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm asking this question because I pull the whole if statements from SQL and this variables can be numeric type or character type, if I replace&amp;nbsp;whole .(period) values with " " then some of my character type will be affected wrong.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is my sample code;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Have;
Length Variable $ 20 Value 8;
Infile Datalines Missover;
Input Variable Value;
Datalines;
. 1000
Istanbul 1000
Istanbul 1000
. 1000
;
Run;

Data Want;
Set Have;
If Variable=" " Then Value=1600;
Run;
/*Change Whole Values*/
Data Want;
Set Have;
If Variable=. Then Value=1600;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;May I have breif information, please?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jun 2016 10:20:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/When-We-Put-Period-Why-If-Statement-Changes-Whole-Values-If-the/m-p/276210#M55322</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-06-09T10:20:07Z</dc:date>
    </item>
    <item>
      <title>Re: When We Put Period Why If Statement Changes Whole Values If the Variable Has Character Type</title>
      <link>https://communities.sas.com/t5/SAS-Programming/When-We-Put-Period-Why-If-Statement-Changes-Whole-Values-If-the/m-p/276215#M55323</link>
      <description>&lt;P&gt;It is because you are mixing types. &amp;nbsp;Your first datastep:&lt;/P&gt;
&lt;PRE&gt;data have;
  length variable $ 20 value 8;
  infile datalines missover;
  input variable value;
datalines;
. 1000
Istanbul 1000
Istanbul 1000
. 1000
;
Run;&lt;/PRE&gt;
&lt;P&gt;Creates a dataset with 1 character datatype and one numeric datatype. &amp;nbsp;The "." when read in becomes "" as that is the empty character equivalent.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The your next datastep:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  if variable="" then value=1600;
  /* or: if missing(variable) then... */
run;&lt;/PRE&gt;
&lt;P&gt;I checking is the character string in variable equal to the character string on the right of the =. &amp;nbsp;You can use no space, a space, or the missing function they all do the same thing. &amp;nbsp;This works as ""="" then 1600, but "Istanbul"="" not true. &amp;nbsp;This is fine logic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your next datastep:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  if variable=. then value=1600;
run;&lt;/PRE&gt;
&lt;P&gt;Is invalid code. &amp;nbsp;What is happening is that at the if statement it is looking at the logic, = numeric value, and that to the left is a character string. &amp;nbsp;So it starts to implicitly convert your string into numeric, however "Istanbul" cannot be a number, so gets set to . or missing. &amp;nbsp;Therefore, all rows equate to missing empty=missing, and "Istanbul" cannot convert so missing. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;Its a good example of why you should always explicitly convert datatypes - know your data, program for your data.&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jun 2016 10:34:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/When-We-Put-Period-Why-If-Statement-Changes-Whole-Values-If-the/m-p/276215#M55323</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-06-09T10:34:38Z</dc:date>
    </item>
    <item>
      <title>Re: When We Put Period Why If Statement Changes Whole Values If the Variable Has Character Type</title>
      <link>https://communities.sas.com/t5/SAS-Programming/When-We-Put-Period-Why-If-Statement-Changes-Whole-Values-If-the/m-p/276216#M55324</link>
      <description>&lt;P&gt;The dot denotes the default MISSING value for numeric variables only. With character variables, the dot is simpy a 1-byte string containing the dot.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The log of your second data step is very verbose about your mistake:&lt;/P&gt;
&lt;PRE&gt;23         Data Want;
24         Set Have;
25         If Variable=. Then Value=1600;
26         Run;

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
      25:4   
NOTE: Invalid numeric data, Variable='Istanbul' , at line 25 column 4.
Variable=Istanbul Value=1600 _ERROR_=1 _N_=2
NOTE: Invalid numeric data, Variable='Istanbul' , at line 25 column 4.
Variable=Istanbul Value=1600 _ERROR_=1 _N_=3
NOTE: There were 4 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.WANT has 4 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.00 seconds
&lt;/PRE&gt;
&lt;P&gt;SAS tries to convert your Variable to numeric, fails in observations 2 and 3, which causes a missing numeric value, represented by the dot; therefore the condition is also true. In observation 1 and 4, the empty string is correctly converted to a missing value, causing the same result, but without ERROR.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jun 2016 10:37:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/When-We-Put-Period-Why-If-Statement-Changes-Whole-Values-If-the/m-p/276216#M55324</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-06-09T10:37:18Z</dc:date>
    </item>
  </channel>
</rss>

