<?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: Comparison of groups within groups in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Comparison-of-groups-within-groups/m-p/412568#M279817</link>
    <description>&lt;P&gt;OK. I get confused with denominator.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards expandtabs ;
input id1	id2	$ date	value;
cards;
1	A	2014	0.5
1	B	2014	0.8
1	C	2014	0.1
1	D	2014	1.2
1	A	2015	1.3
1	C	2015	5.6
1	D	2015	0.4
1	E	2015	0.7
1	F	2015	0.3
1	C	2016	1.3
1	D	2016	2.5
1	F	2016	4.1
1	G	2016	3.1
1	H	2016	2.1
;
run;
data want;
array x{9999} $ 32 _temporary_;
m=0;
do until(last.date);
 set have;
 by id1 date;
 if id2 in x then m+1;
end;
want=divide(k-m,k);
if id1 ne lag(id1) then call missing(want);
output;

k=0;
do until(last.date);
 set have;
 by id1 date;
 k+1;x{k}=id2;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 11 Nov 2017 10:27:59 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2017-11-11T10:27:59Z</dc:date>
    <item>
      <title>Comparison of groups within groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparison-of-groups-within-groups/m-p/412212#M279814</link>
      <description>&lt;P&gt;I have the following dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;id1&lt;/TD&gt;&lt;TD&gt;id2&lt;/TD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2.1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;2014&lt;/TD&gt;&lt;TD&gt;5.4&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;BR /&gt;I want to compare the distinct id2s by each id1 and year group. For instance, I want to compare id2s where id1=1 and year=2014 with id2s where id1=1 and year=2015. So, in the first case(id1=1 and year=2014), the distinct values of id2 are A, B, C, D and for the second case (id1=1 and year=2015) distinct values are A,&amp;nbsp;C,&amp;nbsp;D, E. I can co this by using first.id1, first.year etc.&amp;nbsp;After this step the dataset will look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;id1&lt;/TD&gt;&lt;TD&gt;id2&lt;/TD&gt;&lt;TD&gt;date&lt;/TD&gt;&lt;TD&gt;value&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;2014&lt;/TD&gt;&lt;TD&gt;0.5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;2014&lt;/TD&gt;&lt;TD&gt;0.8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;2014&lt;/TD&gt;&lt;TD&gt;0.1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;D&lt;/TD&gt;&lt;TD&gt;2014&lt;/TD&gt;&lt;TD&gt;1.2&lt;/TD&gt;&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&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;H&lt;/TD&gt;&lt;TD&gt;2016&lt;/TD&gt;&lt;TD&gt;2.1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now, I want to compare these three groups and get the id2 that exist in first case but not exist in the second case (i.e. B exists in first id1xyear group but not in second id1xyear group). In the end, the&amp;nbsp;measure I want will divide the&amp;nbsp;total number of distinct id2s in first&amp;nbsp;id1xyear with total number of nonexisting id2s in the second id1xyear (1/4 in the first comparison from 2014 to 2015).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It will repeat the same procedure with id1=2 and so on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;id1&lt;/TD&gt;&lt;TD&gt;date&lt;/TD&gt;&lt;TD&gt;measure&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2014&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2015&lt;/TD&gt;&lt;TD&gt;1/4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2016&lt;/TD&gt;&lt;TD&gt;2/5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;2014&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope I was able to convey what I need. I would appreciate any help. Thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Nov 2017 04:49:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparison-of-groups-within-groups/m-p/412212#M279814</guid>
      <dc:creator>lezgin</dc:creator>
      <dc:date>2017-11-10T04:49:42Z</dc:date>
    </item>
    <item>
      <title>Re: Comparison of groups within groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparison-of-groups-within-groups/m-p/412324#M279815</link>
      <description>&lt;P&gt;I think it should be&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;id1&lt;/TD&gt;
&lt;TD&gt;date&lt;/TD&gt;
&lt;TD&gt;measure&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;2014&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;2015&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;1/5&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use your second dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards expandtabs ;
input id1	id2	$ date	value;
cards;
1	A	2014	0.5
1	B	2014	0.8
1	C	2014	0.1
1	D	2014	1.2
1	A	2015	1.3
1	C	2015	5.6
1	D	2015	0.4
1	E	2015	0.7
1	F	2015	0.3
1	C	2016	1.3
1	D	2016	2.5
1	F	2016	4.1
1	G	2016	3.1
1	H	2016	2.1
;
run;
data want;
array x{9999} $ 32 _temporary_;
m=0;
do n=1 by 1 until(last.date);
 set have;
 by id1 date;
 if id2 in x then m+1;
end;
want=divide(k-m,n);
if id1 ne lag(id1) then call missing(want);
output;

k=0;
do until(last.date);
 set have;
 by id1 date;
 k+1;x{k}=id2;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 Nov 2017 13:46:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparison-of-groups-within-groups/m-p/412324#M279815</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-11-10T13:46:33Z</dc:date>
    </item>
    <item>
      <title>Re: Comparison of groups within groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparison-of-groups-within-groups/m-p/412466#M279816</link>
      <description>&lt;P&gt;Thank you very much. I appreciate your help but I think it is not giving what I am looking for. From 2014 to 2015 A,B,C,D becomes A,C,D,E,F. From 2015 to 2016 A,C,D,E,F becomes C,D,F,G,H.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So what I need is from 2014 to 2015: identify&amp;nbsp;that B is missing in 2015 and divide this (1 missing) with all four (A,B,C,D) in 2014=1/4&lt;/P&gt;&lt;P&gt;From 2015 to 2016: identify that A and E is missing (2 missing). Divide 2 by what I have for 2015 (A,C,D,E,F) by 5= 2/5.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It should repeat this by id1. When next id1 comes the code should compare next first id1xdate group with the next date of same id1. I hope this is more clear now. Again, thank you very much.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Nov 2017 18:47:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparison-of-groups-within-groups/m-p/412466#M279816</guid>
      <dc:creator>lezgin</dc:creator>
      <dc:date>2017-11-10T18:47:41Z</dc:date>
    </item>
    <item>
      <title>Re: Comparison of groups within groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparison-of-groups-within-groups/m-p/412568#M279817</link>
      <description>&lt;P&gt;OK. I get confused with denominator.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards expandtabs ;
input id1	id2	$ date	value;
cards;
1	A	2014	0.5
1	B	2014	0.8
1	C	2014	0.1
1	D	2014	1.2
1	A	2015	1.3
1	C	2015	5.6
1	D	2015	0.4
1	E	2015	0.7
1	F	2015	0.3
1	C	2016	1.3
1	D	2016	2.5
1	F	2016	4.1
1	G	2016	3.1
1	H	2016	2.1
;
run;
data want;
array x{9999} $ 32 _temporary_;
m=0;
do until(last.date);
 set have;
 by id1 date;
 if id2 in x then m+1;
end;
want=divide(k-m,k);
if id1 ne lag(id1) then call missing(want);
output;

k=0;
do until(last.date);
 set have;
 by id1 date;
 k+1;x{k}=id2;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 11 Nov 2017 10:27:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparison-of-groups-within-groups/m-p/412568#M279817</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-11-11T10:27:59Z</dc:date>
    </item>
    <item>
      <title>Re: Comparison of groups within groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparison-of-groups-within-groups/m-p/412636#M279818</link>
      <description>&lt;P&gt;Thanks for your patience. I understand if you don't have time for this. You have already been very helpful. I appreciate that. I realized that I need to&amp;nbsp;decompose the measure into two parts. Let me give you a new example of each measure. There are only subtle changes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Measure1: Suppose we have A,B,C,D in id1xdate1 and A,B,C,E in id1xdate2 and C,D,E,F in id1xdate3. Measure1 finds that D from id1xdate1 is missing in id1xdate2 and divides D (1) by A,B,C,D&amp;nbsp;(4) of id1xdate1 and returns 1/4. Similarly, from id1xdate2 to id1xdate3, this measure finds that A,B&amp;nbsp;are missing in id1xdate2 and divides (2) by A,B,C,E (4) and returns 2/4. &lt;STRONG&gt;This measure makes the second comparison between id2s of id1xdate2 and id1xdate3. The change from id1xdate2 to id1xdate3 matters now.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Measure 2: Again, suppose we have&amp;nbsp;&lt;SPAN&gt;A,B,C,D in id1xdate1 and A,B,C,E in id1xdate2 and C,D,E,F in id1xdate3.&lt;/SPAN&gt;&amp;nbsp;Measure2 finds that E is not present in id1xdate1 but is present in id1xdate2. This time measure2 divides E (1) by A,B,C,D (4) in id1xdate1 and return 1/4. From id1xdate2 to id1xdate3, the code finds that D,F&amp;nbsp;are not present in id1xdate2 but are present in id1xdate3. Measure divides D,F&amp;nbsp;(2) by A,B,C,E (4) and return 2/4. &lt;STRONG&gt;Similarly, this measure makes the second comparison between id2s of id1xdate2 and id1xdate3. The change from id1xdate2 to id1xdate3 matters now.&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Dataset for this example is below. I tried to modify your code to separate the two measures but I couldn't get the code to make the comparison between only two id1xdates. Not from the beginning.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;id1&lt;/TD&gt;&lt;TD&gt;id2&lt;/TD&gt;&lt;TD&gt;date&lt;/TD&gt;&lt;TD&gt;value&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;20140530&lt;/TD&gt;&lt;TD&gt;0.5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;20140530&lt;/TD&gt;&lt;TD&gt;0.8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt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TD&gt;&lt;TD&gt;20141130&lt;/TD&gt;&lt;TD&gt;4.1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;19990130&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Sun, 12 Nov 2017 03:01:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparison-of-groups-within-groups/m-p/412636#M279818</guid>
      <dc:creator>lezgin</dc:creator>
      <dc:date>2017-11-12T03:01:55Z</dc:date>
    </item>
    <item>
      <title>Re: Comparison of groups within groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparison-of-groups-within-groups/m-p/412678#M279819</link>
      <description>&lt;P&gt;OK. the following code should work for your second measure.&lt;/P&gt;
&lt;P&gt;the code I have already posted is for your first measure.&lt;/P&gt;
&lt;P&gt;Note: use your second table in your first post .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards expandtabs ;
input id1	id2	$ date	value;
cards;
1	A	20140530	0.5
1	B	20140530	0.8
1	C	20140530	0.1
1	D	20140530	1.2
1	A	20140831	1.3
1	B	20140831	5.6
1	C	20140831	0.4
1	E	20140831	0.7
1	C	20141130	0.3
1	D	20141130	1.3
1	E	20141130	2.5
1	F	20141130	4.1
2	A	19990130	3
;
run;
data want;
array x{9999} $ 32 _temporary_;
m=0;
do until(last.date);
 set have;
 by id1 date;
 if id2 not in x then m+1; /*********/
end;
want=divide(m,k);  /*********/
if id1 ne lag(id1) then call missing(want);
output;

k=0;
do until(last.date);
 set have;
 by id1 date;
 k+1;x{k}=id2;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Nov 2017 11:00:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparison-of-groups-within-groups/m-p/412678#M279819</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-11-12T11:00:45Z</dc:date>
    </item>
    <item>
      <title>Re: Comparison of groups within groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparison-of-groups-within-groups/m-p/412709#M279820</link>
      <description>&lt;P&gt;In the first sheet of attached excel&amp;nbsp;file I included a portion of the data. The first measure mostly works fine but sometimes returns negative values where it should return 0. The second measure does not work properly and I wasn't able to detect the problem. In the second sheet of the attached excel file I included the dateset transposed to show you how it should work. I included what the measure should return and what it returns when you use the dataset in the first sheet. The discrepancies are in red. Thank you very much.&lt;/P&gt;</description>
      <pubDate>Sun, 12 Nov 2017 18:01:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparison-of-groups-within-groups/m-p/412709#M279820</guid>
      <dc:creator>lezgin</dc:creator>
      <dc:date>2017-11-12T18:01:10Z</dc:date>
    </item>
    <item>
      <title>Re: Comparison of groups within groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparison-of-groups-within-groups/m-p/412904#M279821</link>
      <description>&lt;P&gt;I feel very Sorry. My bad. Add CALL MISSING(of x{*});&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;call missing(of x{*}) ;
k&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;0&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
do until&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;last&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;date&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
 &lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; have&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
 &lt;SPAN class="token statement"&gt;by&lt;/SPAN&gt; id1 &lt;SPAN class="token function"&gt;date&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
 k&lt;SPAN class="token operator"&gt;+&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;x&lt;SPAN class="token punctuation"&gt;{&lt;/SPAN&gt;k&lt;SPAN class="token punctuation"&gt;}&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;id2&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
end&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Nov 2017 14:07:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparison-of-groups-within-groups/m-p/412904#M279821</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-11-13T14:07:03Z</dc:date>
    </item>
    <item>
      <title>Re: Comparison of groups within groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparison-of-groups-within-groups/m-p/412908#M279822</link>
      <description>&lt;P&gt;Hi. I rewrite it by Hash Table. Hope you like it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*****For measure1 *******/
proc import datafile='/folders/myfolders/sascommunity.xlsx' out=have dbms=xlsx replace;
run;

proc sort data=have;
 by id1 date;
run;

data want;
if _n_=1 then do;
  if 0 then set have;
  declare hash h1();
  h1.definekey('id2');
  h1.definedone();
end;

n=h1.num_items;
do until(last.date);
 set have;
 by id1 date;
 rc=h1.remove();
end;
m=h1.num_items;
want=divide(m,n);
if id1 ne lag(id1) then call missing(want);
output;
h1.clear();
do until(last.date);
 set have;
 by id1 date;
 h1.ref();
end;
keep id1 id2 date want m n;
run;&lt;/CODE&gt;&lt;/PRE&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/******For measure2 ***********/
proc import datafile='/folders/myfolders/sascommunity.xlsx' out=have dbms=xlsx replace;
run;

proc sort data=have;
 by id1 date;
run;

data want;
if _n_=1 then do;
  if 0 then set have;
  declare hash h1();
  h1.definekey('id2');
  h1.definedone();
end;

m=0;
n=h1.num_items;
do until(last.date);
 set have;
 by id1 date;
 if h1.check() ne 0 then m+1;
end;
want=divide(m,n);
if id1 ne lag(id1) then call missing(want);
output;
h1.clear();
do until(last.date);
 set have;
 by id1 date;
 h1.ref();
end;
keep id1 id2 date want m n;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Nov 2017 14:13:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparison-of-groups-within-groups/m-p/412908#M279822</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-11-13T14:13:43Z</dc:date>
    </item>
    <item>
      <title>Re: Comparison of groups within groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparison-of-groups-within-groups/m-p/412912#M279823</link>
      <description>&lt;P&gt;The following code is the fixed my original code. Sorry .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*******For measure1*********/
data want;
array x{9999} $ 32 _temporary_;
m=0;
do until(last.date);
 set have;
 by id1 date;
 if id2 in x then m+1;
end;
want=divide(k-m,k);
if id1 ne lag(id1) then call missing(want);
output;

call missing(of x{*}); /* &amp;lt;--*/
k=0;
do until(last.date);
 set have;
 by id1 date;
 k+1;x{k}=id2;
end;
run;&lt;/CODE&gt;&lt;/PRE&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;PRE&gt;&lt;CODE class=" language-sas"&gt;/******For measure2***********/

data want;
array x{9999} $ 32 _temporary_;
m=0;
do until(last.date);
 set have;
 by id1 date;
 if id2 not in x then m+1; /*********/
end;
want=divide(m,k);  /*********/
if id1 ne lag(id1) then call missing(want);
output;

call missing(of x{*}); /*&amp;lt;---*/
k=0;
do until(last.date);
 set have;
 by id1 date;
 k+1;x{k}=id2;
end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Nov 2017 14:19:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparison-of-groups-within-groups/m-p/412912#M279823</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-11-13T14:19:15Z</dc:date>
    </item>
    <item>
      <title>Re: Comparison of groups within groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparison-of-groups-within-groups/m-p/412974#M279824</link>
      <description>&lt;P&gt;This has been very helpful. Thank you very much for your kind and quick replies.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Nov 2017 17:47:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparison-of-groups-within-groups/m-p/412974#M279824</guid>
      <dc:creator>lezgin</dc:creator>
      <dc:date>2017-11-13T17:47:22Z</dc:date>
    </item>
  </channel>
</rss>

