<?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: request for calculation no. of records in each sub group in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/request-for-calculation-no-of-records-in-each-sub-group/m-p/41349#M10685</link>
    <description>Try the following code. It is simple with Proc SQL instead od datastep;&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table test1 as&lt;BR /&gt;
select postcode, branch, count(*) as norecs&lt;BR /&gt;
from test&lt;BR /&gt;
group by postcode, branch&lt;BR /&gt;
order by postcode, branch;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
~ Sukanya E</description>
    <pubDate>Fri, 05 Jun 2009 17:31:03 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-06-05T17:31:03Z</dc:date>
    <item>
      <title>request for calculation no. of records in each sub group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/request-for-calculation-no-of-records-in-each-sub-group/m-p/41347#M10683</link>
      <description>Hi All,&lt;BR /&gt;
I have a file like &lt;BR /&gt;
name postcode branch&lt;BR /&gt;
simon  me1 4en  ctm&lt;BR /&gt;
john  me1 3ed rnt&lt;BR /&gt;
tst3  me1 7fg str&lt;BR /&gt;
hfjk me2 4kw  ctm&lt;BR /&gt;
jdk  me2 6df  str&lt;BR /&gt;
jde me2 8dj  rnt&lt;BR /&gt;
.&lt;BR /&gt;
.&lt;BR /&gt;
.&lt;BR /&gt;
.&lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
i would like to find the no. of records for&lt;BR /&gt;
pcode  branch  norecs&lt;BR /&gt;
me1 ctm  25&lt;BR /&gt;
me1 str  15&lt;BR /&gt;
me2 rnt  46&lt;BR /&gt;
....&lt;BR /&gt;
&lt;BR /&gt;
i have used the following code&lt;BR /&gt;
&lt;BR /&gt;
data test2(rename=(pcode1=pcode));&lt;BR /&gt;
set test1;&lt;BR /&gt;
* pcode is postcode;&lt;BR /&gt;
pcode1=substr(pcode,1,3);&lt;BR /&gt;
den=length(pcode1);&lt;BR /&gt;
if length(pcode1)&amp;lt;3 then delete;&lt;BR /&gt;
drop pcode;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=test3 nodup out=test4;&lt;BR /&gt;
by pcode lastname branch;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data test6;&lt;BR /&gt;
set test4;&lt;BR /&gt;
by pcode;&lt;BR /&gt;
retain npc;&lt;BR /&gt;
if first.pcode then do;&lt;BR /&gt;
npc=0;&lt;BR /&gt;
** i think some code here;&lt;BR /&gt;
end;&lt;BR /&gt;
npc+1;&lt;BR /&gt;
if last.pcode then output;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Now i am getting the how many records me1,me2.... but i would like to get&lt;BR /&gt;
me1 ctm ??&lt;BR /&gt;
me1 str ??&lt;BR /&gt;
me1 rnt ??&lt;BR /&gt;
me2 ctm ?&lt;BR /&gt;
.....&lt;BR /&gt;
&lt;BR /&gt;
Thanks in advance&lt;BR /&gt;
Sams</description>
      <pubDate>Fri, 05 Jun 2009 08:39:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/request-for-calculation-no-of-records-in-each-sub-group/m-p/41347#M10683</guid>
      <dc:creator>ssas</dc:creator>
      <dc:date>2009-06-05T08:39:46Z</dc:date>
    </item>
    <item>
      <title>Re: request for calculation no. of records in each sub group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/request-for-calculation-no-of-records-in-each-sub-group/m-p/41348#M10684</link>
      <description>proc sql;&lt;BR /&gt;
create table l as select *, count(postcode) as cnt  from l2 where postcode='me1' and branch='ctm' ;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
do the same for the remaining conditions then u will get 3 datasets then keep set for the three datasets.</description>
      <pubDate>Fri, 05 Jun 2009 12:07:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/request-for-calculation-no-of-records-in-each-sub-group/m-p/41348#M10684</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-05T12:07:34Z</dc:date>
    </item>
    <item>
      <title>Re: request for calculation no. of records in each sub group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/request-for-calculation-no-of-records-in-each-sub-group/m-p/41349#M10685</link>
      <description>Try the following code. It is simple with Proc SQL instead od datastep;&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table test1 as&lt;BR /&gt;
select postcode, branch, count(*) as norecs&lt;BR /&gt;
from test&lt;BR /&gt;
group by postcode, branch&lt;BR /&gt;
order by postcode, branch;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
~ Sukanya E</description>
      <pubDate>Fri, 05 Jun 2009 17:31:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/request-for-calculation-no-of-records-in-each-sub-group/m-p/41349#M10685</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-05T17:31:03Z</dc:date>
    </item>
    <item>
      <title>Re: request for calculation no. of records in each sub group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/request-for-calculation-no-of-records-in-each-sub-group/m-p/41350#M10686</link>
      <description>Hi:&lt;BR /&gt;
  While many good SQL solutions have been posted, do not overlook PROC FREQ or PROC TABULATE. They will both create counts and/or percents for you.&lt;BR /&gt;
  &lt;BR /&gt;
cynthia&lt;BR /&gt;
      &lt;BR /&gt;
[pre]&lt;BR /&gt;
                      &lt;BR /&gt;
proc freq data=postdata;&lt;BR /&gt;
  tables pcode1*branch / list;&lt;BR /&gt;
run;&lt;BR /&gt;
                     &lt;BR /&gt;
proc tabulate data=postdata;&lt;BR /&gt;
  class pcode1 branch;&lt;BR /&gt;
  table pcode1 all,&lt;BR /&gt;
        branch*n all*n;&lt;BR /&gt;
  keylabel n=' ';&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
[/pre]</description>
      <pubDate>Fri, 05 Jun 2009 20:56:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/request-for-calculation-no-of-records-in-each-sub-group/m-p/41350#M10686</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2009-06-05T20:56:20Z</dc:date>
    </item>
    <item>
      <title>Thanks a lot</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/request-for-calculation-no-of-records-in-each-sub-group/m-p/41351#M10687</link>
      <description>Excellent,&lt;BR /&gt;
Thanks a lot for your help.&lt;BR /&gt;
Sukanya's and Cynth's suggestions are really helpful.&lt;BR /&gt;
Many thanks mate(s)</description>
      <pubDate>Mon, 08 Jun 2009 10:36:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/request-for-calculation-no-of-records-in-each-sub-group/m-p/41351#M10687</guid>
      <dc:creator>ssas</dc:creator>
      <dc:date>2009-06-08T10:36:49Z</dc:date>
    </item>
  </channel>
</rss>

