<?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: saving file with different decimal places, and rounding in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/saving-file-with-different-decimal-places-and-rounding/m-p/848206#M335345</link>
    <description>As you say, I may have to format the decimal place in the programming part that's about the presentation. Okay, thanks.</description>
    <pubDate>Tue, 06 Dec 2022 21:00:09 GMT</pubDate>
    <dc:creator>geneshackman</dc:creator>
    <dc:date>2022-12-06T21:00:09Z</dc:date>
    <item>
      <title>saving file with different decimal places, and rounding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/saving-file-with-different-decimal-places-and-rounding/m-p/848179#M335342</link>
      <description>&lt;P&gt;I hope this is a simple question. I have the following data. The first five rows are population, the second five rows are percent of population. For reasons too complex to get into here, I need them both in the same "rate" column, so please, no suggestions about putting them in different columns.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My question is how to save a sas data set where population has no decimal places and percent is rounded to one decimal place.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 96pt;" border="0" width="128" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" style="height: 15.0pt; width: 48pt;"&gt;group&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="width: 48pt;"&gt;rate&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;A&lt;/TD&gt;
&lt;TD align="right"&gt;35000&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;B&lt;/TD&gt;
&lt;TD align="right"&gt;746&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;C&lt;/TD&gt;
&lt;TD align="right"&gt;462158&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;D&lt;/TD&gt;
&lt;TD align="right"&gt;9534&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;E&lt;/TD&gt;
&lt;TD align="right"&gt;760449&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;A&lt;/TD&gt;
&lt;TD align="right"&gt;31.523&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;B&lt;/TD&gt;
&lt;TD align="right"&gt;30.64&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;C&lt;/TD&gt;
&lt;TD align="right"&gt;12.701&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;D&lt;/TD&gt;
&lt;TD align="right"&gt;24.339&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;E&lt;/TD&gt;
&lt;TD align="right"&gt;18.9111&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Gene&lt;/P&gt;</description>
      <pubDate>Tue, 06 Dec 2022 18:33:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/saving-file-with-different-decimal-places-and-rounding/m-p/848179#M335342</guid>
      <dc:creator>geneshackman</dc:creator>
      <dc:date>2022-12-06T18:33:19Z</dc:date>
    </item>
    <item>
      <title>Re: saving file with different decimal places, and rounding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/saving-file-with-different-decimal-places-and-rounding/m-p/848204#M335344</link>
      <description>&lt;P&gt;A numeric variable can only have one format.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Don't worry about how it is stored, format in the presentation.&amp;nbsp; Surely there is a key or indicator to tell you whether the value in rate is a population or a percent.&amp;nbsp; Perhaps if there are no populations under 100 you could do it that way.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Dec 2022 20:53:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/saving-file-with-different-decimal-places-and-rounding/m-p/848204#M335344</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2022-12-06T20:53:30Z</dc:date>
    </item>
    <item>
      <title>Re: saving file with different decimal places, and rounding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/saving-file-with-different-decimal-places-and-rounding/m-p/848206#M335345</link>
      <description>As you say, I may have to format the decimal place in the programming part that's about the presentation. Okay, thanks.</description>
      <pubDate>Tue, 06 Dec 2022 21:00:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/saving-file-with-different-decimal-places-and-rounding/m-p/848206#M335345</guid>
      <dc:creator>geneshackman</dc:creator>
      <dc:date>2022-12-06T21:00:09Z</dc:date>
    </item>
    <item>
      <title>Re: saving file with different decimal places, and rounding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/saving-file-with-different-decimal-places-and-rounding/m-p/848226#M335352</link>
      <description>&lt;P&gt;Generic comment: Poor things happen when a variable has more than one meaning, ie. Count of population, percentage of anything.&lt;/P&gt;
&lt;P&gt;If you are creating output files that go into another application then that's possibly poor design in that program but I would likely wait until writing the output file to worry about the format and not try to use it in SAS.&lt;/P&gt;
&lt;P&gt;If someone is manipulating this data in SAS then they have chosen something that is going to require lots of work to deal with properly.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Dec 2022 23:50:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/saving-file-with-different-decimal-places-and-rounding/m-p/848226#M335352</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-12-06T23:50:46Z</dc:date>
    </item>
    <item>
      <title>Re: saving file with different decimal places, and rounding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/saving-file-with-different-decimal-places-and-rounding/m-p/849785#M335918</link>
      <description>&lt;P&gt;data table;&lt;BR /&gt;input group $ rate ;&lt;BR /&gt;datalines;&lt;BR /&gt;A 35000&lt;BR /&gt;B 746&lt;BR /&gt;C 462158&lt;BR /&gt;D 9534&lt;BR /&gt;E 760449&lt;BR /&gt;A 31.523&lt;BR /&gt;B 30.64&lt;BR /&gt;C 12.701&lt;BR /&gt;D 24.339&lt;BR /&gt;E 18.9111&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;set table;&lt;BR /&gt;if scan(put(rate, best.),2,".") = '' then rate = put(rate, 12.);&lt;BR /&gt;if scan(put(rate, best.),2,".") ne '' then rate = put(rate, 12.1);&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;Output:&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 102pt;" border="0" width="138" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 14.6pt;"&gt;
&lt;TD width="69" height="19" class="xl65" style="height: 14.6pt; width: 51pt;"&gt;group&lt;/TD&gt;
&lt;TD width="69" class="xl65" style="border-left: none; width: 51pt;"&gt;rate&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.6pt;"&gt;
&lt;TD height="19" class="xl65" style="height: 14.6pt; border-top: none;"&gt;A&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;35000&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.6pt;"&gt;
&lt;TD height="19" class="xl65" style="height: 14.6pt; border-top: none;"&gt;B&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;746&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.6pt;"&gt;
&lt;TD height="19" class="xl65" style="height: 14.6pt; border-top: none;"&gt;C&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;462158&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.6pt;"&gt;
&lt;TD height="19" class="xl65" style="height: 14.6pt; border-top: none;"&gt;D&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;9534&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.6pt;"&gt;
&lt;TD height="19" class="xl65" style="height: 14.6pt; border-top: none;"&gt;E&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;760449&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.6pt;"&gt;
&lt;TD height="19" class="xl65" style="height: 14.6pt; border-top: none;"&gt;A&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;31.5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.6pt;"&gt;
&lt;TD height="19" class="xl65" style="height: 14.6pt; border-top: none;"&gt;B&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;30.6&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.6pt;"&gt;
&lt;TD height="19" class="xl65" style="height: 14.6pt; border-top: none;"&gt;C&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;12.7&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.6pt;"&gt;
&lt;TD height="19" class="xl65" style="height: 14.6pt; border-top: none;"&gt;D&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;24.3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.6pt;"&gt;
&lt;TD height="19" class="xl65" style="height: 14.6pt; border-top: none;"&gt;E&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;18.9&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Thu, 15 Dec 2022 05:51:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/saving-file-with-different-decimal-places-and-rounding/m-p/849785#M335918</guid>
      <dc:creator>SK_11</dc:creator>
      <dc:date>2022-12-15T05:51:37Z</dc:date>
    </item>
    <item>
      <title>Re: saving file with different decimal places, and rounding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/saving-file-with-different-decimal-places-and-rounding/m-p/849815#M335921</link>
      <description>&lt;P&gt;Not perfect but one of below two options might give you what you're after.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input group $ rate;
  datalines;
A 35000
B 746
C 462158
D 9534
E 760449
A 31.523
B 30.64
C 12.701
D 24.339
E 18.9111
;

proc format;
  value real_pct
    -100 - 100 = [16.1]
    other      = [16.]
    ;
run;

data want;
  set have;

  format rate2 real_pct.;
  rate2=rate;

  format rate3 best32.;
  rate3=round(rate,0.1);
run;

proc print data=want;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1671097598746.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78566i571DCDEA844497EB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1671097598746.png" alt="Patrick_0-1671097598746.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2022 09:46:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/saving-file-with-different-decimal-places-and-rounding/m-p/849815#M335921</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-12-15T09:46:45Z</dc:date>
    </item>
    <item>
      <title>Re: saving file with different decimal places, and rounding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/saving-file-with-different-decimal-places-and-rounding/m-p/849820#M335923</link>
      <description>&lt;P&gt;Or here a 3rd option.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input group $ rate;
  datalines;
A 35000
B 746
C 462158
D 9534
E 760449
A 31.523
B 30.64
C 12.701
D 24.339
E 18.9111
;

proc fcmp outlib=work.fcmp.funcs;
  function f_real_pct(in) $16;
    if ceil(in)=in then
      out=put(in,f16.);
    else 
      out=catx(' ',put(in,f16.1),'%');
    out=strip(out);
    return(out);
  endsub;
run;quit;

options cmplib=work.fcmp;

proc format;
  value real_pct
    other=[f_real_pct()]
    ;
run;

proc print data=have;
  format rate real_pct.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1671098904787.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78569i03A96207D415C4D6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1671098904787.png" alt="Patrick_0-1671098904787.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2022 10:08:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/saving-file-with-different-decimal-places-and-rounding/m-p/849820#M335923</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-12-15T10:08:30Z</dc:date>
    </item>
  </channel>
</rss>

