<?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 years occurrence in aggregated periods in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Count-years-occurrence-in-aggregated-periods/m-p/843258#M36584</link>
    <description>&lt;P&gt;One way:&lt;/P&gt;
&lt;PRE&gt;data temp;
   set db1;
   array a(2015:2021) a2015 - a2021;
   do i=2015 to 2021;
      a[i]= (year(start) le i le year(end));
   end;
   keep id a: ;
run;

proc summary data=temp nway;
   class id;
   var a: ;
   output out=want (drop=_:) max=;
run;&lt;/PRE&gt;
&lt;P&gt;Of course, after you put data, as in a year value, into a variable name it becomes much harder to work with in general.&lt;/P&gt;
&lt;P&gt;What will you do with the Want data set.&lt;/P&gt;</description>
    <pubDate>Tue, 08 Nov 2022 23:07:57 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2022-11-08T23:07:57Z</dc:date>
    <item>
      <title>Count years occurrence in aggregated periods</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Count-years-occurrence-in-aggregated-periods/m-p/843249#M36581</link>
      <description>&lt;P&gt;Hi guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need your support for a quite complicated task.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the following&amp;nbsp;&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 DB1;
input ID :$20. (Start End)(:date9.);
format Start End date9.;
cards;
0001 01JAN2015 06FEB2017 
0001 08FEB2017 25APR2018 
0001 26APR2018 31DEC2021 
0002 01JAN2017 12JUL2017 
0002 13JUL2017 31DEC2019 
0002 01JAN2020 31OCT2021
;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;what I need to do is to add a flag for each year if the ID appears in the *year. Then for each year I need to count one time the flag for each ID if it appears more than one time (but I can do this by myself).&lt;/P&gt;
&lt;P&gt;The desired output would be:&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 DB1;
input ID :$20. (Start End)(:date9.) F2015 :$20. F2016 :$20. F2017 :$20. F2018 :$20. F2019 :$20. F2020 :$20. F2021 :$20.;
format Start End date9.;
cards;
0001 01JAN2015 06FEB2017 1 1 1 0 0 0 0
0001 08FEB2017 25APR2018 0 0 1 1 0 0 0
0001 26APR2018 31DEC2021 0 0 0 1 1 1 1
0002 01JAN2017 12JUL2017 0 0 1 0 0 0 0
0002 13JUL2017 31DEC2019 0 0 1 1 1 0 0
0002 01JAN2020 31OCT2021 0 0 0 0 0 1 1
;

data want;
input ID :$20.A2015 :$20. A2016 :$20. A2017 :$20. A2018 :$20. A2019 :$20. A2020 :$20. A2021 :$20.;
cards;
0001 1 1 1 1 1 1 1
0002 0 0 1 1 1 1 1
;



&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My point is that periods are aggregated across years so that year(Start) is ineffective. Can anyone help me please?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Nov 2022 21:55:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Count-years-occurrence-in-aggregated-periods/m-p/843249#M36581</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2022-11-08T21:55:12Z</dc:date>
    </item>
    <item>
      <title>Re: Count years occurrence in aggregated periods</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Count-years-occurrence-in-aggregated-periods/m-p/843251#M36582</link>
      <description>&lt;P&gt;Retain on the array variables and reset it at the start of each ID.&lt;/P&gt;
&lt;P&gt;So as you set it to one it stays as one until it's reset.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Nov 2022 22:00:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Count-years-occurrence-in-aggregated-periods/m-p/843251#M36582</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-11-08T22:00:09Z</dc:date>
    </item>
    <item>
      <title>Re: Count years occurrence in aggregated periods</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Count-years-occurrence-in-aggregated-periods/m-p/843258#M36584</link>
      <description>&lt;P&gt;One way:&lt;/P&gt;
&lt;PRE&gt;data temp;
   set db1;
   array a(2015:2021) a2015 - a2021;
   do i=2015 to 2021;
      a[i]= (year(start) le i le year(end));
   end;
   keep id a: ;
run;

proc summary data=temp nway;
   class id;
   var a: ;
   output out=want (drop=_:) max=;
run;&lt;/PRE&gt;
&lt;P&gt;Of course, after you put data, as in a year value, into a variable name it becomes much harder to work with in general.&lt;/P&gt;
&lt;P&gt;What will you do with the Want data set.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Nov 2022 23:07:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Count-years-occurrence-in-aggregated-periods/m-p/843258#M36584</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-11-08T23:07:57Z</dc:date>
    </item>
    <item>
      <title>Re: Count years occurrence in aggregated periods</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Count-years-occurrence-in-aggregated-periods/m-p/843284#M36587</link>
      <description>Thank you very much! I just need to do summary stats with "want".</description>
      <pubDate>Wed, 09 Nov 2022 06:25:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Count-years-occurrence-in-aggregated-periods/m-p/843284#M36587</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2022-11-09T06:25:31Z</dc:date>
    </item>
  </channel>
</rss>

