<?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: Strange result when exporting to SPSS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Strange-result-when-exporting-to-SPSS/m-p/434950#M281954</link>
    <description>&lt;P&gt;Other programming languages, not just SAS, have the concept of -0 (a little mind bending when you think about it).&amp;nbsp; The representation difference is the sign bit, but SAS (as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;says) treats the two values as equal -- as do most other programming languages.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've written about this here: &lt;A href="https://blogs.sas.com/content/sasdummy/2011/12/14/all-about-negative-zero/" target="_self"&gt;What's the difference between 0 and -0?&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 07 Feb 2018 16:34:13 GMT</pubDate>
    <dc:creator>ChrisHemedinger</dc:creator>
    <dc:date>2018-02-07T16:34:13Z</dc:date>
    <item>
      <title>Strange result when exporting to SPSS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Strange-result-when-exporting-to-SPSS/m-p/434536#M281949</link>
      <description>&lt;P&gt;I've got a derived variable in a dataset called AGE_DECADE defined as&amp;nbsp;length=3 format=3.&lt;/P&gt;&lt;P&gt;This variable is created from a another variable called AGE with this code:&lt;/P&gt;&lt;P&gt;AGE_DECADE=10*int(AGE/10);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So&lt;/P&gt;&lt;P&gt;if AGE is between 0 and 9 then AGE_DECADE is set to 0.&lt;/P&gt;&lt;P&gt;if AGE is between 10 and 19 then AGE_DECADE is set to 10&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if AGE is between 20 and 29 then AGE_DECADE is set to 20&amp;nbsp;&lt;/SPAN&gt;and so on...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I export this dataset to SPSS using proc export (dbms=sav) and then do a simple frequency count on AGE_DECADE I get two rows with AGE_DECADE=0!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my case I get 14 instances of&amp;nbsp;&lt;SPAN&gt;AGE_DECADE=0 and also 40 instances of&amp;nbsp;AGE_DECADE=0.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I've increased the number of decimals in SPSS but there is no difference between the two that I can see.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;A frequency count in SAS results correctly in 54 instances of&amp;nbsp;AGE_DECADE=0.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;When I check the age variable there are 14 with AGE=0 and the other 40 rows have&amp;nbsp;AGE between 1 and 9.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;So somehow "10*int(AGE/10)" results in one type of zero if AGE=0 and a different type of zero if AGE=1-9.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Could someone explain this to me?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;By the way, I solved the problem by:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if&amp;nbsp;AGE &amp;gt;= 0 and&amp;nbsp;AGE &amp;lt;= 9 then AGE_DECADE=0;&lt;BR /&gt;else if&amp;nbsp;AGE ne . then AGE_DECADE=10*int(d_age/10);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This works (I get only one frequency count for AGE_DECADE in SPSS) but I'd really like to know whats going on...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2018 14:11:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Strange-result-when-exporting-to-SPSS/m-p/434536#M281949</guid>
      <dc:creator>andypandy_swe</dc:creator>
      <dc:date>2018-02-06T14:11:27Z</dc:date>
    </item>
    <item>
      <title>Re: Strange result when exporting to SPSS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Strange-result-when-exporting-to-SPSS/m-p/434558#M281950</link>
      <description>&lt;P&gt;Interesting question! Actually, in this case, SAS is treating them the same, while SPSS is correctly (IMHO) treating zero values differently. Possibly someone from SAS Institute can chime in with an explanation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Run the following and look at the results of the proc freq:&lt;/P&gt;
&lt;PRE&gt;data have;
  input dob date9.;
  if _n_ eq 2 then age=0;
  else age=yrdif(dob,today());
  AGE_DECADE=10*int(AGE/10);
  hage_decade=put(AGE_DECADE,hex16.);
  cards;
4apr2007
.
4apr2008
4apr2009
4apr2010
4apr2011
4apr2012
4apr2013
4apr2014
4apr2015
4apr2016
4apr2017
;
proc freq data=have;
  tables age_decade hage_decade;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2018 15:06:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Strange-result-when-exporting-to-SPSS/m-p/434558#M281950</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-02-06T15:06:12Z</dc:date>
    </item>
    <item>
      <title>Re: Strange result when exporting to SPSS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Strange-result-when-exporting-to-SPSS/m-p/434708#M281951</link>
      <description>Curious as to why you would say that SPSS treats the zeroes correctly? I guess as a developer (and not a statistician) I feel it is obvious that the intention of the code is to bin the age into decade containers... Why would a zero not bin into zero when a ten bins into 1 and twenty into 2?&lt;BR /&gt;&lt;BR /&gt;I’ve got a feeling I’m about to get schooled but I really want to know &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 06 Feb 2018 21:59:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Strange-result-when-exporting-to-SPSS/m-p/434708#M281951</guid>
      <dc:creator>andypandy_swe</dc:creator>
      <dc:date>2018-02-06T21:59:51Z</dc:date>
    </item>
    <item>
      <title>Re: Strange result when exporting to SPSS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Strange-result-when-exporting-to-SPSS/m-p/434729#M281952</link>
      <description>&lt;P&gt;As neither a developer, mathematician or statistician, my explanation could be totally wrong, which is why I was hoping that a developer from SAS Institute would have chimed in.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4"&gt;@ChrisHemedinger&lt;/a&gt;: Know anyone who could address this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, that said, I have spent numerous hours getting SAS to perform as expected when numeric precision showed its ugly head. Interestingly, in this case, SAS is ignoring the fuzz factor without being told to do so.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are the calculations "precisely" the same, given your formula [i.e.,AGE_DECADE=10*int(AGE/10)&amp;nbsp;] when age is 0 and age is between 1 and 10. The answer is no if you are considering a number represented in 32 bits.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you will get the same answers in SAS and SPSS if you use the formula:&lt;/P&gt;
&lt;PRE&gt;AGE_DECADE=fuzz(10*int(AGE/10))&lt;/PRE&gt;
&lt;P&gt;I'm just surprised that SAS ignores the difference in this case when the values are clearly different when viewed in Hex16. format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2018 23:31:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Strange-result-when-exporting-to-SPSS/m-p/434729#M281952</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-02-06T23:31:55Z</dc:date>
    </item>
    <item>
      <title>Re: Strange result when exporting to SPSS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Strange-result-when-exporting-to-SPSS/m-p/434736#M281953</link>
      <description>&lt;P&gt;The first bit, which differs as shown by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13711"&gt;@art297&lt;/a&gt;&amp;nbsp;, is the sign bit (see&amp;nbsp;&lt;A href="http://support.sas.com/kb/31/437.html" target="_blank"&gt;http://support.sas.com/kb/31/437.html&lt;/A&gt;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So&amp;nbsp; &amp;nbsp;&lt;FONT face="courier new,courier"&gt;10*int(AGE/10)&lt;/FONT&gt;&amp;nbsp;returns -0 for some (probably precision) reason.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are several ways to obtain a +0 result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE;
  AGE=0;
  AGE_DECADE1=      10*int(AGE/10)      ;
  AGE_DECADE2=round(10*int(AGE/10) )    ;
  AGE_DECADE3=      10*int(AGE/10) -0   ;
  AGE_DECADE4=      10*int(AGE/10) +1-1 ;
  AGE_DECADE5=      10*int(AGE/10) *1   ;
  AGE_DECADE6=      10*int(AGE/10) *2/2 ;
  AGE_DECADE7=abs(  10*int(AGE/10) )    ;
  format _ALL_ binary64.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;yields:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="595"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="104"&gt;AGE_DECADE1&lt;/TD&gt;
&lt;TD width="491"&gt;1000000000000000000000000000000000000000000000000000000000000000&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;AGE_DECADE2&lt;/TD&gt;
&lt;TD&gt;0000000000000000000000000000000000000000000000000000000000000000&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;AGE_DECADE3&lt;/TD&gt;
&lt;TD&gt;1000000000000000000000000000000000000000000000000000000000000000&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;AGE_DECADE4&lt;/TD&gt;
&lt;TD&gt;0000000000000000000000000000000000000000000000000000000000000000&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;AGE_DECADE5&lt;/TD&gt;
&lt;TD&gt;1000000000000000000000000000000000000000000000000000000000000000&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;AGE_DECADE6&lt;/TD&gt;
&lt;TD&gt;1000000000000000000000000000000000000000000000000000000000000000&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;AGE_DECADE7&lt;/TD&gt;
&lt;TD&gt;0000000000000000000000000000000000000000000000000000000000000000&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS does not differentiate between +0 and -0 so proc freq or proc compare (see below) group them together.&lt;/P&gt;
&lt;P&gt;SPSS treats the 2 values as different.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc compare data=HAVE compare=HAVE(keep=AGE_DECADE1 rename=(AGE_DECADE1=AGE)); run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;NOTE: No unequal values were found. All values compared are exactly equal.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since SAS does not differentiate ( and in this case gets it wrong: there is no reason the result should be negative here), I would argue that SAS should never store the value -0 in its data sets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 01:28:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Strange-result-when-exporting-to-SPSS/m-p/434736#M281953</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-02-07T01:28:27Z</dc:date>
    </item>
    <item>
      <title>Re: Strange result when exporting to SPSS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Strange-result-when-exporting-to-SPSS/m-p/434950#M281954</link>
      <description>&lt;P&gt;Other programming languages, not just SAS, have the concept of -0 (a little mind bending when you think about it).&amp;nbsp; The representation difference is the sign bit, but SAS (as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;says) treats the two values as equal -- as do most other programming languages.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've written about this here: &lt;A href="https://blogs.sas.com/content/sasdummy/2011/12/14/all-about-negative-zero/" target="_self"&gt;What's the difference between 0 and -0?&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 16:34:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Strange-result-when-exporting-to-SPSS/m-p/434950#M281954</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2018-02-07T16:34:13Z</dc:date>
    </item>
    <item>
      <title>Re: Strange result when exporting to SPSS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Strange-result-when-exporting-to-SPSS/m-p/434959#M281955</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4"&gt;@ChrisHemedinger&lt;/a&gt;!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Usually learn something new every day but, today, guess that's -nothing!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/141876"&gt;@andypandy_swe&lt;/a&gt;: So, like I said before, use:&lt;/P&gt;
&lt;PRE&gt;AGE_DECADE=fuzz(10*int(AGE/10));&lt;/PRE&gt;
&lt;P&gt;in your SAS code (before exporting the file), then you'll get the same results in both SAS and SPSS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 17:14:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Strange-result-when-exporting-to-SPSS/m-p/434959#M281955</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-02-07T17:14:52Z</dc:date>
    </item>
    <item>
      <title>Re: Strange result when exporting to SPSS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Strange-result-when-exporting-to-SPSS/m-p/435062#M281956</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13711"&gt;@art297&lt;/a&gt;&amp;nbsp;lol -nothing ! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 20:55:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Strange-result-when-exporting-to-SPSS/m-p/435062#M281956</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-02-07T20:55:56Z</dc:date>
    </item>
  </channel>
</rss>

