<?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: Do loop to find a person's status over two time points? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Do-loop-to-find-a-person-s-status-over-two-time-points/m-p/120900#M33319</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If I understand what you mean .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data aa;
format id best. start end yymmdd10.;
input id start yymmdd10. end yymmdd10.;
datalines;
1 2006-05-05 2006-06-30
2 2006-02-05 2006-05-30
3 2006-09-01 2008-11-30
4 2006-03-31 2009-2-28
;
run;
data want(drop=i s e);
 set aa;
 s=mdy(4,1,year(start));
 e=mdy(4,1,year(end));
 if start lt s then do; fyear=year(start)-1; output;end;
 do i=year(start) to year(end)-1;
&amp;nbsp; fyear=i;cyear=i;output;
 end;
 cyear=year(end);
 if end lt e then call missing(fyear);
&amp;nbsp; else fyear=cyear;
 output;
run;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 13 Sep 2012 04:41:43 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2012-09-13T04:41:43Z</dc:date>
    <item>
      <title>Do loop to find a person's status over two time points?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Do-loop-to-find-a-person-s-status-over-two-time-points/m-p/120897#M33316</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;Hello,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;I’ve a dataset with an ID variable and two time points that can be used to identify if an individual is active between two time points. I’d like to create a dataset that can record the person’s ID and if the person is active in each year. I'd like to do fiscal year (say from April 1 to March 31), though if one program can do calendar year (i.e. from Jan 1 to Dec 31), that's be terrific too. If the active period goes cross several years’ span, this person will have multiple records.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;Here is the data I’ve:&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;&lt;STRONG style="color: navy; background: none repeat scroll 0% 0% white; font-size: 10pt;"&gt;data&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; color: black; background: none repeat scroll 0% 0% white;"&gt; aa; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;&lt;SPAN style="font-size: 10pt; color: blue; background: none repeat scroll 0% 0% white;"&gt;format&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: black; background: none repeat scroll 0% 0% white;"&gt; id &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: teal; background: none repeat scroll 0% 0% white;"&gt;best.&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: black; background: none repeat scroll 0% 0% white;"&gt; start end &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: teal; background: none repeat scroll 0% 0% white;"&gt;yymmdd10.&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: black; background: none repeat scroll 0% 0% white;"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;&lt;SPAN style="font-size: 10pt; color: blue; background: none repeat scroll 0% 0% white;"&gt;input&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: black; background: none repeat scroll 0% 0% white;"&gt; id start &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: teal; background: none repeat scroll 0% 0% white;"&gt;yymmdd10.&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: black; background: none repeat scroll 0% 0% white;"&gt; end &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: teal; background: none repeat scroll 0% 0% white;"&gt;yymmdd10.&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: black; background: none repeat scroll 0% 0% white;"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;&lt;SPAN style="font-size: 10pt; color: blue; background: none repeat scroll 0% 0% white;"&gt;datalines&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: black; background: none repeat scroll 0% 0% white;"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10pt; font-family: arial,helvetica,sans-serif; color: black; background: none repeat scroll 0% 0% #ffffc0;"&gt;1 2006-05-05 2006-06-30&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10pt; font-family: arial,helvetica,sans-serif; color: black; background: none repeat scroll 0% 0% #ffffc0;"&gt;2 2006-02-05 2006-05-30&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10pt; font-family: arial,helvetica,sans-serif; color: black; background: none repeat scroll 0% 0% #ffffc0;"&gt;3 2006-09-01 2008-11-30&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10pt; font-family: arial,helvetica,sans-serif; color: black; background: none repeat scroll 0% 0% #ffffc0;"&gt;4 2006-03-31 2009-2-28&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10pt; font-family: arial,helvetica,sans-serif; color: black; background: none repeat scroll 0% 0% white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; &lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;The output data should look like the following. Cyear is a bonus ONLY if it can easily done and does not over-complicate the program:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;ID Fyear Cyear&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;1&amp;nbsp;&amp;nbsp; 2006&amp;nbsp; 2006&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;2&amp;nbsp;&amp;nbsp; 2005 &lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;2&amp;nbsp;&amp;nbsp; 2006&amp;nbsp; 2006&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;3&amp;nbsp;&amp;nbsp; 2006&amp;nbsp; 2006&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;3&amp;nbsp;&amp;nbsp; 2007&amp;nbsp; 2007&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;3&amp;nbsp;&amp;nbsp; 2008&amp;nbsp; 2008&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;4&amp;nbsp;&amp;nbsp; 2005&amp;nbsp; &lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;4&amp;nbsp;&amp;nbsp; 2006&amp;nbsp; 2006&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;4&amp;nbsp;&amp;nbsp; 2007&amp;nbsp; 2007&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;4&amp;nbsp;&amp;nbsp; 2008&amp;nbsp; 2008&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2009&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Sep 2012 20:47:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Do-loop-to-find-a-person-s-status-over-two-time-points/m-p/120897#M33316</guid>
      <dc:creator>Solph</dc:creator>
      <dc:date>2012-09-12T20:47:36Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop to find a person's status over two time points?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Do-loop-to-find-a-person-s-status-over-two-time-points/m-p/120898#M33317</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I tried the following doing fiscal year, but it sort of worked and didn't work.&lt;/P&gt;&lt;P&gt;#1 It seems to be working - it's creating multiple year records. But the yr2 parameter is read in as say "2005+1" or "2006+1", so it isn't creating the right records - For one, year 2005 records aren't outputted.&lt;/P&gt;&lt;P&gt;#2 The code seems not very efficient as it is reading each record 6 times. If I've a large dataset or have a large time span (say from 1950 to 2011), the program is not very efficient.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hopefully people have solutions to at least #1 above. Thanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro try;&lt;/P&gt;&lt;P&gt;data bb;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set aa;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; format year best.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do i = 2005 %to 2011;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let yr1 = &amp;amp;i;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let yr2= &amp;amp;i.+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if START &amp;lt;= "31Mar&amp;amp;yr2."d and (END &amp;gt;="01Apr&amp;amp;yr1."d or END=.) then do;&amp;nbsp; *need END=. to accommodate those who have open end date;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; year=&amp;amp;yr1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;%mend try;&lt;/P&gt;&lt;P&gt;%try;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;p.s. I thought the following would work but it didn't work (year values aren't outputted).&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;%do i = 2005 %to 2011 and j=2006 %to 2012;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let yr1 = &amp;amp;i;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let yr2= &amp;amp;j;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Sep 2012 22:01:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Do-loop-to-find-a-person-s-status-over-two-time-points/m-p/120898#M33317</guid>
      <dc:creator>Solph</dc:creator>
      <dc:date>2012-09-12T22:01:14Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop to find a person's status over two time points?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Do-loop-to-find-a-person-s-status-over-two-time-points/m-p/120899#M33318</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It can be done this way :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;data aa; &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;format id best. start end yymmdd10.;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;input id start yymmdd10. end yymmdd10.;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;datalines;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;1 2006-05-05 2006-06-30&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;2 2006-02-05 2006-05-30&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;3 2006-09-01 2008-11-30&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;4 2006-03-31 2009-2-28&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;proc sort data=aa; by id; run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;data fiscalYears(keep=id year);&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;set aa;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;do year = year(intnx("YEAR.4",start,0)) to year(intnx("YEAR.4",end,0));&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt; output;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt; end;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;data calendarYears(keep=id year);&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;set aa;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;do year = year(start) to year(end);&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt; output;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt; end;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;data bothYears(keep=id fYear cYear);&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;merge fiscalYears (in=inf) calendarYears (in=inc) ;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;by id year;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;if inf then fYear = year;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;if inc then cYear = year;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;proc print; run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Sep 2012 00:34:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Do-loop-to-find-a-person-s-status-over-two-time-points/m-p/120899#M33318</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2012-09-13T00:34:35Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop to find a person's status over two time points?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Do-loop-to-find-a-person-s-status-over-two-time-points/m-p/120900#M33319</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If I understand what you mean .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data aa;
format id best. start end yymmdd10.;
input id start yymmdd10. end yymmdd10.;
datalines;
1 2006-05-05 2006-06-30
2 2006-02-05 2006-05-30
3 2006-09-01 2008-11-30
4 2006-03-31 2009-2-28
;
run;
data want(drop=i s e);
 set aa;
 s=mdy(4,1,year(start));
 e=mdy(4,1,year(end));
 if start lt s then do; fyear=year(start)-1; output;end;
 do i=year(start) to year(end)-1;
&amp;nbsp; fyear=i;cyear=i;output;
 end;
 cyear=year(end);
 if end lt e then call missing(fyear);
&amp;nbsp; else fyear=cyear;
 output;
run;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Sep 2012 04:41:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Do-loop-to-find-a-person-s-status-over-two-time-points/m-p/120900#M33319</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-09-13T04:41:43Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop to find a person's status over two time points?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Do-loop-to-find-a-person-s-status-over-two-time-points/m-p/120901#M33320</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data fy cy;&lt;/P&gt;&lt;P&gt;format id best. start end yymmdd10.;&lt;/P&gt;&lt;P&gt;input id start :yymmdd10. end :yymmdd10.;&lt;/P&gt;&lt;P&gt;nfy=intck('month12.4',start,end);&lt;/P&gt;&lt;P&gt;ncy=intck('year',start,end);&lt;/P&gt;&lt;P&gt;do i=0 to nfy;&lt;/P&gt;&lt;P&gt;fy=year(intnx('month12.4',start,i));&lt;/P&gt;&lt;P&gt;output fy;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;fy=.;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;do i=0 to ncy;&lt;/P&gt;&lt;P&gt;cy=year(intnx('year',start,i));&lt;/P&gt;&lt;P&gt;output cy;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1 2006-05-05 2006-06-30&lt;/P&gt;&lt;P&gt;2 2006-02-05 2006-05-30&lt;/P&gt;&lt;P&gt;3 2006-09-01 2008-11-30&lt;/P&gt;&lt;P&gt;4 2006-03-31 2009-2-28&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table want as &lt;/P&gt;&lt;P&gt;&amp;nbsp; select coalesce(fy.id,cy.id) as id, fy.fy,cy.cy from&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; fy (keep=id fy) full join cy (keep=id cy)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; on fy.id=cy.id and fy.fy=cy.cy;&lt;/P&gt;&lt;P&gt;&amp;nbsp; quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Sep 2012 06:53:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Do-loop-to-find-a-person-s-status-over-two-time-points/m-p/120901#M33320</guid>
      <dc:creator>AUTigers</dc:creator>
      <dc:date>2012-09-13T06:53:45Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop to find a person's status over two time points?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Do-loop-to-find-a-person-s-status-over-two-time-points/m-p/120902#M33321</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Solph,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The more I look at your desired outcome, the more I question if that is what you should aim for.&amp;nbsp; For example, why should calendar year always equal fiscal year (or be missing).&amp;nbsp; There are some periods when they would be different.&amp;nbsp; Consider the time period for ID=year and FYear=CYear=2007.&amp;nbsp; Shouldn't that really be broken down into multiple time periods?&amp;nbsp; One block of months would have FYear=2007 and CYear=2007, but another block of months would have FYear=2006 and CYear=2007.&amp;nbsp; At any rate, here is a program that works slightly differently and breaks the data down into more blocks.&amp;nbsp; (Thanks to AUTigers for looking up the syntax for intnx using month12.4.)&amp;nbsp; Think about whether this result might better suit your needs:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; input id start : yymmdd10. end : yymmdd10.;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; n_months = intck('month', start, end);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; fyear = year( intnx('month12.4', start, 0) );&lt;BR /&gt;&amp;nbsp;&amp;nbsp; cyear = year(start);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; do _n_=1 to n_months;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; test_date = intnx('month', start, _n_);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; test_fyear = year( intnx('month12.4', test_date, 0) );&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; test_cyear = year(test_date);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (test_fyear ne fyear) or (test_cyear ne cyear) then do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fyear = test_fyear;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cyear = test_cyear;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp; * put cyear= fyear=;&lt;BR /&gt;&amp;nbsp; * put n_months=;&lt;BR /&gt;&amp;nbsp; keep id fyear cyear start end;&lt;BR /&gt;&amp;nbsp; format start end yymmdd10.;&lt;BR /&gt;datalines;&lt;BR /&gt;1 2006-05-05 2006-06-30&lt;BR /&gt;2 2006-02-05 2006-05-30&lt;BR /&gt;3 2006-09-01 2008-11-30&lt;BR /&gt;4 2006-03-31 2009-02-28&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;proc print; &lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Obs&amp;nbsp;&amp;nbsp;&amp;nbsp; id&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; start&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end&amp;nbsp;&amp;nbsp;&amp;nbsp; fyear&amp;nbsp;&amp;nbsp;&amp;nbsp; cyear&lt;/P&gt;&lt;P&gt;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 2006-05-05&amp;nbsp;&amp;nbsp;&amp;nbsp; 2006-06-30&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2006&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2006&lt;BR /&gt;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp; 2006-02-05&amp;nbsp;&amp;nbsp;&amp;nbsp; 2006-05-30&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2005&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2006&lt;BR /&gt;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp; 2006-02-05&amp;nbsp;&amp;nbsp;&amp;nbsp; 2006-05-30&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2006&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2006&lt;BR /&gt;&amp;nbsp; 4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp; 2006-09-01&amp;nbsp;&amp;nbsp;&amp;nbsp; 2008-11-30&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2006&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2006&lt;BR /&gt;&amp;nbsp; 5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp; 2006-09-01&amp;nbsp;&amp;nbsp;&amp;nbsp; 2008-11-30&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2006&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2007&lt;BR /&gt;&amp;nbsp; 6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp; 2006-09-01&amp;nbsp;&amp;nbsp;&amp;nbsp; 2008-11-30&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2007&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2007&lt;BR /&gt;&amp;nbsp; 7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp; 2006-09-01&amp;nbsp;&amp;nbsp;&amp;nbsp; 2008-11-30&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2007&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2008&lt;BR /&gt;&amp;nbsp; 8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp; 2006-09-01&amp;nbsp;&amp;nbsp;&amp;nbsp; 2008-11-30&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2008&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2008&lt;BR /&gt;&amp;nbsp; 9&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&amp;nbsp;&amp;nbsp; 2006-03-31&amp;nbsp;&amp;nbsp;&amp;nbsp; 2009-02-28&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2005&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2006&lt;BR /&gt; 10&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&amp;nbsp;&amp;nbsp; 2006-03-31&amp;nbsp;&amp;nbsp;&amp;nbsp; 2009-02-28&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2006&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2006&lt;BR /&gt; 11&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&amp;nbsp;&amp;nbsp; 2006-03-31&amp;nbsp;&amp;nbsp;&amp;nbsp; 2009-02-28&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2006&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2007&lt;BR /&gt; 12&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&amp;nbsp;&amp;nbsp; 2006-03-31&amp;nbsp;&amp;nbsp;&amp;nbsp; 2009-02-28&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2007&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2007&lt;BR /&gt; 13&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&amp;nbsp;&amp;nbsp; 2006-03-31&amp;nbsp;&amp;nbsp;&amp;nbsp; 2009-02-28&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2007&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2008&lt;BR /&gt; 14&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&amp;nbsp;&amp;nbsp; 2006-03-31&amp;nbsp;&amp;nbsp;&amp;nbsp; 2009-02-28&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2008&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2008&lt;BR /&gt; 15&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&amp;nbsp;&amp;nbsp; 2006-03-31&amp;nbsp;&amp;nbsp;&amp;nbsp; 2009-02-28&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2008&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2009&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Sep 2012 14:02:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Do-loop-to-find-a-person-s-status-over-two-time-points/m-p/120902#M33321</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2012-09-13T14:02:42Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop to find a person's status over two time points?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Do-loop-to-find-a-person-s-status-over-two-time-points/m-p/120903#M33322</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for everyone. It took me a while to digest your codes as I was not familiar with the INTNX function. And seeing how you (PGState, AUTigers and Astounding) used the function (similarly and differently) I can see how useful it is and it took me a while to get my head around it. Even it took me a while to go through Ksharp's neat code. All helped and worked perfectly. As to Astounding's question why I didn't consider the block, I can see the usefulness of it. It's just that often times we analyze data (say counting people) by either by fiscal year or by calendar year, and rarely both. I'm just hoping to consider both in one dataset so that I've the flexibility of using one or other (but not both). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It's such a great community to seek help. Thanks everyone.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Sep 2012 20:43:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Do-loop-to-find-a-person-s-status-over-two-time-points/m-p/120903#M33322</guid>
      <dc:creator>Solph</dc:creator>
      <dc:date>2012-09-13T20:43:02Z</dc:date>
    </item>
  </channel>
</rss>

