<?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: What am I doing wrong in this simplest code? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-in-this-simplest-code/m-p/56391#M12026</link>
    <description>Suggest you use PROC CONTENTS to analyze the SAS variable types, which are either CHARACTER or NUMERIC.  Unless there are user formats being applied, your assignment statement appears to be attempting to relate different variable types -- I would expect some diagnostic messages in your SAS log would be generated and would help you self-diagnose the program and your data.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
    <pubDate>Fri, 12 Feb 2010 14:08:00 GMT</pubDate>
    <dc:creator>sbb</dc:creator>
    <dc:date>2010-02-12T14:08:00Z</dc:date>
    <item>
      <title>What am I doing wrong in this simplest code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-in-this-simplest-code/m-p/56390#M12025</link>
      <description>Hi mates! &lt;BR /&gt;
I came across with this unexpected fact that caused some serious consequences.&lt;BR /&gt;
&lt;BR /&gt;
So, I have a table1:&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;phone_num mob_num&lt;/B&gt;&lt;BR /&gt;
'1' 1&lt;BR /&gt;
'2' 2&lt;BR /&gt;
'3' 3&lt;BR /&gt;
...&lt;BR /&gt;
&lt;BR /&gt;
phone_num has the same value as mob_num. The only difference is that phone_num is a text variable, mob_num is a numeric one. &lt;BR /&gt;
Also I have a table2:&lt;BR /&gt;
&lt;B&gt;phone_num&lt;/B&gt;&lt;BR /&gt;
'4'&lt;BR /&gt;
'5'&lt;BR /&gt;
'6'&lt;BR /&gt;
...&lt;BR /&gt;
&lt;BR /&gt;
My simplest code is:&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;data&lt;/B&gt; table3; &lt;BR /&gt;
set table1 table2;&lt;BR /&gt;
if mob_num = . then mob_num=phone_num;&lt;BR /&gt;
&lt;B&gt;run&lt;/B&gt;;&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;Question&lt;/B&gt;: what should be the result table?&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
I expected to see table3:&lt;BR /&gt;
&lt;B&gt;phone_num mob_num&lt;/B&gt;&lt;BR /&gt;
'1' 1&lt;BR /&gt;
'2' 2&lt;BR /&gt;
'3' 3&lt;BR /&gt;
'4' 4&lt;BR /&gt;
'5' 5&lt;BR /&gt;
'6' 6&lt;BR /&gt;
&lt;BR /&gt;
However, in fact the result appears like this:&lt;BR /&gt;
&lt;B&gt;phone_num mob_num&lt;/B&gt;&lt;BR /&gt;
'1' 1&lt;BR /&gt;
'2' 2&lt;BR /&gt;
'3' 3&lt;BR /&gt;
'4' 4&lt;BR /&gt;
'5' 4&lt;BR /&gt;
'6' 4&lt;BR /&gt;
&lt;BR /&gt;
&lt;U&gt;What am I doing wrong in this simplest code?&lt;/U&gt; &lt;BR /&gt;
I assume that I shouldn't see the expected result, but why there was not any warnings in the log? &lt;BR /&gt;
Peace! &lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;Victor Popovich&lt;/B&gt;&lt;BR /&gt;
MTS, Russia

Message was edited by: Victor_Popovich</description>
      <pubDate>Fri, 12 Feb 2010 13:59:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-in-this-simplest-code/m-p/56390#M12025</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-02-12T13:59:43Z</dc:date>
    </item>
    <item>
      <title>Re: What am I doing wrong in this simplest code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-in-this-simplest-code/m-p/56391#M12026</link>
      <description>Suggest you use PROC CONTENTS to analyze the SAS variable types, which are either CHARACTER or NUMERIC.  Unless there are user formats being applied, your assignment statement appears to be attempting to relate different variable types -- I would expect some diagnostic messages in your SAS log would be generated and would help you self-diagnose the program and your data.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 12 Feb 2010 14:08:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-in-this-simplest-code/m-p/56391#M12026</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-02-12T14:08:00Z</dc:date>
    </item>
    <item>
      <title>Re: What am I doing wrong in this simplest code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-in-this-simplest-code/m-p/56392#M12027</link>
      <description>There aren't any specific formats used. Phone_num has $11. and mob_num has best12. format.&lt;BR /&gt;
&lt;BR /&gt;
I also expected to see something in log, but I didn't. The only statement in log was that some character variable were converted to numeric ones;&lt;BR /&gt;
&lt;BR /&gt;
Is is also important that if I go this way:&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;data&lt;/B&gt; table3; &lt;BR /&gt;
set table1 table2;&lt;BR /&gt;
&lt;B&gt;run&lt;/B&gt;;&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;data&lt;/B&gt; table3;&lt;BR /&gt;
set table3;&lt;BR /&gt;
if mob_num = . then mob_num=phone_num;&lt;BR /&gt;
&lt;B&gt;run&lt;/B&gt;;&lt;BR /&gt;
&lt;BR /&gt;
I will see exactly what I needed!</description>
      <pubDate>Fri, 12 Feb 2010 14:18:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-in-this-simplest-code/m-p/56392#M12027</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-02-12T14:18:36Z</dc:date>
    </item>
    <item>
      <title>Re: What am I doing wrong in this simplest code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-in-this-simplest-code/m-p/56393#M12028</link>
      <description>For consideration, the values are not equal.  You will need to consider extracting the numeric portion of the character-type variable, using SAS DATA step functions like SCAN, SUBSTR, STRIP, and then use the INPUT function to convert the character result to numeric.  Then you can effectively compare values.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 12 Feb 2010 14:27:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-in-this-simplest-code/m-p/56393#M12028</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-02-12T14:27:54Z</dc:date>
    </item>
    <item>
      <title>Re: What am I doing wrong in this simplest code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-in-this-simplest-code/m-p/56394#M12029</link>
      <description>It is not about how to compare variables, it is about why '4' is placed to the every next observation?</description>
      <pubDate>Fri, 12 Feb 2010 14:43:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-in-this-simplest-code/m-p/56394#M12029</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-02-12T14:43:22Z</dc:date>
    </item>
    <item>
      <title>Re: What am I doing wrong in this simplest code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-in-this-simplest-code/m-p/56395#M12030</link>
      <description>Okay - sounds like you want to do a MERGE with a BY statement instead of a SET.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 12 Feb 2010 14:47:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-in-this-simplest-code/m-p/56395#M12030</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-02-12T14:47:47Z</dc:date>
    </item>
    <item>
      <title>Re: What am I doing wrong in this simplest code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-in-this-simplest-code/m-p/56396#M12031</link>
      <description>Victor,&lt;BR /&gt;
&lt;BR /&gt;
The behavior you saw has to do with the way SAS retains values in a SET with different variables in the two datasets.  I've seen it documented (long ago), but couldn't find it in a cursory search of the 9.2 online docs.  If you add the one line with the comment to table 2, you get the expected results.&lt;BR /&gt;
&lt;BR /&gt;
Doc Muhlbaier&lt;BR /&gt;
Duke&lt;BR /&gt;
--------------------&lt;BR /&gt;
DATA table1; &lt;BR /&gt;
LENGTH Phone_Num $10 Mob_Num 8;&lt;BR /&gt;
input phone_num mob_num;&lt;BR /&gt;
cards;&lt;BR /&gt;
1 1&lt;BR /&gt;
2 2&lt;BR /&gt;
3 3&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
DATA table2;&lt;BR /&gt;
LENGTH Phone_Num $10;&lt;BR /&gt;
INPUT phone_num;&lt;BR /&gt;
mob_num=.;              * &amp;lt;--- add this statement to get desired behavior;&lt;BR /&gt;
cards;&lt;BR /&gt;
4&lt;BR /&gt;
5&lt;BR /&gt;
6&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
data table3;&lt;BR /&gt;
set table1 table2;&lt;BR /&gt;
if mob_num = . then mob_num=phone_num;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
PROC PRINT;  RUN;

You also get the desired result if you sort table1 and table2 by Phone_num and add a BY Phone_Num; statement to the third data step;&lt;BR /&gt;
&lt;BR /&gt;
    &lt;BR /&gt;
Message was edited by: Doc@Duke</description>
      <pubDate>Fri, 12 Feb 2010 16:11:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-in-this-simplest-code/m-p/56396#M12031</guid>
      <dc:creator>Doc_Duke</dc:creator>
      <dc:date>2010-02-12T16:11:39Z</dc:date>
    </item>
    <item>
      <title>Re: What am I doing wrong in this simplest code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-in-this-simplest-code/m-p/56397#M12032</link>
      <description>Very useful DOC reference below:&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a001292604.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a001292604.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
Recommended Google advanced search argument this topic/post:&lt;BR /&gt;
&lt;BR /&gt;
data step processing missing values site:sas.com</description>
      <pubDate>Fri, 12 Feb 2010 17:00:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-in-this-simplest-code/m-p/56397#M12032</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-02-12T17:00:50Z</dc:date>
    </item>
    <item>
      <title>Re: What am I doing wrong in this simplest code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-in-this-simplest-code/m-p/56398#M12033</link>
      <description>Thanks, Scott.  Here is the line I was looking for.&lt;BR /&gt;
&lt;BR /&gt;
"When Reading a SAS Data Set&lt;BR /&gt;
&lt;BR /&gt;
When variables are read with a SET, MERGE, or UPDATE statement, SAS sets the values to missing only before the first iteration of the DATA step. (If you use a BY statement, the variable values are also set to missing when the BY group changes.) The variables retain their values until new values become available;..."</description>
      <pubDate>Fri, 12 Feb 2010 17:24:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-am-I-doing-wrong-in-this-simplest-code/m-p/56398#M12033</guid>
      <dc:creator>Doc_Duke</dc:creator>
      <dc:date>2010-02-12T17:24:08Z</dc:date>
    </item>
  </channel>
</rss>

