<?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: How to do a macro which could apply to multiple years and months? in Advanced Programming</title>
    <link>https://communities.sas.com/t5/Advanced-Programming/How-to-do-a-macro-which-could-apply-to-multiple-years-and-months/m-p/700050#M25</link>
    <description>&lt;P&gt;That data structure is hiding two critical pieces of data: the year and the month of a whatever the indicator means.&lt;/P&gt;
&lt;P&gt;You may be better off with data such as&lt;/P&gt;
&lt;PRE&gt;data work2018;
input patientid $4. indicator_month1-indicator_month12 eventdate mmddyy10.;
format eventdate mmddyy10.;
datalines;
001 0 0 0 1 1 1 1 1 1 1 1 1 03/19/2018
002 1 1 1 1 1 1 1 1 1 1 1 1 09/01/2018
003 0 0 0 0 0 0 0 0 0 0 1 1 02/20/2019
004 1 1 1 1 1 1 1 1 1 1 1 1 12/12/2019
;
run;

data need;
   set work2018;
   array ind (*) indicator_: ;
   do i=1 to dim(ind);
      if ind[i]=1 then do;
        indicatordate= mdy(i,1,2018);
        output;
      end;

   end;
   format indicatordate mmddyy10.;
   keep patientid eventdate indicatordate;
run;

 data want;
    set need;
    if intck ('month',indicatordate,eventdate) le 6;
run;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So now you can use Indicatordate along with any other date of interest to calculate intervals, duration or keep/exclude. To work across years make "need" data sets from each of the year data sets and then combine them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The above code finds all the "indicator months" within the given range of 6 months. Up to you to use that to "exclude" or do anything else.&lt;/P&gt;</description>
    <pubDate>Wed, 18 Nov 2020 23:32:41 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-11-18T23:32:41Z</dc:date>
    <item>
      <title>How to do a macro which could apply to multiple years and months?</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/How-to-do-a-macro-which-could-apply-to-multiple-years-and-months/m-p/699877#M17</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;I am working on a project. If a patient had an event in Jan 2016, I need to make sure this patient did not have another indicator within 6 months prior to Jan 2016. Wondering how to create a macro which could be applied to multiple years and months? For example, events from Jan 2016 to Dec 2018?&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;&lt;P&gt;My codes:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;if event_month = &lt;STRONG&gt;1&lt;/STRONG&gt; and event_year = &lt;STRONG&gt;2016&lt;/STRONG&gt; then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;/* drop if indicator not in 0 */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;if indicator12_2015 not in ("0") then drop = &lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;if indicator11_2015 not in ("0") then drop = &lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;if indicator10_2015 not in ("0") then drop = &lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if indicator9_2015 not in ("0") then drop = &lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;if indicator8_2015 not in ("0") then drop = &lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;if indicator7_2015 not in ("0") then drop = &lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if drop = 1 then delete;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Nov 2020 16:35:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/How-to-do-a-macro-which-could-apply-to-multiple-years-and-months/m-p/699877#M17</guid>
      <dc:creator>wantonxia</dc:creator>
      <dc:date>2020-11-18T16:35:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a macro which could apply to multiple years and months?</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/How-to-do-a-macro-which-could-apply-to-multiple-years-and-months/m-p/699886#M18</link>
      <description>&lt;P&gt;Since you have data in the variable name for all those indicator variables then your data structure is likely making this much harder than it should be.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You would be better off with a structure that has a variable named "date of event", with an actual date value and one record per person event. Then this becomes fairly easy. SAS has functions to compare date intervals directly.&lt;/P&gt;
&lt;P&gt;With that suggested structure you could identify records within 6 months with something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if intck('month',dateofevent, "01JAN2016"d) le 6 then &amp;lt;do whatever&amp;gt;.&lt;/P&gt;
&lt;P&gt;A "macro" would then allow you dynamically replace the reference date and the number of months very easily.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your current structure would be a moving target of variable names and ugly ones at that.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Nov 2020 16:47:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/How-to-do-a-macro-which-could-apply-to-multiple-years-and-months/m-p/699886#M18</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-11-18T16:47:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a macro which could apply to multiple years and months?</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/How-to-do-a-macro-which-could-apply-to-multiple-years-and-months/m-p/699891#M19</link>
      <description>&lt;P&gt;Adding to what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;said, you probably could transpose the data somehow to a much more agreeable format, and then the coding is simple.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Nov 2020 16:57:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/How-to-do-a-macro-which-could-apply-to-multiple-years-and-months/m-p/699891#M19</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-11-18T16:57:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a macro which could apply to multiple years and months?</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/How-to-do-a-macro-which-could-apply-to-multiple-years-and-months/m-p/699907#M20</link>
      <description>&lt;P&gt;Hi ballardw,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much for your help! It makes sense. Could I ask one more questions please?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I got it that I'd better to use dateofevent and&lt;SPAN&gt;&amp;nbsp;intck('month',dateofevent, &lt;STRONG&gt;"01JAN2016"d)&lt;/STRONG&gt; le 6. However, I am not sure how to use the monthly indicator instead of&amp;nbsp;&lt;STRONG&gt;"01JAN2016"d.&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is the further clarification of my data. Actually, in my data, it's not like&amp;nbsp;&lt;SPAN&gt;indicator12_2015 or&amp;nbsp;indicator11_2015. The format is indicator 1- indicator12 for each month (indication 1 is Jan, and indicator 12 is Dec) of each year (dummy variable, 1=yes, and 0=No). In addition, I do have the date of event. My goal is to measure whether the patients had '0' in each monthly indicator within 6 months prior to the date of event.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Please let me know if I did not explain it clearly and happy to clarify. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks again!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Nov 2020 17:38:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/How-to-do-a-macro-which-could-apply-to-multiple-years-and-months/m-p/699907#M20</guid>
      <dc:creator>wantonxia</dc:creator>
      <dc:date>2020-11-18T17:38:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a macro which could apply to multiple years and months?</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/How-to-do-a-macro-which-could-apply-to-multiple-years-and-months/m-p/699910#M21</link>
      <description>&lt;P&gt;So each observation covers a whole year? Is that year stored in another variable in that observation?&lt;/P&gt;</description>
      <pubDate>Wed, 18 Nov 2020 17:42:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/How-to-do-a-macro-which-could-apply-to-multiple-years-and-months/m-p/699910#M21</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-18T17:42:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a macro which could apply to multiple years and months?</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/How-to-do-a-macro-which-could-apply-to-multiple-years-and-months/m-p/699917#M22</link>
      <description>&lt;P&gt;Agree. I just updated my question. Thank you for your help!&lt;/P&gt;</description>
      <pubDate>Wed, 18 Nov 2020 17:55:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/How-to-do-a-macro-which-could-apply-to-multiple-years-and-months/m-p/699917#M22</guid>
      <dc:creator>wantonxia</dc:creator>
      <dc:date>2020-11-18T17:55:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a macro which could apply to multiple years and months?</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/How-to-do-a-macro-which-could-apply-to-multiple-years-and-months/m-p/699984#M23</link>
      <description>&lt;P&gt;Data&lt;/P&gt;
&lt;P&gt;Actual example data.&lt;/P&gt;
&lt;P&gt;I'm not sure that your description makes anything better.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the &amp;lt;/&amp;gt; icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Nov 2020 20:31:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/How-to-do-a-macro-which-could-apply-to-multiple-years-and-months/m-p/699984#M23</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-11-18T20:31:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a macro which could apply to multiple years and months?</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/How-to-do-a-macro-which-could-apply-to-multiple-years-and-months/m-p/700016#M24</link>
      <description>&lt;P&gt;Hi ballardw,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry it was my first time to post a question and I did not know it. Thanks for your suggestion. Below is the datasets.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;/* Year 2017 */&lt;BR /&gt;data work2017;&lt;BR /&gt;input patientid $4. indicator_month1-indicator_month12 eventdate mmddyy10.;&lt;BR /&gt;format eventdate mmddyy10.;&lt;BR /&gt;datalines;&lt;BR /&gt;001 0 0 0 0 0 0 0 0 0 0 0 0 03/19/2018&lt;BR /&gt;002 0 1 1 1 1 1 1 1 1 1 1 1 09/01/2018&lt;BR /&gt;003 0 0 0 0 0 0 0 0 0 0 0 0 02/20/2019&lt;BR /&gt;004 0 0 0 0 0 0 1 1 1 1 1 1 12/12/2019&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;/* Year 2018 */&lt;BR /&gt;data work2018;&lt;BR /&gt;input patientid $4. indicator_month1-indicator_month12 eventdate mmddyy10.;&lt;BR /&gt;format eventdate mmddyy10.;&lt;BR /&gt;datalines;&lt;BR /&gt;001 0 0 0 1 1 1 1 1 1 1 1 1 03/19/2018&lt;BR /&gt;002 1 1 1 1 1 1 1 1 1 1 1 1 09/01/2018&lt;BR /&gt;003 0 0 0 0 0 0 0 0 0 0 1 1 02/20/2019&lt;BR /&gt;004 1 1 1 1 1 1 1 1 1 1 1 1 12/12/2019&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* Year 2019 */&lt;BR /&gt;data work2019;&lt;BR /&gt;input patientid $4. indicator_month1-indicator_month12 eventdate mmddyy10.;&lt;BR /&gt;format eventdate mmddyy10.;&lt;BR /&gt;datalines;&lt;BR /&gt;001 1 1 1 1 1 1 1 1 1 1 0 0 03/19/2018&lt;BR /&gt;002 1 1 1 1 1 1 1 1 1 1 1 1 09/01/2018&lt;BR /&gt;003 0 1 1 1 1 1 1 1 0 0 0 0 02/20/2019&lt;BR /&gt;004 1 1 1 1 0 0 0 0 0 0 0 0 12/12/2019&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have three years of data. It includes patient ID, date of event, and indicator month. In each year, indicator month is from 1-12, which represents Jan to Dec of this year. My goal is: if a patient had at least a indicator value=1 within 6 month prior to the event month, this patient will be excluded. For example, Patient 003's event date was 02/20/2019,&amp;nbsp; I need to find the value of indicator_month from August 2018 to Jan 2019, and found this patient had indicator_month11=1 and indicator_month_12=1 in 2018 and indicator_month_1 =1 in 2019. So this patient should be excluded.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please let me know if I am not explain it clearly and happy to further clarify it. Thanks again!&lt;/P&gt;</description>
      <pubDate>Wed, 18 Nov 2020 22:26:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/How-to-do-a-macro-which-could-apply-to-multiple-years-and-months/m-p/700016#M24</guid>
      <dc:creator>wantonxia</dc:creator>
      <dc:date>2020-11-18T22:26:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a macro which could apply to multiple years and months?</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/How-to-do-a-macro-which-could-apply-to-multiple-years-and-months/m-p/700050#M25</link>
      <description>&lt;P&gt;That data structure is hiding two critical pieces of data: the year and the month of a whatever the indicator means.&lt;/P&gt;
&lt;P&gt;You may be better off with data such as&lt;/P&gt;
&lt;PRE&gt;data work2018;
input patientid $4. indicator_month1-indicator_month12 eventdate mmddyy10.;
format eventdate mmddyy10.;
datalines;
001 0 0 0 1 1 1 1 1 1 1 1 1 03/19/2018
002 1 1 1 1 1 1 1 1 1 1 1 1 09/01/2018
003 0 0 0 0 0 0 0 0 0 0 1 1 02/20/2019
004 1 1 1 1 1 1 1 1 1 1 1 1 12/12/2019
;
run;

data need;
   set work2018;
   array ind (*) indicator_: ;
   do i=1 to dim(ind);
      if ind[i]=1 then do;
        indicatordate= mdy(i,1,2018);
        output;
      end;

   end;
   format indicatordate mmddyy10.;
   keep patientid eventdate indicatordate;
run;

 data want;
    set need;
    if intck ('month',indicatordate,eventdate) le 6;
run;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So now you can use Indicatordate along with any other date of interest to calculate intervals, duration or keep/exclude. To work across years make "need" data sets from each of the year data sets and then combine them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The above code finds all the "indicator months" within the given range of 6 months. Up to you to use that to "exclude" or do anything else.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Nov 2020 23:32:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/How-to-do-a-macro-which-could-apply-to-multiple-years-and-months/m-p/700050#M25</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-11-18T23:32:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a macro which could apply to multiple years and months?</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/How-to-do-a-macro-which-could-apply-to-multiple-years-and-months/m-p/700062#M26</link>
      <description>Thank you so much ballardw! I am very appreciated!</description>
      <pubDate>Thu, 19 Nov 2020 00:30:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/How-to-do-a-macro-which-could-apply-to-multiple-years-and-months/m-p/700062#M26</guid>
      <dc:creator>wantonxia</dc:creator>
      <dc:date>2020-11-19T00:30:01Z</dc:date>
    </item>
  </channel>
</rss>

