<?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 of repeat contacts fromk previous days in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/count-of-repeat-contacts-fromk-previous-days/m-p/510670#M32416</link>
    <description>&lt;P&gt;Have added the following code that gets me the same day repeat Persons.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test2;
	set test;
	Where date = '05Nov2018'd;
run;

proc sql;
	Create table testCallPersons as
		Select Date, Person, count(person) as personcount
			From (select distinct date, Person from Test2)
				Group by Date, Person;
quit;

proc Summary data=testCallPersons;
	By Date;
	VAr personcount;
	Output out=testPCount (Drop=_freq_ _Type_) sum=;
run;

proc sql;
	Create table testCallCount as
		Select Date, Person, count(person) as Callcount
			From (select date, Person from Test2)
				Group by Date, Person;
quit;

Data TestDupPerscount;
	Set testCallCount;

	If Callcount &amp;gt;1 Then
		DupCount = 2;
	Else DupCount = 1;
run;

proc Summary data=TestDupPerscount;
	By Date;
	VAr Callcount	DupCount;
	Output out=testCCount (Drop=_freq_ _Type_) sum=;
run;

Data testMerge;
	Merge testPCount  testCCount;
	By Date;
run;

Data testPerc;
	Drop personcount Callcount DupCount;
	Set testmerge;
	Day1Perc = (DupCount - personcount) / personcount;
	format Day1perc percent7.2;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyway of doing this smarter? Just now need to work out how to match against the previous days to get the duplicates.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dean&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 06 Nov 2018 02:41:51 GMT</pubDate>
    <dc:creator>DME790</dc:creator>
    <dc:date>2018-11-06T02:41:51Z</dc:date>
    <item>
      <title>count of repeat contacts fromk previous days</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/count-of-repeat-contacts-fromk-previous-days/m-p/510665#M32415</link>
      <description>&lt;P&gt;HI All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a data set which I need to&amp;nbsp;calculate&amp;nbsp;any persons that made&amp;nbsp;multiple contact on that day as well as made contact in the previous&amp;nbsp;seven days.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example I have a list of all contacts made on 5 November 2018 and I need&amp;nbsp;a count of those 'Persons' that also made contact between the 29 October 2018 and 4 November 2018. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;I need the total count of contacts (in example is 10)&lt;/LI&gt;&lt;LI&gt;Distinct number of contacts (in the example is 9)&lt;/LI&gt;&lt;LI&gt;the&amp;nbsp;count of&amp;nbsp;duplicate person who made contact on the previous seven days &amp;nbsp;&lt;/LI&gt;&lt;LI&gt;Then I can calculate the percentage of repeat contacts&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input Date :yymmdd. DN $ Person $;
format date yymmdd10.;
datalines;
2018-11-05 Apple AA
2018-11-05 Pear BB
2018-11-05 Peach CC
2018-11-05 Apple AA
2018-11-05 Apple DD
2018-11-05 Apple EE
2018-11-05 Pear FF
2018-11-05 Peach GG
2018-11-05 Peach HH
2018-11-05 Pear II
2018-11-02 Apple DDD
2018-11-02 Pear EEE
2018-11-02 Peach FFF
2018-11-02 Apple GGG
2018-11-02 Apple HHH
2018-11-02 Apple DD
2018-11-02 Pear III
2018-11-02 Peach FF
2018-11-02 Peach JJJ
2018-11-02 Pear KKK
2018-11-01 Pear JJ
2018-11-01 Apple AA
2018-11-01 Peach KK
2018-11-01 Pear BB
2018-11-01 Peach LL
2018-11-01 Pear MM
2018-11-01 Apple EE
2018-11-01 Apple NN
2018-11-01 Pear OO
2018-11-01 Peach PP
2018-10-31 Pear QQ
2018-10-31 Apple RR
2018-10-31 Peach SS
2018-10-31 Pear FF
2018-10-31 Peach TT
2018-10-31 Pear UU
2018-10-31 Apple AA
2018-10-31 Apple VV
2018-10-31 Pear WW
2018-10-31 Peach XX
2018-10-30 Apple AA
2018-10-30 Pear AAA
2018-10-30 Peach CC
2018-10-30 Apple BBB
2018-10-30 Apple DD
2018-10-30 Apple EE
2018-10-30 Pear FF
2018-10-30 Peach GG
2018-10-30 Peach HH
2018-10-30 Pear ZZ
2018-10-29 Pear QQ
2018-10-29 Apple RR
2018-10-29 Peach SS
2018-10-29 Pear FF
2018-10-29 Peach TT
2018-10-29 Pear UU
2018-10-29 Apple AA
2018-10-29 Apple VV
2018-10-29 Pear WW
2018-10-29 Peach XX;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;so from the example I should end up with the following result.&lt;/P&gt;&lt;P&gt;&amp;nbsp;Percentage of multiple contacts&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;5/11/2018&lt;/TD&gt;&lt;TD&gt;2/11/2018&lt;/TD&gt;&lt;TD&gt;1/11/2018&lt;/TD&gt;&lt;TD&gt;31/10/2018&lt;/TD&gt;&lt;TD&gt;30/10/2018&lt;/TD&gt;&lt;TD&gt;29/10/2018&lt;/TD&gt;&lt;TD&gt;total Repeat %&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Monday, 5 November 2018&lt;/TD&gt;&lt;TD&gt;11%&lt;/TD&gt;&lt;TD&gt;22%&lt;/TD&gt;&lt;TD&gt;33%&lt;/TD&gt;&lt;TD&gt;22%&lt;/TD&gt;&lt;TD&gt;78%&lt;/TD&gt;&lt;TD&gt;22%&lt;/TD&gt;&lt;TD&gt;89%&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have attached the spreadsheet with the test data and calculations - I'm not sure how to get the same results out of SAS EG.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help appreciated&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dean&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Nov 2018 01:53:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/count-of-repeat-contacts-fromk-previous-days/m-p/510665#M32415</guid>
      <dc:creator>DME790</dc:creator>
      <dc:date>2018-11-06T01:53:03Z</dc:date>
    </item>
    <item>
      <title>Re: count of repeat contacts fromk previous days</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/count-of-repeat-contacts-fromk-previous-days/m-p/510670#M32416</link>
      <description>&lt;P&gt;Have added the following code that gets me the same day repeat Persons.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test2;
	set test;
	Where date = '05Nov2018'd;
run;

proc sql;
	Create table testCallPersons as
		Select Date, Person, count(person) as personcount
			From (select distinct date, Person from Test2)
				Group by Date, Person;
quit;

proc Summary data=testCallPersons;
	By Date;
	VAr personcount;
	Output out=testPCount (Drop=_freq_ _Type_) sum=;
run;

proc sql;
	Create table testCallCount as
		Select Date, Person, count(person) as Callcount
			From (select date, Person from Test2)
				Group by Date, Person;
quit;

Data TestDupPerscount;
	Set testCallCount;

	If Callcount &amp;gt;1 Then
		DupCount = 2;
	Else DupCount = 1;
run;

proc Summary data=TestDupPerscount;
	By Date;
	VAr Callcount	DupCount;
	Output out=testCCount (Drop=_freq_ _Type_) sum=;
run;

Data testMerge;
	Merge testPCount  testCCount;
	By Date;
run;

Data testPerc;
	Drop personcount Callcount DupCount;
	Set testmerge;
	Day1Perc = (DupCount - personcount) / personcount;
	format Day1perc percent7.2;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyway of doing this smarter? Just now need to work out how to match against the previous days to get the duplicates.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dean&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Nov 2018 02:41:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/count-of-repeat-contacts-fromk-previous-days/m-p/510670#M32416</guid>
      <dc:creator>DME790</dc:creator>
      <dc:date>2018-11-06T02:41:51Z</dc:date>
    </item>
    <item>
      <title>Re: count of repeat contacts fromk previous days</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/count-of-repeat-contacts-fromk-previous-days/m-p/510672#M32417</link>
      <description>&lt;P&gt;Here's one approach that's simpler. It matches the 11.1% you reported via your method.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=test noprint;;
where date='05Nov2018'd;
table person / out=t1;
run;

proc format;
value dup_fmt
1 = 'Unique'
2-high = 'Duplicated';
run;

proc freq data=t1 (rename=count=Freq) noprint;;
table freq / out=t2;
format freq dup_fmt.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/75899"&gt;@DME790&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Have added the following code that gets me the same day repeat Persons.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test2;
	set test;
	Where date = '05Nov2018'd;
run;

proc sql;
	Create table testCallPersons as
		Select Date, Person, count(person) as personcount
			From (select distinct date, Person from Test2)
				Group by Date, Person;
quit;

proc Summary data=testCallPersons;
	By Date;
	VAr personcount;
	Output out=testPCount (Drop=_freq_ _Type_) sum=;
run;

proc sql;
	Create table testCallCount as
		Select Date, Person, count(person) as Callcount
			From (select date, Person from Test2)
				Group by Date, Person;
quit;

Data TestDupPerscount;
	Set testCallCount;

	If Callcount &amp;gt;1 Then
		DupCount = 2;
	Else DupCount = 1;
run;

proc Summary data=TestDupPerscount;
	By Date;
	VAr Callcount	DupCount;
	Output out=testCCount (Drop=_freq_ _Type_) sum=;
run;

Data testMerge;
	Merge testPCount  testCCount;
	By Date;
run;

Data testPerc;
	Drop personcount Callcount DupCount;
	Set testmerge;
	Day1Perc = (DupCount - personcount) / personcount;
	format Day1perc percent7.2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway of doing this smarter? Just now need to work out how to match against the previous days to get the duplicates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dean&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Nov 2018 03:05:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/count-of-repeat-contacts-fromk-previous-days/m-p/510672#M32417</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-11-06T03:05:54Z</dc:date>
    </item>
  </channel>
</rss>

