<?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 How to get the percentage for each unique combinations of variables in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-get-the-percentage-for-each-unique-combinations-of/m-p/46606#M12434</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I created the code as below, but don't know how I can calculate the percentage which should be: num/sum. Any idea how can I add this to the code?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table work.data02 as&lt;/P&gt;&lt;P&gt;&amp;nbsp; select x, y, gender, count(gender) as num, (select count(*) from work.data) as sum from work.data&lt;/P&gt;&lt;P&gt;&amp;nbsp; group by x, y, gender;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 06 Feb 2012 15:14:38 GMT</pubDate>
    <dc:creator>bncoxuk</dc:creator>
    <dc:date>2012-02-06T15:14:38Z</dc:date>
    <item>
      <title>How to get the percentage for each unique combinations of variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-get-the-percentage-for-each-unique-combinations-of/m-p/46604#M12432</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data work.data;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input x $ y $ gender $;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;&amp;nbsp; 1 1 F&lt;/P&gt;&lt;P&gt;&amp;nbsp; 1 2 M&lt;/P&gt;&lt;P&gt;&amp;nbsp; 2 1 F&lt;/P&gt;&lt;P&gt;&amp;nbsp; 2 2 F&lt;/P&gt;&lt;P&gt;&amp;nbsp; 1 2 M&lt;/P&gt;&lt;P&gt;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to use PROC SQL to create a table which has 4 columns: x, y, gender and percentage. The percentage represents: number of cases for each unique combination of x, y and gender, divided by the number of observations. So the result should look like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1 1 F&amp;nbsp; 0.2&lt;/P&gt;&lt;P&gt;1 2 M 0.4 &lt;/P&gt;&lt;P&gt;2 1 F&amp;nbsp; 0.2&lt;/P&gt;&lt;P&gt;2 2 F 0.2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Feb 2012 15:00:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-get-the-percentage-for-each-unique-combinations-of/m-p/46604#M12432</guid>
      <dc:creator>bncoxuk</dc:creator>
      <dc:date>2012-02-06T15:00:24Z</dc:date>
    </item>
    <item>
      <title>How to get the percentage for each unique combinations of variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-get-the-percentage-for-each-unique-combinations-of/m-p/46605#M12433</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why use SQL?&amp;nbsp; FREQ does this directly:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC FREQ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; TABLES x*y*gender/LIST;&lt;/P&gt;&lt;P&gt;&amp;nbsp; RUN;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can look up how to output the results into a SAS dataset if you need it that way.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Doc Muhlbaier&lt;/P&gt;&lt;P&gt;Duke&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Feb 2012 15:07:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-get-the-percentage-for-each-unique-combinations-of/m-p/46605#M12433</guid>
      <dc:creator>Doc_Duke</dc:creator>
      <dc:date>2012-02-06T15:07:58Z</dc:date>
    </item>
    <item>
      <title>How to get the percentage for each unique combinations of variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-get-the-percentage-for-each-unique-combinations-of/m-p/46606#M12434</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I created the code as below, but don't know how I can calculate the percentage which should be: num/sum. Any idea how can I add this to the code?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table work.data02 as&lt;/P&gt;&lt;P&gt;&amp;nbsp; select x, y, gender, count(gender) as num, (select count(*) from work.data) as sum from work.data&lt;/P&gt;&lt;P&gt;&amp;nbsp; group by x, y, gender;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Feb 2012 15:14:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-get-the-percentage-for-each-unique-combinations-of/m-p/46606#M12434</guid>
      <dc:creator>bncoxuk</dc:creator>
      <dc:date>2012-02-06T15:14:38Z</dc:date>
    </item>
    <item>
      <title>How to get the percentage for each unique combinations of variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-get-the-percentage-for-each-unique-combinations-of/m-p/46607#M12435</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I agree with Doc that you are doing a lot of unnecessary work, but you could do what you want with some minor adjustment to your code.&amp;nbsp; e.g.:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table work.data02 as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select x, y, gender, &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count(gender)/(select count(*) from work.data)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; as pct&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from work.data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; group by x, y, gender;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Feb 2012 15:24:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-get-the-percentage-for-each-unique-combinations-of/m-p/46607#M12435</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-02-06T15:24:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the percentage for each unique combinations of variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-get-the-percentage-for-each-unique-combinations-of/m-p/46608#M12436</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi:&lt;/P&gt;&lt;P&gt;&amp;nbsp; I know this has been answered, but to be fair to PROC REPORT and PROC TABULATE, they can also generate the percentage quite easily (easier than PROC SQL, I think). So I would have chosen TABULATE or REPORT or FREQ depending on whose output look and feel I liked better.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cynthia&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;ods html file='c:\temp\pctn_examp.html';&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;proc tabulate data=work.data;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp; title '1) TABULATE';&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp; class x y gender;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp; table x*y*gender,pctn;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;proc report data=work.data nowd;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp; title '2) REPORT';&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp; column x y gender pctn;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp; define x /group;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp; define y / group;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp; define gender / group;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp; define pctn / 'Percentage' f=percent8.2;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;proc freq data=work.data;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp; tables x*y*gender / list nocum;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp; title '3) FREQ';&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;ods html close;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Feb 2012 16:13:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-get-the-percentage-for-each-unique-combinations-of/m-p/46608#M12436</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2012-02-06T16:13:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the percentage for each unique combinations of variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-get-the-percentage-for-each-unique-combinations-of/m-p/46609#M12437</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Thanks, Cynthia, for the good examples of using the reporting procedures.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Feb 2012 16:22:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-get-the-percentage-for-each-unique-combinations-of/m-p/46609#M12437</guid>
      <dc:creator>bncoxuk</dc:creator>
      <dc:date>2012-02-06T16:22:07Z</dc:date>
    </item>
  </channel>
</rss>

