<?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: Rounding issue in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Rounding-issue/m-p/74512#M16041</link>
    <description>Suggest you reply to your post with SAS log output showing code and resulting values of concern.  Also, for your own investigation, a SAS CONTENTS listing may reveal differences in your two files - when SAS files are concatenated / merged, there are specific rules about how like-named SAS variables are treated when it comes to LENGTH, FORMAT, INFORMAT attributes.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
    <pubDate>Sat, 28 Feb 2009 14:26:15 GMT</pubDate>
    <dc:creator>sbb</dc:creator>
    <dc:date>2009-02-28T14:26:15Z</dc:date>
    <item>
      <title>Rounding issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rounding-issue/m-p/74511#M16040</link>
      <description>Hello all,&lt;BR /&gt;
&lt;BR /&gt;
got a little problem here and would be glad to get help.&lt;BR /&gt;
&lt;BR /&gt;
Using a User Written Code in DI Studio I am trying to UNION 2 datasets to filter out duplicate rows.&lt;BR /&gt;
&lt;BR /&gt;
Dataset a has 1 column with informat 12.7/outformat 12.7, so has dataset b.&lt;BR /&gt;
&lt;BR /&gt;
Values are:&lt;BR /&gt;
dataset a      12.1234594999&lt;BR /&gt;
dataset b      12.1234595&lt;BR /&gt;
&lt;BR /&gt;
The value in dataset a is displayed in DI Studio exactly as value b (due to informat/outformat), but once I do not use the usual table view of DI studio, it has all the decimals as written above. So once I do this...&lt;BR /&gt;
&lt;BR /&gt;
SELECT * from a UNION SELECT * from b&lt;BR /&gt;
&lt;BR /&gt;
...the values are identified as NOT duplicate.&lt;BR /&gt;
&lt;BR /&gt;
So there are 2 questions:&lt;BR /&gt;
- Why does the UNION neglect the in/outformat (do I need to specify the format in the UNION again?)&lt;BR /&gt;
- How do I round this (round, roundz?) to fit value b so I can round it before the UNION&lt;BR /&gt;
&lt;BR /&gt;
Any help is appreciated very much.&lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
Thomas</description>
      <pubDate>Wed, 18 Feb 2009 17:59:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rounding-issue/m-p/74511#M16040</guid>
      <dc:creator>ThomasH</dc:creator>
      <dc:date>2009-02-18T17:59:56Z</dc:date>
    </item>
    <item>
      <title>Re: Rounding issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rounding-issue/m-p/74512#M16041</link>
      <description>Suggest you reply to your post with SAS log output showing code and resulting values of concern.  Also, for your own investigation, a SAS CONTENTS listing may reveal differences in your two files - when SAS files are concatenated / merged, there are specific rules about how like-named SAS variables are treated when it comes to LENGTH, FORMAT, INFORMAT attributes.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Sat, 28 Feb 2009 14:26:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rounding-issue/m-p/74512#M16041</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-02-28T14:26:15Z</dc:date>
    </item>
    <item>
      <title>Re: Rounding issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rounding-issue/m-p/74513#M16042</link>
      <description>Hi Thomas&lt;BR /&gt;
&lt;BR /&gt;
Forget about formats when it comes to comparisons. Formats are used only for WRITING data - but calculations/comparisons are always done with the full precision.&lt;BR /&gt;
&lt;BR /&gt;
As this is user written code you can't expect DI Studio to do anything for you. And even if it wasn't user written: DI Studio does nothing else than generate SAS code - so look at the generated SAS code if you want to know what's going on.&lt;BR /&gt;
&lt;BR /&gt;
Seems as rounding the values before the UNION would be a good idea. &lt;BR /&gt;
&lt;BR /&gt;
Why not using a round() function in the select part of the SQL statement?&lt;BR /&gt;
&lt;BR /&gt;
May be that could even be implemented in a standard SQL transform (I would have to try it but I expect it to be possible).&lt;BR /&gt;
&lt;BR /&gt;
Just to show that round() works:&lt;BR /&gt;
data a;&lt;BR /&gt;
  do i=1 to 5;&lt;BR /&gt;
    b=i;&lt;BR /&gt;
    output;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data b;&lt;BR /&gt;
  do i=2,3,5;&lt;BR /&gt;
    b=i*1.00002;&lt;BR /&gt;
    output;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  select *  &lt;BR /&gt;
    from a&lt;BR /&gt;
  union&lt;BR /&gt;
  select i,round(b)&lt;BR /&gt;
    from b&lt;BR /&gt;
  ;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick&lt;BR /&gt;
&lt;BR /&gt;
P.S: I think it's round() you need. Have a look at the SASOnlinedoc to get the exact syntax for the precision you need (it will be something like: &lt;BR /&gt;
round(variable,0.0000001)&lt;BR /&gt;
&lt;BR /&gt;
P.P.S: The question is if the values with lower precision are rounded or truncated. You would want to do the same to the values with higher precision.&lt;BR /&gt;
If it's truncation: Use either a put/input combination or multiply by 10 power the number of digits behind the comma, use int() on the result, divide by 10 power the number of digits behind the comma.</description>
      <pubDate>Sat, 28 Feb 2009 15:00:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rounding-issue/m-p/74513#M16042</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2009-02-28T15:00:04Z</dc:date>
    </item>
  </channel>
</rss>

