<?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: Count the number of individuals with multiple observations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Count-the-number-of-individuals-with-multiple-observations/m-p/617815#M181111</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;very nice. thanks.&lt;/P&gt;
&lt;P&gt;i added one more patient just wondering of my mock data was too simple. but now, the count is output in two separate rows. how to get the sum?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
input ctc_id date_contact; 
cards;
1 1
1 2
2 1
2 1
3 1
3 2
;

proc sql;
select count(distinct ctc_id) as count label='num of indivs with multiple'
from temp
group ctc_id
having count(distinct date_contact)&amp;gt;1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 16 Jan 2020 16:16:22 GMT</pubDate>
    <dc:creator>Cruise</dc:creator>
    <dc:date>2020-01-16T16:16:22Z</dc:date>
    <item>
      <title>Count the number of individuals with multiple observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-the-number-of-individuals-with-multiple-observations/m-p/617800#M181104</link>
      <description>&lt;P&gt;Hi folks:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd like to know how many patients were contacted more than one time. In the mock data, there are two patients and the first patient has two different dates (1 and 2) compared to the second patient who has the same date_contact for both rows. The correct answer to this is 1. Only one patient had two different dates which is indicating that he/she was contacted for two times. However, my proc sql in the code shown outputs 2 which is wrong.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you please help me correct my code or suggest a better approach to solve this problem?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
input ctc_id date_contact; 
cards;
1 1
1 2
2 1
2 1
;

PROC SORT DATA=TEMP;
BY CTC_ID;
DATA TEMP1; SET TEMP; 
by CTC_ID;
if first.CTC_ID then ID + 1;
RUN; 

PROC SORT DATA=TEMP1;
BY CTC_ID DATE_CONTACT;
DATA TEMP2; SET TEMP1; 
by CTC_ID DATE_CONTACT;
if first.DATE_CONTACT then ID1 + 1;
RUN;

DATA TEMP3; SET TEMP2;
IF ID NE ID1; 
RUN;

PROC SQL; SELECT COUNT(DISTINCT CTC_ID) FROM TEMP3; quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jan 2020 15:39:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-the-number-of-individuals-with-multiple-observations/m-p/617800#M181104</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2020-01-16T15:39:44Z</dc:date>
    </item>
    <item>
      <title>Re: Count the number of individuals with multiple observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-the-number-of-individuals-with-multiple-observations/m-p/617804#M181105</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/132289"&gt;@Cruise&lt;/a&gt;&amp;nbsp; if I understand you correctly, you just need this condition&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;having count(distinct date_contact)&amp;gt;1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I.e&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data temp;
input ctc_id date_contact; 
cards;
1 1
1 2
2 1
2 1
;

proc sql;
select *
from temp
group ctc_id
having count(distinct date_contact)&amp;gt;1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And if you want to count the indiv's&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sql;
select count(distinct ctc_id) as count label='num of indivs with multiple'
from temp
group ctc_id
having count(distinct date_contact)&amp;gt;1;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jan 2020 15:44:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-the-number-of-individuals-with-multiple-observations/m-p/617804#M181105</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-01-16T15:44:39Z</dc:date>
    </item>
    <item>
      <title>Re: Count the number of individuals with multiple observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-the-number-of-individuals-with-multiple-observations/m-p/617806#M181106</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
     create table temp1 as select distinct ctc_id,date_contact from temp;
run;
proc freq data=temp1;
    tables ctc_id/noprint out=temp2;
run;
proc freq data=temp2(where=(count&amp;gt;1));
    tables ctc_id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Jan 2020 15:44:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-the-number-of-individuals-with-multiple-observations/m-p/617806#M181106</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-01-16T15:44:27Z</dc:date>
    </item>
    <item>
      <title>Re: Count the number of individuals with multiple observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-the-number-of-individuals-with-multiple-observations/m-p/617815#M181111</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;very nice. thanks.&lt;/P&gt;
&lt;P&gt;i added one more patient just wondering of my mock data was too simple. but now, the count is output in two separate rows. how to get the sum?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
input ctc_id date_contact; 
cards;
1 1
1 2
2 1
2 1
3 1
3 2
;

proc sql;
select count(distinct ctc_id) as count label='num of indivs with multiple'
from temp
group ctc_id
having count(distinct date_contact)&amp;gt;1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Jan 2020 16:16:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-the-number-of-individuals-with-multiple-observations/m-p/617815#M181111</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2020-01-16T16:16:22Z</dc:date>
    </item>
    <item>
      <title>Re: Count the number of individuals with multiple observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-the-number-of-individuals-with-multiple-observations/m-p/617817#M181113</link>
      <description>&lt;P&gt;Hi Again&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/132289"&gt;@Cruise&lt;/a&gt;&amp;nbsp; &amp;nbsp;First off , my sincere apologies for overlooking a very minor logic, albeit that's not an excuse.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try the below modified&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
input ctc_id date_contact; 
cards;
1 1
1 2
2 1
2 1
3 1
3 2
;

proc sql;
create table want as
select count( ctc_id) as count label='num of indivs with multiple'
from
(select distinct ctc_id from temp group ctc_id having count(distinct date_contact)&amp;gt;1);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Jan 2020 16:22:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-the-number-of-individuals-with-multiple-observations/m-p/617817#M181113</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-01-16T16:22:25Z</dc:date>
    </item>
  </channel>
</rss>

