<?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: Convert num into value with less decimals in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-num-into-value-with-less-decimals/m-p/782872#M249574</link>
    <description>&lt;P&gt;If "someone else" is going to work with the data in Excel, you don't need formatting at all. Just have SAS send them the unformatted numbers and let them do calculation and format the results to their liking.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, rounding the data and then giving the results to someone else to do additional calculations is not a good idea. Rounding causes loss of precision! The rule is to round only as the last step; you never round as an intermediate step.&lt;/P&gt;</description>
    <pubDate>Mon, 29 Nov 2021 11:07:30 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-11-29T11:07:30Z</dc:date>
    <item>
      <title>Convert num into value with less decimals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-num-into-value-with-less-decimals/m-p/782426#M249423</link>
      <description>&lt;P&gt;Hallo forum,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to convert a numeric value with dots into a value with comma and only six decimals (num or char). All missing cells shall get a minus ("-").&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="201px"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="113.35px" height="30px"&gt;&lt;STRONG&gt;v1_have&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="95.55px" height="30px"&gt;&lt;STRONG&gt;v1_want&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="113.35px" height="30px"&gt;137.10254134&lt;/TD&gt;
&lt;TD width="95.55px" height="30px"&gt;137,102541&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="113.35px" height="30px"&gt;11.761354987&lt;/TD&gt;
&lt;TD width="95.55px" height="30px"&gt;11,761354&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="113.35px" height="30px"&gt;.&lt;/TD&gt;
&lt;TD width="95.55px" height="30px"&gt;-&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="113.35px" height="30px"&gt;.&lt;/TD&gt;
&lt;TD width="95.55px" height="30px"&gt;-&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="113.35px" height="30px"&gt;.&lt;/TD&gt;
&lt;TD width="95.55px" height="30px"&gt;-&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="113.35px" height="30px"&gt;11.761354987&lt;/TD&gt;
&lt;TD width="95.55px" height="30px"&gt;11,761354&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="113.35px" height="30px"&gt;125.25814946&lt;/TD&gt;
&lt;TD width="95.55px" height="30px"&gt;125,258149&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="113.35px" height="30px"&gt;0.083036885&lt;/TD&gt;
&lt;TD width="95.55px" height="30px"&gt;0,083036&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I thought, its pretty easy. But I just cant get it to work. I tried it for example with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
format v1_want commax20.6;
v1_want=substr(v1_have,1,find(v1_have,".")+6);
if missing(v1_have) then v1_want="-";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you help me? &lt;STRONG&gt;Thank you!&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Nov 2021 12:19:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-num-into-value-with-less-decimals/m-p/782426#M249423</guid>
      <dc:creator>Konkordanz</dc:creator>
      <dc:date>2021-11-25T12:19:35Z</dc:date>
    </item>
    <item>
      <title>Re: Convert num into value with less decimals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-num-into-value-with-less-decimals/m-p/782433#M249428</link>
      <description>&lt;P&gt;Is your question that you want to change the appearance of the data, while leaving the underlying data with more than six decimal places unchanged?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or is your question how to round the actual numbers to 6 decimal places?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;These two are not the same and should not be confused with one another.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the reason you want to do this? To show the numbers in a report? To do additional calculations with the data? Something else?&lt;/P&gt;</description>
      <pubDate>Thu, 25 Nov 2021 12:44:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-num-into-value-with-less-decimals/m-p/782433#M249428</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-11-25T12:44:00Z</dc:date>
    </item>
    <item>
      <title>Re: Convert num into value with less decimals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-num-into-value-with-less-decimals/m-p/782467#M249440</link>
      <description>&lt;P&gt;The SUBSTR() function requires CHARACTER string input.&amp;nbsp; You cannot use it with a number without first converting the number into a string.&amp;nbsp; If you don't make the conversion then SAS will and it will use the BEST12. format when making the conversion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you just want to DISPLAY the number with a fixed number of decimal places then use a FORMAT.&amp;nbsp; Either attach the format to the new variable in the new dataset.&amp;nbsp; Or use a FORMAT statement in the procedure that you are using that is going to display the number.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  v1_want=v1_have;
  format v1_want commax20.6;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to reduce the precision of the number then use something like ROUND().&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  v1_want=round(v1_have,0.000001);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want the missing value to display as - instead of . then you could change the MISSING option.&amp;nbsp; But that would apply to ALL missing values, not just those in V1_WANT.&lt;/P&gt;
&lt;P&gt;If you want you could create a custom format to display V1_WANT as '-' then missing and using COMMAX format otherwise.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format ;
  value myfmt .='-' other=[commax20.6];
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you could make V1_WANT be a character string instead of a number.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  length v1_want $20 ;
  if v1_have=. then v1_want='-';
  else v1_want=put(v1_have,commax20.6);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Nov 2021 17:54:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-num-into-value-with-less-decimals/m-p/782467#M249440</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-11-25T17:54:56Z</dc:date>
    </item>
    <item>
      <title>Re: Convert num into value with less decimals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-num-into-value-with-less-decimals/m-p/782871#M249573</link>
      <description>&lt;P&gt;Thank you for your help!&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/10892"&gt;@PaigeMiller&lt;/a&gt; &lt;EM&gt;What is the reason you want to do this? To show the numbers in a report? To do additional calculations with the data? Something else?&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Yeah, i want to built a table for someone else, they work with it and calculate with the data in excel.&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/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The proc-format-step works within SAS. &lt;STRONG&gt;But:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;This format doesnt retain when I export my table into a excel-file. I tried several ways. Proc-print and proc-Report - it needs a lot of time because of my huge dataset (~44.000*13 cells); seems not practical. Furthermore Excel shows an error when I download the excel-file with SAS. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a better way to get the formatted table into an excel-sheet?&lt;/P&gt;</description>
      <pubDate>Mon, 29 Nov 2021 10:58:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-num-into-value-with-less-decimals/m-p/782871#M249573</guid>
      <dc:creator>Konkordanz</dc:creator>
      <dc:date>2021-11-29T10:58:33Z</dc:date>
    </item>
    <item>
      <title>Re: Convert num into value with less decimals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-num-into-value-with-less-decimals/m-p/782872#M249574</link>
      <description>&lt;P&gt;If "someone else" is going to work with the data in Excel, you don't need formatting at all. Just have SAS send them the unformatted numbers and let them do calculation and format the results to their liking.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, rounding the data and then giving the results to someone else to do additional calculations is not a good idea. Rounding causes loss of precision! The rule is to round only as the last step; you never round as an intermediate step.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Nov 2021 11:07:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-num-into-value-with-less-decimals/m-p/782872#M249574</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-11-29T11:07:30Z</dc:date>
    </item>
    <item>
      <title>Re: Convert num into value with less decimals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-num-into-value-with-less-decimals/m-p/782873#M249575</link>
      <description>&lt;P&gt;PaigeMiller, actually right. But I have to check, if my created table matches the patterntable. The patterntable has the format, I asked for.&lt;/P&gt;
&lt;P&gt;And: I want to learn SAS and just want to find a solution for my Problem ;)...&lt;/P&gt;</description>
      <pubDate>Mon, 29 Nov 2021 11:08:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-num-into-value-with-less-decimals/m-p/782873#M249575</guid>
      <dc:creator>Konkordanz</dc:creator>
      <dc:date>2021-11-29T11:08:56Z</dc:date>
    </item>
    <item>
      <title>Re: Convert num into value with less decimals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-num-into-value-with-less-decimals/m-p/782875#M249577</link>
      <description>&lt;P&gt;So, my question is:&lt;/P&gt;
&lt;P&gt;I formatted my dataset with the proc-format-command. Afterwards I created the final table with an proc-sql-command. How can I export this into a excel-sheet with the same formats?&lt;/P&gt;</description>
      <pubDate>Mon, 29 Nov 2021 11:32:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-num-into-value-with-less-decimals/m-p/782875#M249577</guid>
      <dc:creator>Konkordanz</dc:creator>
      <dc:date>2021-11-29T11:32:45Z</dc:date>
    </item>
  </channel>
</rss>

