<?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 Do loop and Intck to get cases point in time in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-and-Intck-to-get-cases-point-in-time/m-p/665947#M199191</link>
    <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;Last week I asked a question about how to identify a list of cases present in a month between their entry date and discharge. See the code toward the end of post.&amp;nbsp;I'm wondering if I can recycle the code to, now, identify a list of cases present point in time, on 5 different dates:&amp;nbsp;April 1, June 30, Sept 30, Dec 31, and Mar 31. I think I can, but I can't exactly sure how to have it fixed. Any hint is appreciated.&lt;/P&gt;
&lt;P&gt;Here is the data I have and the "want" data for fiscal year 2017-2018 (Apr-Mar) in the right columns.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Get point in time on April 1, Jun 30, Sep 30, Dec 31, Mar 31;
data have; format entry_date discharge_date yymmdd10.; 
input id 1 @3 entry_date yymmdd10. @15 discharge_date yymmdd10. 
apr2017 jun2017 sep2017 dec2017 mar2018 apr2018 jun2018 sep2018 dec2018 mar2019
;
datalines;
1 2017-05-11  2018-08-25 0 1 1 1 1 1 1 0 0 0 
2 2017-04-01  2017-08-02 0 1 0 0 0 0 0 0 0 0
3 2018-05-11  2018-07-20 0 0 0 0 0 0 1 0 0 0
4 2016-01-05  2019-03-29 1 1 1 1 1 1 1 1 1 0 
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the code to identify a list of cases present in a month between their entry date and discharge.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; format entry_date discharge_date yymmdd10.; 
input id 1 @3 entry_date yymmdd10. @15 discharge_date yymmdd10. note $ 26-42;
datalines;
1 2017-05-11  2018-08-25 Active 2017,2018
2 2017-04-01  2017-08-02 Active 2017
3 2018-05-11  2018-07-20 Active 2018
4 2019-01-05  2019-04-29 Active 2018, 2019
5 2020-05-11  2020-05-20 Active 2020
6 2020-04-05  2020-06-02 Active 2020
;
quit;  
data want (keep=FYMO id);
    set have;
    x = intck("month", entry_date, discharge_date);
    format FYMO yymmn6.;
    do i = 0 to x;
        FYMO = intnx('month', entry_date, i, 'BEGINNING');
        output;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 29 Jun 2020 23:02:37 GMT</pubDate>
    <dc:creator>Solph</dc:creator>
    <dc:date>2020-06-29T23:02:37Z</dc:date>
    <item>
      <title>Do loop and Intck to get cases point in time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-and-Intck-to-get-cases-point-in-time/m-p/665947#M199191</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;Last week I asked a question about how to identify a list of cases present in a month between their entry date and discharge. See the code toward the end of post.&amp;nbsp;I'm wondering if I can recycle the code to, now, identify a list of cases present point in time, on 5 different dates:&amp;nbsp;April 1, June 30, Sept 30, Dec 31, and Mar 31. I think I can, but I can't exactly sure how to have it fixed. Any hint is appreciated.&lt;/P&gt;
&lt;P&gt;Here is the data I have and the "want" data for fiscal year 2017-2018 (Apr-Mar) in the right columns.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Get point in time on April 1, Jun 30, Sep 30, Dec 31, Mar 31;
data have; format entry_date discharge_date yymmdd10.; 
input id 1 @3 entry_date yymmdd10. @15 discharge_date yymmdd10. 
apr2017 jun2017 sep2017 dec2017 mar2018 apr2018 jun2018 sep2018 dec2018 mar2019
;
datalines;
1 2017-05-11  2018-08-25 0 1 1 1 1 1 1 0 0 0 
2 2017-04-01  2017-08-02 0 1 0 0 0 0 0 0 0 0
3 2018-05-11  2018-07-20 0 0 0 0 0 0 1 0 0 0
4 2016-01-05  2019-03-29 1 1 1 1 1 1 1 1 1 0 
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the code to identify a list of cases present in a month between their entry date and discharge.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; format entry_date discharge_date yymmdd10.; 
input id 1 @3 entry_date yymmdd10. @15 discharge_date yymmdd10. note $ 26-42;
datalines;
1 2017-05-11  2018-08-25 Active 2017,2018
2 2017-04-01  2017-08-02 Active 2017
3 2018-05-11  2018-07-20 Active 2018
4 2019-01-05  2019-04-29 Active 2018, 2019
5 2020-05-11  2020-05-20 Active 2020
6 2020-04-05  2020-06-02 Active 2020
;
quit;  
data want (keep=FYMO id);
    set have;
    x = intck("month", entry_date, discharge_date);
    format FYMO yymmn6.;
    do i = 0 to x;
        FYMO = intnx('month', entry_date, i, 'BEGINNING');
        output;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jun 2020 23:02:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-and-Intck-to-get-cases-point-in-time/m-p/665947#M199191</guid>
      <dc:creator>Solph</dc:creator>
      <dc:date>2020-06-29T23:02:37Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop and Intck to get cases point in time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-and-Intck-to-get-cases-point-in-time/m-p/665966#M199200</link>
      <description>&lt;P&gt;No too sure what the question is.&lt;/P&gt;
&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do D='01apr2017'd, '01jun2017'd, '01sep2017'd, '01dec2017'd, '01mar2018'd, '01apr2018'd, '01jun2018'd, '01sep2018'd, '01dec2018'd, '01mar2019'd;
  if  ENTRY_DATE &amp;lt;= D &amp;lt;= DISCHARGE_DATE then output;
end; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jun 2020 01:29:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-and-Intck-to-get-cases-point-in-time/m-p/665966#M199200</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-06-30T01:29:31Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop and Intck to get cases point in time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-and-Intck-to-get-cases-point-in-time/m-p/665983#M199206</link>
      <description>&lt;P&gt;Yes, it worked and I modified a bit to suit my needs. Thank a lot.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro loop;
%do year=2017 %to 2019;
	data want&amp;amp;year;
    set have;
	if discharge_date =. or discharge_date&amp;gt; "&amp;amp;enddt"d then discharge_date="&amp;amp;enddt"d;
	if  ENTRY_DATE &amp;lt;= "01apr&amp;amp;year."d &amp;lt;= DISCHARGE_DATE then ID01apr=1;
	if  ENTRY_DATE &amp;lt;= "30jun&amp;amp;year."d &amp;lt;= DISCHARGE_DATE then ID30jun=1;
	if  ENTRY_DATE &amp;lt;= "30sep&amp;amp;year."d &amp;lt;= DISCHARGE_DATE then ID30sep=1;
	if  ENTRY_DATE &amp;lt;= "31dec&amp;amp;year."d &amp;lt;= DISCHARGE_DATE then ID31dec=1;
	if  ENTRY_DATE &amp;lt;= "31mar%eval(&amp;amp;year+1)"d &amp;lt;= DISCHARGE_DATE then ID31mar=1;
	Fyear=&amp;amp;year;
	output want&amp;amp;year;
	run;
%end;
%mend;
%loop;
data want; set want2017-want2019; run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Jun 2020 03:24:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-and-Intck-to-get-cases-point-in-time/m-p/665983#M199206</guid>
      <dc:creator>Solph</dc:creator>
      <dc:date>2020-06-30T03:24:42Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop and Intck to get cases point in time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-and-Intck-to-get-cases-point-in-time/m-p/665987#M199208</link>
      <description>&lt;P&gt;Why several tables? And why a macro? Would something like this work?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;data WANT;
  set HAVE;
  do FYEAR=2017 to 2019;
    DISCHARGE_DATE = min(DISCHARGE_DATE, "&amp;amp;enddt"d);
    if ENTRY_DATE &amp;lt;= mdy( 4, 1, FYEAR)   &amp;lt;= DISCHARGE_DATE then ID01APR=1;
    if ENTRY_DATE &amp;lt;= mdy( 6, 1, FYEAR)   &amp;lt;= DISCHARGE_DATE then ID30JUN=1;
    if ENTRY_DATE &amp;lt;= mdy( 9, 1, FYEAR)   &amp;lt;= DISCHARGE_DATE then ID30SEP=1;
    if ENTRY_DATE &amp;lt;= mdy(12, 1, FYEAR)   &amp;lt;= DISCHARGE_DATE then ID31DEC=1;
    if ENTRY_DATE &amp;lt;= mdy( 3, 1, FYEAR+1) &amp;lt;= DISCHARGE_DATE then ID31MAR=1;
  end;
run;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jun 2020 04:38:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-and-Intck-to-get-cases-point-in-time/m-p/665987#M199208</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-06-30T04:38:08Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop and Intck to get cases point in time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-and-Intck-to-get-cases-point-in-time/m-p/665988#M199209</link>
      <description>&lt;P&gt;Even better if you want the zeros to be populated too:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;ID01APR = ( ENTRY_DATE &amp;lt;= mdy( 4, 1, FYEAR)   &amp;lt;= DISCHARGE_DATE ) ;&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 30 Jun 2020 04:40:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-and-Intck-to-get-cases-point-in-time/m-p/665988#M199209</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-06-30T04:40:14Z</dc:date>
    </item>
  </channel>
</rss>

