<?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 Need help with proc freq in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-with-proc-freq/m-p/41806#M10834</link>
    <description>Greetings (think I posted this in the wrong forum earlier),&lt;BR /&gt;
&lt;BR /&gt;
Currently I have a stored process that does a proc freq on a table of data. The 2 columns of interest are Facility and Contacts. I have a filter setup in the stored process to filter on the Facility. The table looks like this:&lt;BR /&gt;
&lt;BR /&gt;
Facility, Contacts&lt;BR /&gt;
A, 1&lt;BR /&gt;
A, 2&lt;BR /&gt;
B, 3&lt;BR /&gt;
B, 10&lt;BR /&gt;
C, 15&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Now... in my stored process has the following code:&lt;BR /&gt;
proc sort data=opmetric.sas_geo_2010all out=barron;&lt;BR /&gt;
by descending facilityname descending contacts;&lt;BR /&gt;
where state in (%stringGen(parm=state)) and facilityname in (%stringGen(parm=facility)); run;&lt;BR /&gt;
&lt;BR /&gt;
proc freq data=barron order=data noprint;&lt;BR /&gt;
tables state*city*facilityname / list out=contacts;&lt;BR /&gt;
weight contacts;&lt;BR /&gt;
run;&lt;BR /&gt;
data finalcontacts (drop=percent);&lt;BR /&gt;
set contacts;&lt;BR /&gt;
cumcontacts+percent;&lt;BR /&gt;
run;&lt;BR /&gt;
data sasbase.geo2010all;&lt;BR /&gt;
merge barron (in=c) finalcontacts (in=a) finalrounds (in=b);&lt;BR /&gt;
if c;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Now when I run this, this will calculate the frequency and cumulative % for each facility that I supply in the filter. So if I supplied Facilities A and B, the ending table would look like:&lt;BR /&gt;
Facility, Contacts, % of Total, Cum %&lt;BR /&gt;
A, 1, 6.25%, 6.25%&lt;BR /&gt;
A, 2, 12.5%, 18.75%&lt;BR /&gt;
B, 3, 18.75%, 37.50%&lt;BR /&gt;
B, 10, 62.50%, 100%&lt;BR /&gt;
&lt;BR /&gt;
However, what I would like for it to do is break out a cumulative % per Facility, instead of lumping every facility from the filter together. So Facility A would have its own cumulative %, then Facility B would have its own cumulative %. etc&lt;BR /&gt;
&lt;BR /&gt;
Hope this makes sense&lt;BR /&gt;
&lt;BR /&gt;
Thanks!</description>
    <pubDate>Tue, 30 Nov 2010 21:31:32 GMT</pubDate>
    <dc:creator>bcwhiteh</dc:creator>
    <dc:date>2010-11-30T21:31:32Z</dc:date>
    <item>
      <title>Need help with proc freq</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-with-proc-freq/m-p/41806#M10834</link>
      <description>Greetings (think I posted this in the wrong forum earlier),&lt;BR /&gt;
&lt;BR /&gt;
Currently I have a stored process that does a proc freq on a table of data. The 2 columns of interest are Facility and Contacts. I have a filter setup in the stored process to filter on the Facility. The table looks like this:&lt;BR /&gt;
&lt;BR /&gt;
Facility, Contacts&lt;BR /&gt;
A, 1&lt;BR /&gt;
A, 2&lt;BR /&gt;
B, 3&lt;BR /&gt;
B, 10&lt;BR /&gt;
C, 15&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Now... in my stored process has the following code:&lt;BR /&gt;
proc sort data=opmetric.sas_geo_2010all out=barron;&lt;BR /&gt;
by descending facilityname descending contacts;&lt;BR /&gt;
where state in (%stringGen(parm=state)) and facilityname in (%stringGen(parm=facility)); run;&lt;BR /&gt;
&lt;BR /&gt;
proc freq data=barron order=data noprint;&lt;BR /&gt;
tables state*city*facilityname / list out=contacts;&lt;BR /&gt;
weight contacts;&lt;BR /&gt;
run;&lt;BR /&gt;
data finalcontacts (drop=percent);&lt;BR /&gt;
set contacts;&lt;BR /&gt;
cumcontacts+percent;&lt;BR /&gt;
run;&lt;BR /&gt;
data sasbase.geo2010all;&lt;BR /&gt;
merge barron (in=c) finalcontacts (in=a) finalrounds (in=b);&lt;BR /&gt;
if c;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Now when I run this, this will calculate the frequency and cumulative % for each facility that I supply in the filter. So if I supplied Facilities A and B, the ending table would look like:&lt;BR /&gt;
Facility, Contacts, % of Total, Cum %&lt;BR /&gt;
A, 1, 6.25%, 6.25%&lt;BR /&gt;
A, 2, 12.5%, 18.75%&lt;BR /&gt;
B, 3, 18.75%, 37.50%&lt;BR /&gt;
B, 10, 62.50%, 100%&lt;BR /&gt;
&lt;BR /&gt;
However, what I would like for it to do is break out a cumulative % per Facility, instead of lumping every facility from the filter together. So Facility A would have its own cumulative %, then Facility B would have its own cumulative %. etc&lt;BR /&gt;
&lt;BR /&gt;
Hope this makes sense&lt;BR /&gt;
&lt;BR /&gt;
Thanks!</description>
      <pubDate>Tue, 30 Nov 2010 21:31:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-help-with-proc-freq/m-p/41806#M10834</guid>
      <dc:creator>bcwhiteh</dc:creator>
      <dc:date>2010-11-30T21:31:32Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with proc freq</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-with-proc-freq/m-p/41807#M10835</link>
      <description>First a couple of things that I noticed in the code:&lt;BR /&gt;
1) The data set finalrounds mentioned in the MERGE statement is not shown.&lt;BR /&gt;
2) There is no BY statement associated with the MERGE.  This is called a one-to-one merge and is an exceptionally good way to get wrong results.  In your case the incoming data (BARRON) are sorted, but the FREQ will not necessarily (in your case almost certainly not) maintain that order in the out= data set (CONTACTS).&lt;BR /&gt;
&lt;BR /&gt;
To calculate the FACILITY totals use FIRST. and LAST. processing.  There are a number of posts on the topic.  Your code will include:&lt;BR /&gt;
[pre]&lt;BR /&gt;
by ......facility;&lt;BR /&gt;
. . .&lt;BR /&gt;
* initialize the facility;&lt;BR /&gt;
if first.facility then do;&lt;BR /&gt;
...&lt;BR /&gt;
* create totals much as is currently being done;&lt;BR /&gt;
...&lt;BR /&gt;
* write the facility total.;&lt;BR /&gt;
if last.facility then do; &lt;BR /&gt;
[/pre]</description>
      <pubDate>Tue, 30 Nov 2010 23:03:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-help-with-proc-freq/m-p/41807#M10835</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2010-11-30T23:03:25Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with proc freq</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-with-proc-freq/m-p/41808#M10836</link>
      <description>I'm not sure I understand completely what you are attempting but it may be that PROC TABULATE with the ALL predicate, which gives summaries of items in a class, may be a place to look.</description>
      <pubDate>Thu, 02 Dec 2010 20:42:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-help-with-proc-freq/m-p/41808#M10836</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2010-12-02T20:42:46Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with proc freq</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-with-proc-freq/m-p/41809#M10837</link>
      <description>Hi.&lt;BR /&gt;
I am not sure.Maybe you need add 'by' statement into proc freq;&lt;BR /&gt;
[pre]&lt;BR /&gt;
ods html file='class.html' style=sasweb;&lt;BR /&gt;
proc sort data=sashelp.class out=class;&lt;BR /&gt;
by sex;&lt;BR /&gt;
run;&lt;BR /&gt;
proc freq data=class;&lt;BR /&gt;
 by sex;&lt;BR /&gt;
 tables sex*name /list;&lt;BR /&gt;
run;&lt;BR /&gt;
ods html close;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Fri, 03 Dec 2010 04:41:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-help-with-proc-freq/m-p/41809#M10837</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2010-12-03T04:41:30Z</dc:date>
    </item>
  </channel>
</rss>

