<?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 replacing proc freq with sql count or similar in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/replacing-proc-freq-with-sql-count-or-similar/m-p/170702#M44102</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Let's say I have a dataset like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I use proc freq I'll get the respective frequencies of the total variable but I was wondering how to do it using sql.&amp;nbsp; I used the sum function for the Admit column,&amp;nbsp; but was wondering how to do something similar for Code and Patient Type? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql; select &lt;SPAN style="color: #008000; font-size: 10pt; font-family: Courier New;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;sum(Admit) as AdmitTot&lt;SPAN style="color: #008000; font-size: 10pt; font-family: Courier New;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;from pat_data; &lt;SPAN style="color: #008000; font-size: 10pt; font-family: Courier New;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" jive-data-cell="{&amp;quot;color&amp;quot;:&amp;quot;#000000&amp;quot;,&amp;quot;textAlign&amp;quot;:&amp;quot;left&amp;quot;,&amp;quot;padding&amp;quot;:&amp;quot;2&amp;quot;}" jive-data-header="{&amp;quot;color&amp;quot;:&amp;quot;#FFFFFF&amp;quot;,&amp;quot;backgroundColor&amp;quot;:&amp;quot;#6690BC&amp;quot;,&amp;quot;textAlign&amp;quot;:&amp;quot;center&amp;quot;,&amp;quot;padding&amp;quot;:&amp;quot;2&amp;quot;,&amp;quot;fontFamily&amp;quot;:&amp;quot;arial,helvetica,sans-serif&amp;quot;}" style="border: 1px solid #000000; width: 100%;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="padding: 0px; text-align: left; color: #ffffff; font-family: arial,helvetica,sans-serif; vertical-align: middle; background-color: #6690bc;"&gt;&lt;STRONG&gt;PatientType&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Code&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Admit&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;&lt;P&gt;Sick&lt;/P&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;999&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;Well&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;123&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;Well&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;999&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I use this for example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;select distinct PatientType, Code, Admit, count (*) as n&lt;/P&gt;&lt;P&gt;from pat_data&lt;/P&gt;&lt;P&gt;group by PatientType, Code, Admit;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I get a table that looks like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" style="border: 1px solid rgb(0, 0, 0); width: 100%;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;PatientType&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Code&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Admit&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;n&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;Sick&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;999&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;Well&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;123&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 06 Jan 2015 16:53:05 GMT</pubDate>
    <dc:creator>pinkyc</dc:creator>
    <dc:date>2015-01-06T16:53:05Z</dc:date>
    <item>
      <title>replacing proc freq with sql count or similar</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/replacing-proc-freq-with-sql-count-or-similar/m-p/170702#M44102</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Let's say I have a dataset like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I use proc freq I'll get the respective frequencies of the total variable but I was wondering how to do it using sql.&amp;nbsp; I used the sum function for the Admit column,&amp;nbsp; but was wondering how to do something similar for Code and Patient Type? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql; select &lt;SPAN style="color: #008000; font-size: 10pt; font-family: Courier New;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;sum(Admit) as AdmitTot&lt;SPAN style="color: #008000; font-size: 10pt; font-family: Courier New;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;from pat_data; &lt;SPAN style="color: #008000; font-size: 10pt; font-family: Courier New;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" jive-data-cell="{&amp;quot;color&amp;quot;:&amp;quot;#000000&amp;quot;,&amp;quot;textAlign&amp;quot;:&amp;quot;left&amp;quot;,&amp;quot;padding&amp;quot;:&amp;quot;2&amp;quot;}" jive-data-header="{&amp;quot;color&amp;quot;:&amp;quot;#FFFFFF&amp;quot;,&amp;quot;backgroundColor&amp;quot;:&amp;quot;#6690BC&amp;quot;,&amp;quot;textAlign&amp;quot;:&amp;quot;center&amp;quot;,&amp;quot;padding&amp;quot;:&amp;quot;2&amp;quot;,&amp;quot;fontFamily&amp;quot;:&amp;quot;arial,helvetica,sans-serif&amp;quot;}" style="border: 1px solid #000000; width: 100%;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="padding: 0px; text-align: left; color: #ffffff; font-family: arial,helvetica,sans-serif; vertical-align: middle; background-color: #6690bc;"&gt;&lt;STRONG&gt;PatientType&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Code&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Admit&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;&lt;P&gt;Sick&lt;/P&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;999&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;Well&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;123&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;Well&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;999&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I use this for example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;select distinct PatientType, Code, Admit, count (*) as n&lt;/P&gt;&lt;P&gt;from pat_data&lt;/P&gt;&lt;P&gt;group by PatientType, Code, Admit;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I get a table that looks like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" style="border: 1px solid rgb(0, 0, 0); width: 100%;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;PatientType&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Code&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Admit&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;n&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;Sick&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;999&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;Well&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;123&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Jan 2015 16:53:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/replacing-proc-freq-with-sql-count-or-similar/m-p/170702#M44102</guid>
      <dc:creator>pinkyc</dc:creator>
      <dc:date>2015-01-06T16:53:05Z</dc:date>
    </item>
    <item>
      <title>Re: replacing proc freq with sql count or similar</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/replacing-proc-freq-with-sql-count-or-similar/m-p/170703#M44103</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Your code doesn't match your sample output so I don't want to assume the structure of the data&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;Proc freq with sparse option is easier, or possible proc tabulate or even proc means. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First create a table of all possible combinations and then merge back with the original data is the SQL method.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table all_poss as&lt;/P&gt;&lt;P&gt;select a.patient_type, b.code&lt;/P&gt;&lt;P&gt;from&amp;nbsp; (select distinct patient_type from have) as a&lt;/P&gt;&lt;P&gt;CROSS JOIN&lt;/P&gt;&lt;P&gt;(select distinct code from have) as b;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*Then join/merge with desired table above.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Jan 2015 17:04:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/replacing-proc-freq-with-sql-count-or-similar/m-p/170703#M44103</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-01-06T17:04:44Z</dc:date>
    </item>
    <item>
      <title>Re: replacing proc freq with sql count or similar</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/replacing-proc-freq-with-sql-count-or-similar/m-p/170704#M44104</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry I think I phrased the question badly.&amp;nbsp; The first table is just a dataset with some info., if I use proc freq I'll get that PatientType had 67% well, 33% sick.&amp;nbsp; I was trying to use the count (*) in sql to achieve the same result but instead, it just counts something else and gives a n = 1 as an extra column so I don't think I'm using it correctly.&amp;nbsp; Is there a way to use sql to count each column and report the frequency exactly like proc freq?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So it would report PatientType having 67% well, 33%.&amp;nbsp; Code, 67% 999, and 33% 123.&amp;nbsp; For Admit, I was using Sum which works but I was wondering if there's a way using count to do it for all three columns.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Jan 2015 17:13:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/replacing-proc-freq-with-sql-count-or-similar/m-p/170704#M44104</guid>
      <dc:creator>pinkyc</dc:creator>
      <dc:date>2015-01-06T17:13:25Z</dc:date>
    </item>
    <item>
      <title>Re: replacing proc freq with sql count or similar</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/replacing-proc-freq-with-sql-count-or-similar/m-p/170705#M44105</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Post an example of your data and your output then. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Jan 2015 17:17:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/replacing-proc-freq-with-sql-count-or-similar/m-p/170705#M44105</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-01-06T17:17:08Z</dc:date>
    </item>
    <item>
      <title>Re: replacing proc freq with sql count or similar</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/replacing-proc-freq-with-sql-count-or-similar/m-p/170706#M44106</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As Reeza suggested input data and output will help to understand this in a better way. This is what I understood based on your description.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;select PatientType, count(PatientType) as freq_PatientType,count(PatientType)/(select count(*) from have) as percent format=percent7.,&amp;nbsp; &lt;/P&gt;&lt;P&gt;count(code) as freq_code, count(Code)/(select count(*) from have) as percent format=percent7., &lt;/P&gt;&lt;P&gt;count(Admit) as freq_admit, count(Admit)/(select count(*) from have) as percent format=percent7.&lt;/P&gt;&lt;P&gt;from have &lt;/P&gt;&lt;P&gt;group by PatientType;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Jan 2015 17:30:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/replacing-proc-freq-with-sql-count-or-similar/m-p/170706#M44106</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2015-01-06T17:30:18Z</dc:date>
    </item>
    <item>
      <title>Re: replacing proc freq with sql count or similar</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/replacing-proc-freq-with-sql-count-or-similar/m-p/170707#M44107</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&amp;nbsp; stat interpreted my question correctly, I'll try to post input and output data for any more questions in the future. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Jan 2015 18:10:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/replacing-proc-freq-with-sql-count-or-similar/m-p/170707#M44107</guid>
      <dc:creator>pinkyc</dc:creator>
      <dc:date>2015-01-06T18:10:23Z</dc:date>
    </item>
  </channel>
</rss>

