<?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: date series from start and end dates. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/date-series-from-start-and-end-dates/m-p/476294#M122547</link>
    <description>&lt;P&gt;You say you want "parameters" but you are not showing any code that is using these "parameters".&lt;/P&gt;
&lt;P&gt;Instead you appear to want to create macro variables.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How will the macro variables be used?&amp;nbsp; Why not just leave the value in a dataset?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to make a numbered series it is probably easier to use an iterative DO loop instead of rolling your own loop.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do month = 1 to intck('month',start,end) ;
...
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;If you do need to make macro variables then use the CALL SYMPUTX() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do month = 1 to intck('month',start,end) ;
  call symputx(cats('M',month),put(intnx('month',start,i),yymmn4.));
end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 08 Jul 2018 16:39:28 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-07-08T16:39:28Z</dc:date>
    <item>
      <title>date series from start and end dates.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-series-from-start-and-end-dates/m-p/476278#M122540</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;I want to create&amp;nbsp;a date series from start and end dates.&lt;/P&gt;&lt;P&gt;I know how to do it and you can see the &amp;nbsp;code below.&lt;/P&gt;&lt;P&gt;I need to do further task and I don;t know how to do it.&lt;/P&gt;&lt;P&gt;I want to create a list of parameters called: &amp;nbsp;m0 &amp;nbsp;m1 &amp;nbsp;m2 &amp;nbsp;m3......etc that will receive the values from table&amp;nbsp;&lt;STRONG&gt;want_month.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;So will we get&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%put &amp;amp;m0.; /*1707*/&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%put &amp;amp;m1.; /*1708*/&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%put &amp;amp;m1.; /*1709*/&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;and so on.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%let start=1707;&lt;BR /&gt;%let end=1803;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data want_month;&lt;BR /&gt;ddate=&amp;amp;start_date.;&lt;BR /&gt;do while (ddate&amp;lt;=&amp;amp;end_date.);&lt;BR /&gt;output;&lt;BR /&gt;ddate=intnx('month', ddate, 1, 's');&lt;BR /&gt;end;&lt;BR /&gt;format ddate YYMMn4.;&lt;BR /&gt;run;&lt;BR /&gt;data want_month2;&lt;BR /&gt;Set want_month;&lt;BR /&gt;char_ddate=put(ddate,YYMMn4.);&lt;BR /&gt;Run;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Jul 2018 12:11:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-series-from-start-and-end-dates/m-p/476278#M122540</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-07-08T12:11:54Z</dc:date>
    </item>
    <item>
      <title>Re: date series from start and end dates.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-series-from-start-and-end-dates/m-p/476292#M122545</link>
      <description>&lt;P&gt;OK taking you at your word that you know how to get the values to assign, you could add to your final DATA step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want_month2;&lt;/P&gt;
&lt;P&gt;set want_month;&lt;/P&gt;
&lt;P&gt;char_ddate = put(ddate, YYMMn4.);&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;call symputx('m' || put(mon,z2.), char_ddate);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;mon + 1;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;drop mon;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This actually adds a zero so the parameter names are &amp;amp;m00 &amp;amp;m01 &amp;amp;m02 ... probably a good idea if you ever have a year's worth of data.&amp;nbsp; But if you don't like that and know that you will never need two-digit years, you can always use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;put(mon, 1.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;instead of&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;put(mon, z2.)&lt;/P&gt;</description>
      <pubDate>Sun, 08 Jul 2018 16:00:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-series-from-start-and-end-dates/m-p/476292#M122545</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-07-08T16:00:25Z</dc:date>
    </item>
    <item>
      <title>Re: date series from start and end dates.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-series-from-start-and-end-dates/m-p/476294#M122547</link>
      <description>&lt;P&gt;You say you want "parameters" but you are not showing any code that is using these "parameters".&lt;/P&gt;
&lt;P&gt;Instead you appear to want to create macro variables.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How will the macro variables be used?&amp;nbsp; Why not just leave the value in a dataset?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to make a numbered series it is probably easier to use an iterative DO loop instead of rolling your own loop.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do month = 1 to intck('month',start,end) ;
...
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;If you do need to make macro variables then use the CALL SYMPUTX() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do month = 1 to intck('month',start,end) ;
  call symputx(cats('M',month),put(intnx('month',start,i),yymmn4.));
end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 08 Jul 2018 16:39:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-series-from-start-and-end-dates/m-p/476294#M122547</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-07-08T16:39:28Z</dc:date>
    </item>
    <item>
      <title>Re: date series from start and end dates.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-series-from-start-and-end-dates/m-p/476350#M122582</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;Thanks for nice answers.&lt;/P&gt;&lt;P&gt;I found the best code that is working well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let start=1701;&lt;BR /&gt;%let end=1803;&lt;/P&gt;&lt;P&gt;%let date_start=%sysfunc(inputn(&amp;amp;start.,yymmn4.));&lt;BR /&gt;%let date_end=%sysfunc(inputn(&amp;amp;end.,yymmn4.));&lt;BR /&gt;%put &amp;amp;date_start.;&lt;BR /&gt;%put &amp;amp;date_end.;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Data want_month;&lt;BR /&gt;do j=0 to intck('month',&amp;amp;date_start.,&amp;amp;date_end.) ;&lt;BR /&gt;ddate=intnx('month', &amp;amp;date_start., j, 's');&lt;BR /&gt;char_ddate = put(ddate, YYMMn4.);&lt;BR /&gt;/*Var_Macro_name=compress('m'||put(J,2.));*/&lt;BR /&gt;Var_Macro_name='m'||strip(put(J,2.));&lt;BR /&gt;call symputx('m'||strip(put(J,2.)), char_ddate);&lt;BR /&gt;output;&lt;BR /&gt;end;&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 2 other problems:&lt;/P&gt;&lt;P&gt;Problem1-&lt;/P&gt;&lt;P&gt;I want to calculate number of months between start and end and create a sas macro variable with this value.&lt;/P&gt;&lt;P&gt;One way to do it is working well.&lt;/P&gt;&lt;P&gt;PROC SQL Noprint;&lt;BR /&gt;select count(*) INTO:n&lt;BR /&gt;from want_month&lt;BR /&gt;;&lt;BR /&gt;QUIT;&lt;BR /&gt;%put &amp;amp;n.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried to do it in open code but didn't succeed&lt;/P&gt;&lt;P&gt;%let n=%sysfunc(intck('month',&amp;amp;date_start.,&amp;amp;date_end.));&lt;/P&gt;&lt;P&gt;/*Here we have a problem and we get in log a message:&lt;BR /&gt;WARNING: An argument to the function INTCK referenced&lt;BR /&gt;by the %SYSFUNC or %QSYSFUNC macro function is out of range.*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Problem2-&lt;/P&gt;&lt;P&gt;I want to see sas macro varaibles values in log.&lt;/P&gt;&lt;P&gt;%put &amp;amp;m0;&lt;BR /&gt;%put &amp;amp;m1;&lt;BR /&gt;%put &amp;amp;m2;&lt;BR /&gt;%put &amp;amp;m3;&lt;BR /&gt;%put &amp;amp;m4;&lt;BR /&gt;%put &amp;amp;m14;&lt;BR /&gt;%PUT &amp;amp;&amp;amp;m&amp;amp;n..;&lt;BR /&gt;/*Here there is a problem and I don't get value of macro varaible m15*/&lt;BR /&gt;/*In log we can see :&lt;BR /&gt;WARNING: Apparent symbolic reference M not resolved.&lt;BR /&gt;&amp;amp;m 15.*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jul 2018 05:07:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-series-from-start-and-end-dates/m-p/476350#M122582</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-07-09T05:07:59Z</dc:date>
    </item>
    <item>
      <title>Re: date series from start and end dates.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-series-from-start-and-end-dates/m-p/476351#M122583</link>
      <description>&lt;P&gt;When I say that I need to careate SAS macro varaibles m0,m1,m2,m3...... there is a reason for that.&lt;/P&gt;&lt;P&gt;I have input SAS data sets that are created every month.&lt;/P&gt;&lt;P&gt;I need to use only tables for specific months that are defined by user.&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;%let start=1612;&lt;/P&gt;&lt;P&gt;%let end=1803;&lt;/P&gt;&lt;P&gt;It means that I will use following tables: tbl_1612,tbl_1701,tbl_1702....................tbl_1803.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro mmacro;&lt;BR /&gt;%DO j=1 %TO &amp;amp;n.;&lt;BR /&gt;PROC SQL;&lt;BR /&gt;create table tbl2_&amp;amp;&amp;amp;m&amp;amp;j.. &amp;nbsp; as&lt;BR /&gt;select *&lt;BR /&gt;from tbl_&amp;amp;&amp;amp;m&amp;amp;j..&lt;/P&gt;&lt;P&gt;where &amp;nbsp; out_condition...........&lt;BR /&gt;;&lt;BR /&gt;QUIT;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;BR /&gt;%mmacro;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jul 2018 05:17:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-series-from-start-and-end-dates/m-p/476351#M122583</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-07-09T05:17:14Z</dc:date>
    </item>
    <item>
      <title>Re: date series from start and end dates.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-series-from-start-and-end-dates/m-p/476364#M122593</link>
      <description>&lt;P&gt;You don't need macro variable lists for that. Instead wrap your code into a simple macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro do_once(period);

proc sql;
create table tbl2_&amp;amp;period. as
select *
from tbl_&amp;amp;period.
where out_condition...........
;
quit;

%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and then call that macro from a do loop:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let start=1612;
%let end=1803;

data _null_;
start_date = input("&amp;amp;start",yymmn4.);
end_date = input("&amp;amp;end",yymmn4.);
do until (start_date &amp;gt; end_date);
  call execute('%nrstr(%do_once(' !! put(start_date,yymmn4.) !! '));');
  start_date = intnx('month',start_date,1,'s');
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Jul 2018 06:26:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-series-from-start-and-end-dates/m-p/476364#M122593</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-07-09T06:26:52Z</dc:date>
    </item>
  </channel>
</rss>

