<?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: Summing in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Summing/m-p/569084#M160317</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;have you considered one variable with different levels, e.g.:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set duplicate;

select;
  when (               EventDate &amp;lt; '01SEP2016'd) period = 1;*pre-intervention;
  when ('01SEP2016'd &amp;lt;=EventDate&amp;lt;= '28FEB2017'd) period = 2;*intervention;
  when (               EventDate &amp;gt;= '01MAR2017'd period = 3;*post-intervention;
  otherwise period = -1;
end;

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;all the best&lt;/P&gt;&lt;P&gt;Bart&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 26 Jun 2019 13:11:34 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2019-06-26T13:11:34Z</dc:date>
    <item>
      <title>Summing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing/m-p/569071#M160311</link>
      <description>&lt;P&gt;Hi folks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wanna create a variable to indicate mean number of health visits by ID for three time points that are; pre-intervention, intervention and post-intervention.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried 'SUM' function to specify 'ID' in 'By' statement but don't know how to specify time period in addition to ID.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jun 2019 12:49:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing/m-p/569071#M160311</guid>
      <dc:creator>sks521</dc:creator>
      <dc:date>2019-06-26T12:49:37Z</dc:date>
    </item>
    <item>
      <title>Re: Summing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing/m-p/569075#M160313</link>
      <description>&lt;P&gt;Could you share any sample dataset on your own?&amp;nbsp;&lt;/P&gt;&lt;P&gt;The sample set really helpful to share idea in detail.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jun 2019 12:55:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing/m-p/569075#M160313</guid>
      <dc:creator>Sathish_jammy</dc:creator>
      <dc:date>2019-06-26T12:55:28Z</dc:date>
    </item>
    <item>
      <title>Re: Summing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing/m-p/569080#M160314</link>
      <description>&lt;P&gt;Could you share your code too?&lt;/P&gt;&lt;P&gt;It will be easier to understand your problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jun 2019 13:02:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing/m-p/569080#M160314</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2019-06-26T13:02:49Z</dc:date>
    </item>
    <item>
      <title>Re: Summing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing/m-p/569082#M160315</link>
      <description>&lt;P&gt;So I have following three dummy variables to indicate three time points;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data dummy;&lt;BR /&gt;set duplicate;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;format EventDate YYMMDD10.;&lt;BR /&gt;if EventDate&amp;lt;'01SEP2016'd then preint=1;*pre-intervention;&lt;BR /&gt;else preint=0;&lt;BR /&gt;if '01SEP2016'd &amp;lt;=EventDate&amp;lt;= '28FEB2017'd then intervention=1;*intervention;&lt;BR /&gt;else intervention=0;&lt;BR /&gt;if EventDate &amp;gt;= '01MAR2017'd then postint=1;*post-intervention;&lt;BR /&gt;else postint=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The remaining data looks like this (just a few lines)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;PKid&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; EventDate&amp;nbsp; &amp;nbsp;visit&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Practice&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Status&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;preint&amp;nbsp; &amp;nbsp;intervention postint1234567&lt;/P&gt;&lt;DIV class="branch"&gt;&lt;DIV align="center"&gt;&lt;TABLE cellspacing="0" cellpadding="5"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;TD&gt;2016-02-29&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Bingley Medical Practice&lt;/TD&gt;&lt;TD&gt;Eligible&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;13&lt;/TD&gt;&lt;TD&gt;2016-02-29&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Saltaire Medical Practice&lt;/TD&gt;&lt;TD&gt;Eligible&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;32&lt;/TD&gt;&lt;TD&gt;2016-02-29&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Bingley Medical Practice&lt;/TD&gt;&lt;TD&gt;Eligible&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;73&lt;/TD&gt;&lt;TD&gt;2016-02-29&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Bingley Medical Practice&lt;/TD&gt;&lt;TD&gt;Eligible&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;2016-02-29&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Bingley Medical Practice&lt;/TD&gt;&lt;TD&gt;Eligible&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;104&lt;/TD&gt;&lt;TD&gt;2016-02-29&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Saltaire Medical Practice&lt;/TD&gt;&lt;TD&gt;InterventionGroup&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;105&lt;/TD&gt;&lt;TD&gt;2016-02-29&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Bingley Medical Practice&lt;/TD&gt;&lt;TD&gt;Eligible&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So each ID has multiple visits in each time period and I want average visits by ID in each time period.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jun 2019 13:04:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing/m-p/569082#M160315</guid>
      <dc:creator>sks521</dc:creator>
      <dc:date>2019-06-26T13:04:14Z</dc:date>
    </item>
    <item>
      <title>Re: Summing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing/m-p/569084#M160317</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;have you considered one variable with different levels, e.g.:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set duplicate;

select;
  when (               EventDate &amp;lt; '01SEP2016'd) period = 1;*pre-intervention;
  when ('01SEP2016'd &amp;lt;=EventDate&amp;lt;= '28FEB2017'd) period = 2;*intervention;
  when (               EventDate &amp;gt;= '01MAR2017'd period = 3;*post-intervention;
  otherwise period = -1;
end;

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;all the best&lt;/P&gt;&lt;P&gt;Bart&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jun 2019 13:11:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing/m-p/569084#M160317</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2019-06-26T13:11:34Z</dc:date>
    </item>
    <item>
      <title>Re: Summing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing/m-p/569085#M160318</link>
      <description>&lt;P&gt;Thanks but I do need to create dummy variables of the time period to do my analysis, and from your code I don't know how to create a variable which gives me sum of the number of visits per ID&lt;/P&gt;&lt;P&gt;&amp;nbsp;Can you elaborate please?&lt;/P&gt;&lt;P&gt;Ta&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jun 2019 13:16:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing/m-p/569085#M160318</guid>
      <dc:creator>sks521</dc:creator>
      <dc:date>2019-06-26T13:16:23Z</dc:date>
    </item>
    <item>
      <title>Re: Summing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing/m-p/569102#M160327</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I understand correctly, you need both: dummy variables in your dataset and also variables (or one variable) which counts(summs up) visits, right? In that case the following code should do both (I added some fake data to test it).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;all the best&lt;/P&gt;&lt;P&gt;Bart&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data duplicate;
infile cards dlm = "|";
input id eventDate yymmdd10. visit Practice : $ 50. Status : $ 20.;
format eventDate yymmdd10.;
if id;
cards;
1|2016-02-28|1|Bingley Medical Practice|Eligible|
2|2016-02-28|1|Saltaire Medical Practice|Eligible|
3|2016-02-28|1|Bingley Medical Practice|Eligible|
3|2016-03-28|1|Bingley Medical Practice|Eligible|
1|2016-04-28|1|Bingley Medical Practice|Eligible|
2|2016-04-28|1|Saltaire Medical Practice|InterventionGroup|
2|2016-04-28|1|Bingley Medical Practice|Eligible|
.|.|.| | |
1|2016-10-28|1|Bingley Medical Practice|Eligible|
1|2016-11-28|1|Saltaire Medical Practice|Eligible|
1|2016-12-28|1|Bingley Medical Practice|Eligible|
3|2016-10-28|1|Bingley Medical Practice|Eligible|
1|2017-01-28|1|Bingley Medical Practice|Eligible|
2|2016-10-28|1|Saltaire Medical Practice|InterventionGroup|
2|2016-11-28|1|Bingley Medical Practice|Eligible|
.|.|.| | |
2|2017-02-28|1|Bingley Medical Practice|Eligible|
2|2017-02-28|1|Saltaire Medical Practice|Eligible|
1|2017-02-28|1|Bingley Medical Practice|Eligible|
3|2017-03-28|1|Bingley Medical Practice|Eligible|
1|2017-04-28|1|Bingley Medical Practice|Eligible|
2|2017-04-28|1|Saltaire Medical Practice|InterventionGroup|
2|2017-04-28|1|Bingley Medical Practice|Eligible|
;
run;

proc sort data = duplicate;
by id eventDate;
run; 


data duplicate_1;
  set duplicate;
  
  retain _err_ preint int postint 0;
  array period[0:3] _err_ preint int postint;
 
  select;
    when (               EventDate &amp;lt; '01SEP2016'd) pd = 1;*pre-intervention;
    when ('01SEP2016'd &amp;lt;=EventDate&amp;lt;= '28FEB2017'd) pd = 2;*intervention;
    when (               EventDate&amp;gt;= '01MAR2017'd) pd = 3;*post-intervention;
    otherwise pd = 0;
  end;

  period[pd] = 1;
  output;
  period[pd] = 0;
run;


data duplicate_2;
  do until (last.id);
    set duplicate_1;
    by id;

    array sumperiod[0:3] _err_sum_ sum_preint sum_int sum_postint;

    sumperiod[pd] + 1;
  end;

  do until (last.id);
    set duplicate_1;
    by id;
    all_visits = sum(of sum_:);
    output;
  end;

  call missing(of sumperiod{*}, all_visits);
run;&lt;/CODE&gt;&amp;nbsp;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jun 2019 17:24:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing/m-p/569102#M160327</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2019-06-26T17:24:03Z</dc:date>
    </item>
    <item>
      <title>Re: Summing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing/m-p/569212#M160379</link>
      <description>&lt;P&gt;I scratched my head and I think it could be done with 1 data step and 1 data reading.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All the best&lt;/P&gt;&lt;P&gt;Bart&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data = duplicate;
by id eventDate;
run; 


data duplicate_3;

if _N_ = 1 then
do;
  declare hash H(dataset:"duplicate(obs=0)", ordered:"A", multidata:"Y");
  H.defineKey("id","eventDate");
  H.defineData(all:"yes");
  H.defineDone();
  declare hiter I("H");
end;
  H.clear();

do until (last.id);
  set duplicate;
  by id;
  _rc_ = H.add();

  array sumperiod[0:3] _err_sum_ sum_preint sum_int sum_postint;
 
  select;
    when (               EventDate &amp;lt; '01SEP2016'd) pd = 1;*pre-intervention;
    when ('01SEP2016'd &amp;lt;=EventDate&amp;lt;= '28FEB2017'd) pd = 2;*intervention;
    when (               EventDate&amp;gt;= '01MAR2017'd) pd = 3;*post-intervention;
    otherwise pd = 0;
  end;

  sumperiod[pd] + 1;
end;

all_visits = sum(of sum_:);

do while(I.next() = 0);
  retain _err_ preint int postint 0;
  array period[0:3] _err_ preint int postint;

  select;
    when (               EventDate &amp;lt; '01SEP2016'd) pd = 1;*pre-intervention;
    when ('01SEP2016'd &amp;lt;=EventDate&amp;lt;= '28FEB2017'd) pd = 2;*intervention;
    when (               EventDate&amp;gt;= '01MAR2017'd) pd = 3;*post-intervention;
    otherwise pd = 0;
  end;

  period[pd] = 1;
  output;
  period[pd] = 0;
end; 

 call missing(of sumperiod{*}, all_visits);

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Jun 2019 18:07:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing/m-p/569212#M160379</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2019-06-26T18:07:03Z</dc:date>
    </item>
    <item>
      <title>Re: Summing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing/m-p/569278#M160406</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/277970"&gt;@sks521&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;So I have following three dummy variables to indicate three time points;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data dummy;&lt;BR /&gt;set duplicate;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;format EventDate YYMMDD10.;&lt;BR /&gt;if EventDate&amp;lt;'01SEP2016'd then preint=1;*pre-intervention;&lt;BR /&gt;else preint=0;&lt;BR /&gt;if '01SEP2016'd &amp;lt;=EventDate&amp;lt;= '28FEB2017'd then intervention=1;*intervention;&lt;BR /&gt;else intervention=0;&lt;BR /&gt;if EventDate &amp;gt;= '01MAR2017'd then postint=1;*post-intervention;&lt;BR /&gt;else postint=0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The remaining data looks like this (just a few lines)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;PKid&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; EventDate&amp;nbsp; &amp;nbsp;visit&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Practice&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Status&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;preint&amp;nbsp; &amp;nbsp;intervention postint1234567&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV align="center"&gt;
&lt;TABLE cellspacing="0" cellpadding="5"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;9&lt;/TD&gt;
&lt;TD&gt;2016-02-29&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;Bingley Medical Practice&lt;/TD&gt;
&lt;TD&gt;Eligible&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;13&lt;/TD&gt;
&lt;TD&gt;2016-02-29&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;Saltaire Medical Practice&lt;/TD&gt;
&lt;TD&gt;Eligible&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;32&lt;/TD&gt;
&lt;TD&gt;2016-02-29&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;Bingley Medical Practice&lt;/TD&gt;
&lt;TD&gt;Eligible&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;73&lt;/TD&gt;
&lt;TD&gt;2016-02-29&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;Bingley Medical Practice&lt;/TD&gt;
&lt;TD&gt;Eligible&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;100&lt;/TD&gt;
&lt;TD&gt;2016-02-29&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;Bingley Medical Practice&lt;/TD&gt;
&lt;TD&gt;Eligible&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;104&lt;/TD&gt;
&lt;TD&gt;2016-02-29&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;Saltaire Medical Practice&lt;/TD&gt;
&lt;TD&gt;InterventionGroup&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;105&lt;/TD&gt;
&lt;TD&gt;2016-02-29&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;Bingley Medical Practice&lt;/TD&gt;
&lt;TD&gt;Eligible&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So each ID has multiple visits in each time period and I want average visits by ID in each time period.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;COUNTING is different then DUMMY Coding.&lt;/P&gt;
&lt;P&gt;If you want to count group levels then you use a single variable or a format to create groups from a single variable.&lt;/P&gt;
&lt;P&gt;Something like this perhaps:&lt;/P&gt;
&lt;PRE&gt;proc format library=work;
value intervene
low - &amp;lt;'01SEP2016'd = 'Preintervention'
'01SEP2016'd - '28FEB2017'd = 'Intervention'
'28FEB2017'd&amp;lt; - high = 'Postintervention'
;
run;

proc freq data=duplicate noprint;
   table id* eventdate/out=work.id_eventcount (drop=percent);
   format eventdate intervene.;
run;

proc means data=work.id_eventcount mean;
   class id;
   var eventdate;
   format eventdate intervene.;
run;&lt;/PRE&gt;
&lt;P&gt;of course you haven't supplied any idea of what format the "mean" is supposed to take such as report or data set and whether any other variables go into grouping or not.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jun 2019 20:30:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing/m-p/569278#M160406</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-06-26T20:30:17Z</dc:date>
    </item>
    <item>
      <title>Re: Summing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing/m-p/570537#M160896</link>
      <description>&lt;P&gt;Thanks but if I wanted to have 6 or 7 time periods instead, how will I write the syntax then?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best&lt;/P&gt;&lt;P&gt;Sarwat&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2019 13:01:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing/m-p/570537#M160896</guid>
      <dc:creator>sks521</dc:creator>
      <dc:date>2019-07-02T13:01:43Z</dc:date>
    </item>
    <item>
      <title>Re: Summing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing/m-p/570597#M160922</link>
      <description>&lt;P&gt;I did run this code but the output doesn't look right;&lt;/P&gt;&lt;P&gt;Pkid&amp;nbsp; &amp;nbsp; Nobs&amp;nbsp; &amp;nbsp; &amp;nbsp;Mean&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 20879.60&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 20758.33&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 20879.60&lt;/P&gt;&lt;P&gt;Looks like it has calculated mean out of Date value while I need mean number of visits per following duration; pre-intervention, intervention and post-intervention.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2019 15:25:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing/m-p/570597#M160922</guid>
      <dc:creator>sks521</dc:creator>
      <dc:date>2019-07-02T15:25:24Z</dc:date>
    </item>
    <item>
      <title>Re: Summing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing/m-p/570859#M161022</link>
      <description>&lt;P&gt;So I have tried to use the same syntax using more than three time pints and I got this log;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;885 data SMPsum;&lt;BR /&gt;886 set saltaire;&lt;BR /&gt;887&lt;BR /&gt;888 retain _err_ preint4 preint3 preint2 preint1 int postint1 postint2 postint3 0;&lt;BR /&gt;889 array period[0:8] _err_ preint int postint;&lt;BR /&gt;ERROR: Too few variables defined for the dimension(s) specified for the array period.&lt;BR /&gt;890&lt;BR /&gt;891 select;&lt;BR /&gt;892 when ( EventDate &amp;lt;'01MAR2016'd) pd = 1;*pre-intervention -4;&lt;BR /&gt;893 when ('01MAR2016'd &amp;lt;=EventDate&amp;lt;= '31AUG2016'd) pd=2; *preintrvention -3;&lt;BR /&gt;894 when ('01SEP2016'd &amp;lt;=EventDate&amp;lt;= '28FEB2017'd) pd=3; *preintervention -2;&lt;BR /&gt;895 when ('01MAR2017'd &amp;lt;=EventDate&amp;lt;= '31AUG2017'd) pd=4; *preintervention 1;&lt;BR /&gt;896 when ('01SEP2017'd &amp;lt;=EventDate&amp;lt;= '28FEB2018'd) pd =5;*intervention;&lt;BR /&gt;897 when ('01MAR2018'd &amp;lt;=EventDate&amp;lt;= '31AUG2018'd) pd=6; *postintervention 1;&lt;BR /&gt;898 when ('01SEP2018'd &amp;lt;=EventDate&amp;lt;= '28FEB2019'd) pd=7; *postintervention 2;&lt;BR /&gt;899 when ( EventDate&amp;gt;= '01MAR2019'd) pd =8 ;*post-intervention 3;&lt;BR /&gt;900 otherwise pd = 0;&lt;BR /&gt;901 end;&lt;BR /&gt;902&lt;BR /&gt;903 period[pd] = 1;&lt;BR /&gt;904 output;&lt;BR /&gt;905 period[pd] = 0;&lt;BR /&gt;906 run;&lt;/P&gt;&lt;P&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;WARNING: The data set WORK.SMPSUM may be incomplete. When this step was stopped there were 0&lt;BR /&gt;observations and 49 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.04 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ho do I deal with that please?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;S&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jul 2019 09:00:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing/m-p/570859#M161022</guid>
      <dc:creator>sks521</dc:creator>
      <dc:date>2019-07-03T09:00:56Z</dc:date>
    </item>
  </channel>
</rss>

