<?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: Decimal/percent calculations not working in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Decimal-percent-calculations-not-working/m-p/813819#M321235</link>
    <description>&lt;P&gt;This is how you present data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dlm="09"x dsd;
input column_a column_b;
datalines;
.	1
.	1
1	1
.	1
.	1
.	1
1	1
.	1
.	1
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and this is what you get when you run the code without GROUP BY:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select
    sum(column_a) as column_a,
    sum(column_b) as column_b,
    sum(column_a) / sum(column_b) as Rate format=percent8.2
  from have
;
quit;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;column_a	column_b	Rate
2	9	22.22%
&lt;/PRE&gt;</description>
    <pubDate>Tue, 17 May 2022 14:23:51 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2022-05-17T14:23:51Z</dc:date>
    <item>
      <title>Decimal/percent calculations not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Decimal-percent-calculations-not-working/m-p/813587#M321130</link>
      <description>&lt;P&gt;I have a simple query where I'm summarizing some numerical fields:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;PROC SQL;
CREATE TABLE test AS
SELECT
     SUM(column_a) AS column_a,
     SUM(column_b) AS column_b,
     SUM(column_a)/SUM(column_b) as Rate format=percent8.2

FROM
     table1

GROUP BY
     1

ORDER BY
     1

;quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is an example of the results:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;column_a&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;column_b&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Rate&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;99&lt;/TD&gt;&lt;TD&gt;0.00%&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why aren't my percentage calculations working?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2022 20:18:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Decimal-percent-calculations-not-working/m-p/813587#M321130</guid>
      <dc:creator>thelowendHz</dc:creator>
      <dc:date>2022-05-16T20:18:57Z</dc:date>
    </item>
    <item>
      <title>Re: Decimal/percent calculations not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Decimal-percent-calculations-not-working/m-p/813627#M321139</link>
      <description>&lt;P&gt;It works if you take the GROUP BY and ORDER BY out.&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2022 21:52:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Decimal-percent-calculations-not-working/m-p/813627#M321139</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-05-16T21:52:04Z</dc:date>
    </item>
    <item>
      <title>Re: Decimal/percent calculations not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Decimal-percent-calculations-not-working/m-p/813787#M321212</link>
      <description>&lt;P&gt;Hi Paige,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried taking those out and I got the same results. Any other suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Ryan&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2022 12:42:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Decimal-percent-calculations-not-working/m-p/813787#M321212</guid>
      <dc:creator>thelowendHz</dc:creator>
      <dc:date>2022-05-17T12:42:50Z</dc:date>
    </item>
    <item>
      <title>Re: Decimal/percent calculations not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Decimal-percent-calculations-not-working/m-p/813788#M321213</link>
      <description>&lt;P&gt;Please provide a portion of the data set named TEST.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Provide them according to &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;these instructions&lt;/A&gt; or by typing &lt;FONT color="#FF0000"&gt;working&lt;/FONT&gt; SAS data step code yourself.&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2022 12:49:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Decimal-percent-calculations-not-working/m-p/813788#M321213</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-05-17T12:49:22Z</dc:date>
    </item>
    <item>
      <title>Re: Decimal/percent calculations not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Decimal-percent-calculations-not-working/m-p/813807#M321228</link>
      <description>&lt;P&gt;This is what it looks like:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;column_a&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;column_b&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Tue, 17 May 2022 14:06:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Decimal-percent-calculations-not-working/m-p/813807#M321228</guid>
      <dc:creator>thelowendHz</dc:creator>
      <dc:date>2022-05-17T14:06:51Z</dc:date>
    </item>
    <item>
      <title>Re: Decimal/percent calculations not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Decimal-percent-calculations-not-working/m-p/813819#M321235</link>
      <description>&lt;P&gt;This is how you present data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dlm="09"x dsd;
input column_a column_b;
datalines;
.	1
.	1
1	1
.	1
.	1
.	1
1	1
.	1
.	1
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and this is what you get when you run the code without GROUP BY:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select
    sum(column_a) as column_a,
    sum(column_b) as column_b,
    sum(column_a) / sum(column_b) as Rate format=percent8.2
  from have
;
quit;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;column_a	column_b	Rate
2	9	22.22%
&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 May 2022 14:23:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Decimal-percent-calculations-not-working/m-p/813819#M321235</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-05-17T14:23:51Z</dc:date>
    </item>
    <item>
      <title>Re: Decimal/percent calculations not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Decimal-percent-calculations-not-working/m-p/813821#M321236</link>
      <description>&lt;P&gt;Your code cannot use column 1 as the grouping variable. It is the result of an aggregate function.&lt;/P&gt;
&lt;P&gt;Perhaps you meant there was some other variable you want to group by?&lt;/P&gt;
&lt;P&gt;Let's add a variable ID to your example data and try that.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  id=1;
  column_b=1;
  input column_a @@;
cards;
. . 1 . . . 1 . .
;

PROC SQL;
CREATE TABLE test AS
SELECT ID
     , SUM(column_a) AS column_a
     , SUM(column_b) AS column_b
     , SUM(column_a)/SUM(column_b) as Rate format=percent8.2

FROM
     have

GROUP BY
     1

ORDER BY
     1
;
quit;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1652797529614.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/71550iACF258276ABB7ECC/image-size/large?v=v2&amp;amp;px=999" role="button" title="Tom_0-1652797529614.png" alt="Tom_0-1652797529614.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2022 14:25:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Decimal-percent-calculations-not-working/m-p/813821#M321236</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-17T14:25:45Z</dc:date>
    </item>
  </channel>
</rss>

