<?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: dynamic programming - creating date ranges in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/dynamic-programming-creating-date-ranges/m-p/175608#M33720</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Keep it simple.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%let start_date = 01Jul2012;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;%let end_date = 30Aug2013; /* not used */&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data testa;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;format svcBegDate date9.;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;svcBegDate = '05jul2012'd;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data testb;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;set testa;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;monYr = propcase(put(SvcBegDate, monyy7.));&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;order = 1 + intck("MONTH", "&amp;amp;start_date."d, svcBegDate);&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc print data=testb noobs; 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>Tue, 17 Dec 2013 17:27:41 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2013-12-17T17:27:41Z</dc:date>
    <item>
      <title>dynamic programming - creating date ranges</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dynamic-programming-creating-date-ranges/m-p/175606#M33718</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm looking to automate the piece of code below using macros, %sysfuc(), and do loops, but I'm not very well versed using&amp;nbsp; %sysfuc() and would appreciate your help. &lt;/P&gt;&lt;P&gt;I want to be able to set up 2 macro variables (something like: %let start_date = 01Jul2012; %let end_date = 30Aug2013;) and have the intervals bellow be constructed for me automatically. This is the hard code:&lt;/P&gt;&lt;P&gt;**************&lt;/P&gt;&lt;P&gt;data testb;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set testa;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if '01Jul2012'd&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;=SvcBegDate&amp;lt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '01Aug2012'd&amp;nbsp; then do; monyr="Jul2012" ; order=1;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if '01Aug2012'd&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;=SvcBegDate&amp;lt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '01Sep2012'd then do; monyr="Aug2012" ; order=2;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if '01Sep2012'd&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;=SvcBegDate&amp;lt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '01Oct2012'd then do; monyr="Sep2012" ; order=3;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if '01Oct2012'd&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;=SvcBegDate&amp;lt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '01Nov2012'd then do; monyr="Oct2012" ; order=4;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if '01Nov2012'd&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;=SvcBegDate&amp;lt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '01Dec2012'd then do; monyr="Nov2012" ; order=5;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if '01Dec2012'd&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;=SvcBegDate&amp;lt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '01Jan2013'd then do; monyr="Dec2012" ; order=6;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if '01Jan2013'd&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;=SvcBegDate&amp;lt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '01Feb2013'd then do; monyr="Jan2013" ; order=7;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if '01Feb2013'd&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;=SvcBegDate&amp;lt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '01Mar2013'd then do; monyr="Feb2013" ; order=8;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if '01Mar2013'd&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;=SvcBegDate&amp;lt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '01Apr2013'd then do; monyr="Mar2013" ; order=9;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if '01Apr2013'd&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;=SvcBegDate&amp;lt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '01May2013'd then do; monyr="Apr2013" ; order=10; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if '01May2013'd&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;=SvcBegDate&amp;lt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '01Jun2013'd then do; monyr="May2013" ; order=11; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if '01Jun2013'd&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;=SvcBegDate&amp;lt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '01Jul2013'd then do; monyr="Jun2013" ; order=12; end;&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;I've been playing around with the code below trying to automate it, but I'm not getting it right:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let start_date = 01Jul2012;&lt;/P&gt;&lt;P&gt;%let end_date = 30Aug2013;&lt;/P&gt;&lt;P&gt;%let start = %sysfunc(inputn(&amp;amp;start_date.,anydtdte9.));&lt;/P&gt;&lt;P&gt;%let end = %sysfunc(inputn(&amp;amp;end_date.,anydtdte9.));&lt;/P&gt;&lt;P&gt;%let dif = %sysfunc(intck(month,&amp;amp;start.,&amp;amp;end.));&lt;/P&gt;&lt;P&gt;%let date1 = %sysfunc(putn(%sysfunc(intnx(month,&amp;amp;start.,1,b)),date9.));&lt;/P&gt;&lt;P&gt;%let date1a = %sysfunc(intnx(month,&amp;amp;start.,1,b));&lt;/P&gt;&lt;P&gt;%let date_final = %sysfunc(putn(%sysfunc(intnx(month,&amp;amp;start.,2,b)),monyy7.)); &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data testb;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set testa;&lt;/P&gt;&lt;P&gt;do i = 0 to &amp;amp;dif.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if&amp;nbsp; %sysfunc(intnx(month,&amp;amp;start.,&amp;amp;i.,b)) &amp;lt;= SvcBegDate &amp;lt;&amp;nbsp; %sysfunc(intnx(month,&amp;amp;start.,&amp;amp;i.+1,b)) then do; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; monyr = %sysfunc(putn(%sysfunc(intnx(month,&amp;amp;start.,&amp;amp;i.,b)),monyy7.))); &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; order = &amp;amp;i.+1;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;END;&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;I would appreciate your help with this. Thanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Alex&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Dec 2013 16:58:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dynamic-programming-creating-date-ranges/m-p/175606#M33718</guid>
      <dc:creator>avbraga</dc:creator>
      <dc:date>2013-12-17T16:58:37Z</dc:date>
    </item>
    <item>
      <title>Re: dynamic programming - creating date ranges</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dynamic-programming-creating-date-ranges/m-p/175607#M33719</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If SvcBegDatea is a date in&amp;nbsp; dataset, why do you need all the macro functions to create this?&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's a non-macro solution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;set testa;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;monyr=put(SvcBegDate, monyy7.);&lt;/P&gt;&lt;P&gt;order=mod(month(SvcBegDate)+5, 12)+1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Dec 2013 17:19:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dynamic-programming-creating-date-ranges/m-p/175607#M33719</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2013-12-17T17:19:53Z</dc:date>
    </item>
    <item>
      <title>Re: dynamic programming - creating date ranges</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dynamic-programming-creating-date-ranges/m-p/175608#M33720</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Keep it simple.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%let start_date = 01Jul2012;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;%let end_date = 30Aug2013; /* not used */&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data testa;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;format svcBegDate date9.;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;svcBegDate = '05jul2012'd;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data testb;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;set testa;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;monYr = propcase(put(SvcBegDate, monyy7.));&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;order = 1 + intck("MONTH", "&amp;amp;start_date."d, svcBegDate);&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc print data=testb noobs; 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>Tue, 17 Dec 2013 17:27:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dynamic-programming-creating-date-ranges/m-p/175608#M33720</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2013-12-17T17:27:41Z</dc:date>
    </item>
    <item>
      <title>Re: dynamic programming - creating date ranges</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dynamic-programming-creating-date-ranges/m-p/175609#M33721</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Reeza,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for your help. This is good but not quite doing what I would like done. The order variable is grouping monyr by the month, so things like JUL2012 and JUL2013 are getting order=1, when it should be: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for JUL2012, order = 1,&lt;/P&gt;&lt;P&gt;for AUG2012, order = 2,&lt;/P&gt;&lt;P&gt;for SEP2012, order = 3,&lt;/P&gt;&lt;P&gt;..., etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you anyway, I liked the simplicity of your thinking.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Dec 2013 17:31:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dynamic-programming-creating-date-ranges/m-p/175609#M33721</guid>
      <dc:creator>avbraga</dc:creator>
      <dc:date>2013-12-17T17:31:58Z</dc:date>
    </item>
    <item>
      <title>Re: dynamic programming - creating date ranges</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dynamic-programming-creating-date-ranges/m-p/175610#M33722</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That did it, PG. Keeping it simple is good!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Dec 2013 17:37:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dynamic-programming-creating-date-ranges/m-p/175610#M33722</guid>
      <dc:creator>avbraga</dc:creator>
      <dc:date>2013-12-17T17:37:02Z</dc:date>
    </item>
  </channel>
</rss>

