<?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 use a macro to do a rolling in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-macro-to-do-a-rolling/m-p/141623#M28434</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am not quite sure how to use data step to achieve this. The reason I want to use macro is because I need to roll the data (pick different sample for each loop). As I mentioned, for example, for the first loop I would like to grab one year's data from &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;1970/01/01 to 1970/12/31&lt;/SPAN&gt;, after I get these year's data I can code and get one value, which is what I need. For the second loop, I would like to move forward to choose one year's data from &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;1970/02/01 to 1970/01/31&lt;/SPAN&gt; to calculate the second value. I would like to continue to move forward until sometime like 2010/1/1 to 2010/12/31 to get the last value. I want to create a variable and use macro to do a loop. something like %do i=&amp;amp;st %to &amp;amp;end, where st is starting point and end is the end point. I am not sure how to give an example since it's kind of complicated. But I hope you can understand what I want to achieve. I am not sure how to use data step. YOu can see that this will probably loop for more than 50 times.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 14 Nov 2013 06:46:39 GMT</pubDate>
    <dc:creator>SeanZ</dc:creator>
    <dc:date>2013-11-14T06:46:39Z</dc:date>
    <item>
      <title>How to use a macro to do a rolling</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-macro-to-do-a-rolling/m-p/141621#M28432</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;i have a date variable from 1970/01/01 to 2010/12/31. And stock returns for each day. What I want to do is that use one year as a rolling window. Use full year's returns to calculate a new variable and merge that variable as the next month's date after one year window. Specifically, I will achieve two tasks. The first one, use returns from 1970/01/01 to 1970/12/31 to calculate one value and use this value as 1971/01's value(monthly), next, use returns from 1970/02/01 to 1970/01/31 to calculate the second Value and use this value as 1979/02's value, and so on. The second task would be: use returns from 1970/01/01 to 1970/12/31 to get one value as 1971/01/01's value(daily), next use returns from 1970/01/02 to 1971/01/01 to get the second value for 1970/01/02's value, and so on. Also, not all dates are available. Weekends and holidays are not in the data set. That means I only have around 250 days in each year. How to setup a macro to do this?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Nov 2013 09:36:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-macro-to-do-a-rolling/m-p/141621#M28432</guid>
      <dc:creator>SeanZ</dc:creator>
      <dc:date>2013-11-13T09:36:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a macro to do a rolling</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-macro-to-do-a-rolling/m-p/141622#M28433</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why would you need a macro for this task?&lt;/P&gt;&lt;P&gt;There might be a few people here with enough subject matter expertise to fully understand what you want to achieve. For the rest of us: I suggest you provide a data step creating some sample data and then you show us how the result should look like.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Nov 2013 09:54:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-macro-to-do-a-rolling/m-p/141622#M28433</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2013-11-13T09:54:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a macro to do a rolling</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-macro-to-do-a-rolling/m-p/141623#M28434</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am not quite sure how to use data step to achieve this. The reason I want to use macro is because I need to roll the data (pick different sample for each loop). As I mentioned, for example, for the first loop I would like to grab one year's data from &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;1970/01/01 to 1970/12/31&lt;/SPAN&gt;, after I get these year's data I can code and get one value, which is what I need. For the second loop, I would like to move forward to choose one year's data from &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;1970/02/01 to 1970/01/31&lt;/SPAN&gt; to calculate the second value. I would like to continue to move forward until sometime like 2010/1/1 to 2010/12/31 to get the last value. I want to create a variable and use macro to do a loop. something like %do i=&amp;amp;st %to &amp;amp;end, where st is starting point and end is the end point. I am not sure how to give an example since it's kind of complicated. But I hope you can understand what I want to achieve. I am not sure how to use data step. YOu can see that this will probably loop for more than 50 times.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Nov 2013 06:46:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-macro-to-do-a-rolling/m-p/141623#M28434</guid>
      <dc:creator>SeanZ</dc:creator>
      <dc:date>2013-11-14T06:46:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a macro to do a rolling</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-macro-to-do-a-rolling/m-p/141624#M28435</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The following code will need good testing to verify that I've got the logic 100% correct - but it should give you the idea.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want the average instead of the sum then divide the sum by the number on non-missing array elements:&amp;nbsp;&amp;nbsp; n(of _amt(*))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;&amp;nbsp; format date date9.;&lt;BR /&gt;&amp;nbsp; do date='01jan1970'd to '31dec2012'd;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; amt=round(ranuni(1)*1000,0.01);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if weekday(date) not in (1,7) then output;&lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want(drop=_:);&lt;BR /&gt;&amp;nbsp; set have;&lt;BR /&gt;&amp;nbsp; by date;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain _start_date;&lt;BR /&gt;&amp;nbsp; format _start_date date9.;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp; if _n_=1 then _start_date=date;&lt;BR /&gt;&amp;nbsp; &lt;BR /&gt;&amp;nbsp; /* create an array to hold 1 year worth of data */&lt;BR /&gt;/*&amp;nbsp; array _amt {12,31} 8 ;*/&lt;BR /&gt;/*&amp;nbsp; retain _amt;*/&lt;BR /&gt;&amp;nbsp; array _amt {12,31} 8 _temporary_;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; _lag_date=lag(date);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if intck('year',_start_date,date) &amp;lt; 1 then &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* processing for the first year of data */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _amt[month(date),day(date)]=amt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; retain amt_yearsum_daily amt_yearsum_monthly;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; amt_yearsum_daily=sum(of _amt&lt;LI&gt;);&lt;/LI&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* first available date of month */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if intck('month',_lag_date,date)=1 then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; amt_yearsum_monthly=sum(of _amt&lt;LI&gt;);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* special logic to deal with leap years */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if month(_lag_date)=2 and day(intnx('month',_lag_date,-12,'b'))=29 then call missing(_amt[2,29]);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* populate array element with the new amt value from the input data set for the next iteration */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; _amt[month(date),day(date)]=amt;&lt;/LI&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* for gaps in the date: set all array elements to missing for which there is no new data available */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do _i=_lag_date+1 to date-1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call missing(_amt[month(_i),day(_i)]);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Nov 2013 10:01:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-macro-to-do-a-rolling/m-p/141624#M28435</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2013-11-14T10:01:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a macro to do a rolling</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-macro-to-do-a-rolling/m-p/141625#M28436</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Patrick. Thank you very much for your answer. That is enormous for me. I need some time to figure it out. But I do appreciate a lot for your work.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Nov 2013 05:28:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-macro-to-do-a-rolling/m-p/141625#M28436</guid>
      <dc:creator>SeanZ</dc:creator>
      <dc:date>2013-11-15T05:28:00Z</dc:date>
    </item>
  </channel>
</rss>

