<?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: Percentange Calculation in SQL in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Percentange-Calculation-in-SQL/m-p/186337#M3816</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;proc report / tabulate ....&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 19 Jul 2014 20:24:16 GMT</pubDate>
    <dc:creator>jakarman</dc:creator>
    <dc:date>2014-07-19T20:24:16Z</dc:date>
    <item>
      <title>Percentange Calculation in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Percentange-Calculation-in-SQL/m-p/186336#M3815</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How can we calculate unique count percentage and normal percentage by a group? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;input Q1 Q2 Q3 Q4 Q5 Age BU;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1 5 2 3 4 3 3&lt;/P&gt;&lt;P&gt;4 5 2 1 2 1 3&lt;/P&gt;&lt;P&gt;2 4 4 3 2 3 2&lt;/P&gt;&lt;P&gt;1 3 2 5 3 2 3&lt;/P&gt;&lt;P&gt;1 2 4 2 1 2 2&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The following program calculates unique count and count for Q1 by Age.&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;/P&gt;&lt;P&gt;create table file1 as&lt;/P&gt;&lt;P&gt;select Age,Count(Distinct Q1) as Unique, Count(Q2) as Count&lt;/P&gt;&lt;P&gt;from test&lt;/P&gt;&lt;P&gt;group by Age;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" height="101" style="width: 287px; height: 88px;" summary="Page Layout"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="xl64" height="21" width="105"&gt;Age&lt;/TD&gt;&lt;TD class="xl65" style="border-left: none;" width="53"&gt;Unique&lt;/TD&gt;&lt;TD class="xl66" style="border-left: none;" width="44"&gt;Count&lt;/TD&gt;&lt;TD class="xl73" width="90"&gt;Unique %&lt;/TD&gt;&lt;TD class="xl73" width="64"&gt;%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl67" height="20" style="border-top: none;" width="105"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;" width="53"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl68" style="border-top: none; border-left: none;" width="44"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl72"&gt;25%&lt;/TD&gt;&lt;TD align="right" class="xl72"&gt;20%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl67" height="20" style="border-top: none;" width="105"&gt;2&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;" width="53"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl68" style="border-top: none; border-left: none;" width="44"&gt;2&lt;/TD&gt;&lt;TD align="right" class="xl72"&gt;25%&lt;/TD&gt;&lt;TD align="right" class="xl72"&gt;40%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl69" height="21" style="border-top: none;" width="105"&gt;3&lt;/TD&gt;&lt;TD align="right" class="xl70" style="border-top: none; border-left: none;" width="53"&gt;2&lt;/TD&gt;&lt;TD align="right" class="xl71" style="border-top: none; border-left: none;" width="44"&gt;2&lt;/TD&gt;&lt;TD align="right" class="xl72"&gt;50%&lt;/TD&gt;&lt;TD align="right" class="xl72"&gt;40%&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;I am unable to calculate percentage for these two columns. Refer the table above. The percentage is count for each case by total values. Is it possible via data step or PROC SQL?&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 19 Jul 2014 18:53:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Percentange-Calculation-in-SQL/m-p/186336#M3815</guid>
      <dc:creator>Ujjawal</dc:creator>
      <dc:date>2014-07-19T18:53:03Z</dc:date>
    </item>
    <item>
      <title>Re: Percentange Calculation in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Percentange-Calculation-in-SQL/m-p/186337#M3816</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;proc report / tabulate ....&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 19 Jul 2014 20:24:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Percentange-Calculation-in-SQL/m-p/186337#M3816</guid>
      <dc:creator>jakarman</dc:creator>
      <dc:date>2014-07-19T20:24:16Z</dc:date>
    </item>
    <item>
      <title>Re: Percentange Calculation in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Percentange-Calculation-in-SQL/m-p/186338#M3817</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table file1 as&lt;BR /&gt;select Age,Count(Distinct Q1) as Uniq, Count(Q2) as Count&lt;BR /&gt;from test&lt;BR /&gt;group by Age;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;select age,uniq,count,(uniq/(select sum(uniq) from file1)) as unique_percent,(count/(select sum(count) from file1)) as cnt_percent&lt;BR /&gt;from file1;&lt;BR /&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 19 Jul 2014 21:07:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Percentange-Calculation-in-SQL/m-p/186338#M3817</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2014-07-19T21:07:56Z</dc:date>
    </item>
    <item>
      <title>Re: Percentange Calculation in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Percentange-Calculation-in-SQL/m-p/186339#M3818</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't understand what this is about but you seem to want something like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;select &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; age, &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; daQ1 label="Q1 Unique", &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; caQ1 label="Q1 Count", &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; daQ1/dQ2 label="Unique Q1/Q2" format=percent6.1, &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; caQ1/cQ2 label="Count Q1/Q2" format=percent6.1&lt;/P&gt;&lt;P&gt;from &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (select age, count(distinct Q1) as daQ1, count(Q1) as caQ1 &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from test&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; group by age), &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (select count(distinct Q2) as dQ2, count(Q2) as cQ2 from test);&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 19 Jul 2014 21:47:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Percentange-Calculation-in-SQL/m-p/186339#M3818</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2014-07-19T21:47:29Z</dc:date>
    </item>
    <item>
      <title>Re: Percentange Calculation in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Percentange-Calculation-in-SQL/m-p/186340#M3819</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This question has been asked many times before like: &lt;A _jive_internal="true" href="https://communities.sas.com/message/115464"&gt;https://communities.sas.com/message/115464&lt;/A&gt; , &lt;A _jive_internal="true" href="https://communities.sas.com/thread/30943?tstart=0"&gt;https://communities.sas.com/thread/30943&lt;/A&gt;&lt;/P&gt;&lt;P&gt;If you are new to SAS my preference is leaving out any restriction learning all the possibilities with their advantages and disadvantages.&lt;BR /&gt;As SAS is more as just a data-step or SQL language I made the reference to procedures, there are several of them.&lt;/P&gt;&lt;P&gt;Reviewing the options with proc means it is remarkable what you can do with that. &lt;A href="http://support.sas.com/documentation/cdl/en/proc/66663/HTML/default/viewer.htm#n1qnc9bddfvhzqn105kqitnf29cp.htm" title="http://support.sas.com/documentation/cdl/en/proc/66663/HTML/default/viewer.htm#n1qnc9bddfvhzqn105kqitnf29cp.htm"&gt;Base SAS(R) 9.4 Procedures Guide, Second Edition&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 20 Jul 2014 06:08:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Percentange-Calculation-in-SQL/m-p/186340#M3819</guid>
      <dc:creator>jakarman</dc:creator>
      <dc:date>2014-07-20T06:08:03Z</dc:date>
    </item>
  </channel>
</rss>

