<?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: Counting observations per ID in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Counting-observations-per-ID/m-p/819683#M40932</link>
    <description>&lt;P&gt;Next time please include a data example as i have included.&amp;nbsp; Seem like the code is working fine. see below&lt;/P&gt;
&lt;P&gt;also you could get rid of the data step procedure and include this line in your sql .&lt;/P&gt;
&lt;P&gt;where calculated diagct &amp;lt; 2;&amp;nbsp; (hint- in-between the from and the group by)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;data denomip ;
input claimheaderid  dxSeqNo icd ;
datalines ;
10 3 1
40 1 2
40 1 2
40 2 2
10 1 2
10 3 2
10 2 2
40 1 3
40 3 3
40 2 3
;
run;

proc sql;
create table diagcount as
select
claimheaderid,
dxSeqNo,
count(icd) as diagct
from denomip
group by claimheaderid, dxSeqno;
run;

/*less than or equal to 2 dx codes per claimheaderid*/
data diagct;
set diagcount;
by claimHeaderId;
where diagct &amp;lt;=2;
run;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 22 Jun 2022 16:06:32 GMT</pubDate>
    <dc:creator>CarmineVerrell</dc:creator>
    <dc:date>2022-06-22T16:06:32Z</dc:date>
    <item>
      <title>Counting observations per ID</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Counting-observations-per-ID/m-p/819674#M40929</link>
      <description>&lt;P&gt;I am trying to get the number of diagnoses per ID and grab only those with 2 or less:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table diagcount as
select
claimheaderid,
dxSeqNo,
count(icd) as diagct
from denomip
group by claimheaderid, dxSeqno;
run;

/*less than or equal to 2 dx codes per claimheaderid*/
data diagct;
set diagcount;
by claimHeaderId;
where diagct &amp;lt;=2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Am I on the right track?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2022 15:50:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Counting-observations-per-ID/m-p/819674#M40929</guid>
      <dc:creator>bhca60</dc:creator>
      <dc:date>2022-06-22T15:50:34Z</dc:date>
    </item>
    <item>
      <title>Re: Counting observations per ID</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Counting-observations-per-ID/m-p/819683#M40932</link>
      <description>&lt;P&gt;Next time please include a data example as i have included.&amp;nbsp; Seem like the code is working fine. see below&lt;/P&gt;
&lt;P&gt;also you could get rid of the data step procedure and include this line in your sql .&lt;/P&gt;
&lt;P&gt;where calculated diagct &amp;lt; 2;&amp;nbsp; (hint- in-between the from and the group by)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;data denomip ;
input claimheaderid  dxSeqNo icd ;
datalines ;
10 3 1
40 1 2
40 1 2
40 2 2
10 1 2
10 3 2
10 2 2
40 1 3
40 3 3
40 2 3
;
run;

proc sql;
create table diagcount as
select
claimheaderid,
dxSeqNo,
count(icd) as diagct
from denomip
group by claimheaderid, dxSeqno;
run;

/*less than or equal to 2 dx codes per claimheaderid*/
data diagct;
set diagcount;
by claimHeaderId;
where diagct &amp;lt;=2;
run;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2022 16:06:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Counting-observations-per-ID/m-p/819683#M40932</guid>
      <dc:creator>CarmineVerrell</dc:creator>
      <dc:date>2022-06-22T16:06:32Z</dc:date>
    </item>
    <item>
      <title>Re: Counting observations per ID</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Counting-observations-per-ID/m-p/819686#M40933</link>
      <description>&lt;P&gt;Your SQL is counting by ID AND Dxseqno. That does not match your description of counting the number of diagnoses.&lt;/P&gt;
&lt;P&gt;Does the SQL give what you expect?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My &lt;STRONG&gt;guess&lt;/STRONG&gt; is that you may not want the Dxseqno in that counting as you will get separate count for ID=1 and DXseqno=1, Id=1 and Dxseqno=2, Id=1 and Dxseqno=3. If there exactly 3 observations for Id=1 that look like that list and you expect a count to be 3 then you want to remove Dxseqno from the Group by&amp;nbsp; and the Select.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Provide some example data and expected result for that small sample.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2022 16:02:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Counting-observations-per-ID/m-p/819686#M40933</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-06-22T16:02:54Z</dc:date>
    </item>
  </channel>
</rss>

