<?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 Create series if macro varaibles for dates values in data set in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-series-if-macro-varaibles-for-dates-values-in-data-set/m-p/498951#M132695</link>
    <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I have a data set that contain dates( This data set is created automatically by enter start and end dates ).&lt;/P&gt;
&lt;P&gt;The task is to create sas macro varaibles:&lt;/P&gt;
&lt;P&gt;First date value will be in macro varaible called: m1&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;second&amp;nbsp;date value will be in macro varaible called: m2&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;and do on&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;How can I do it please?&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*create date series from start and end dates*/
%let start_date=01sep2017;
%let end_date=01sep2018;


/*create dates series from start and end dates-Jump in months*/
data want_month;
date="&amp;amp;start_date"d;
date_char=put("&amp;amp;start_date"d,yymmn4.);
do while (date&amp;lt;="&amp;amp;end_date"d);
    output;
    date=intnx('month', date, 1, 's');
	date_char=put(date,yymmn4.);
end;
format date yymmn4.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;s&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 26 Sep 2018 05:20:57 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2018-09-26T05:20:57Z</dc:date>
    <item>
      <title>Create series if macro varaibles for dates values in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-series-if-macro-varaibles-for-dates-values-in-data-set/m-p/498951#M132695</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I have a data set that contain dates( This data set is created automatically by enter start and end dates ).&lt;/P&gt;
&lt;P&gt;The task is to create sas macro varaibles:&lt;/P&gt;
&lt;P&gt;First date value will be in macro varaible called: m1&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;second&amp;nbsp;date value will be in macro varaible called: m2&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;and do on&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;How can I do it please?&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*create date series from start and end dates*/
%let start_date=01sep2017;
%let end_date=01sep2018;


/*create dates series from start and end dates-Jump in months*/
data want_month;
date="&amp;amp;start_date"d;
date_char=put("&amp;amp;start_date"d,yymmn4.);
do while (date&amp;lt;="&amp;amp;end_date"d);
    output;
    date=intnx('month', date, 1, 's');
	date_char=put(date,yymmn4.);
end;
format date yymmn4.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;s&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Sep 2018 05:20:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-series-if-macro-varaibles-for-dates-values-in-data-set/m-p/498951#M132695</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-09-26T05:20:57Z</dc:date>
    </item>
    <item>
      <title>Re: Create series if macro varaibles for dates values in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-series-if-macro-varaibles-for-dates-values-in-data-set/m-p/498953#M132696</link>
      <description>&lt;P&gt;Your data step can be simplified:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT_MONTH;
  do DATE="&amp;amp;start_date"d to "&amp;amp;end_date"d;
    DATE_CHAR=put(DATE,yymmn4.);
    output;
    DATE=intnx('month', DATE, 0, 'e');
  end;
  format DATE date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You don't need it to create the macro variables, but if you just want to add their creation as an extra benefit during the creation of the table, this works:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT_MONTH;
  do DATE="&amp;amp;start_date"d to "&amp;amp;end_date"d;
    DATE_CHAR=put(DATE,yymmn4.);
    output;
    N+1;
    call symput (catt('M',N),DATE_CHAR);
    DATE=intnx('month', DATE, 0, 'e');
  end;
  format DATE yymmn4.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Sep 2018 05:34:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-series-if-macro-varaibles-for-dates-values-in-data-set/m-p/498953#M132696</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-09-26T05:34:55Z</dc:date>
    </item>
    <item>
      <title>Re: Create series if macro varaibles for dates values in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-series-if-macro-varaibles-for-dates-values-in-data-set/m-p/498974#M132710</link>
      <description>&lt;P&gt;Thanks.&lt;/P&gt;
&lt;P&gt;When I run it I don't see the we get the desired outcome.&lt;/P&gt;
&lt;P&gt;As you can see &amp;amp;m0 &amp;nbsp;&amp;amp;m1 &amp;amp;m2 ......were not created&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let start_date=15sep2017;
%let end_date=01sep2018;


data WANT_MONTH;
  do DATE="&amp;amp;start_date"d to "&amp;amp;end_date"d;
    DATE_CHAR=put(DATE,yymmn4.);
    output;
    N+1;
    call symput (catt('M',N),DATE_CHAR);
    DATE=intnx('month', DATE, 0, 'e');
  end;
  format DATE yymmn4.;
run;
%put &amp;amp;m0;
%put &amp;amp;m1;
%put &amp;amp;m2;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Sep 2018 07:29:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-series-if-macro-varaibles-for-dates-values-in-data-set/m-p/498974#M132710</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-09-26T07:29:04Z</dc:date>
    </item>
    <item>
      <title>Re: Create series if macro varaibles for dates values in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-series-if-macro-varaibles-for-dates-values-in-data-set/m-p/498979#M132713</link>
      <description>&lt;P&gt;Where to start, ok the bit that gets ignored.&amp;nbsp; Putting data into lots of macro variables, especially numeric dates in character macro variables, is really really not a good idea.&lt;/P&gt;
&lt;P&gt;Onto your code.&amp;nbsp; N is never initialised, therefore is always missing.&amp;nbsp; It is also never retained anyways, so would not increment.&amp;nbsp; You do not need most of that code which consists of writing a dataset, as you do not use that dataset.&amp;nbsp; What is it you expect this code to do?&lt;/P&gt;
&lt;PRE&gt;DATE=intnx('month', DATE, 0, 'e');&lt;/PRE&gt;
&lt;P&gt;All that will do is set the date to be the end of the month, however your&amp;nbsp;loop is operating on days, numeric dates are the number of days since the cuttoff, so m0=day 0, m1=day 1, m2=day 2 - they are all in month Sep though, so the output will be number of days between start and stop = how many macro variables you create.&amp;nbsp; What I suspect you want is:&lt;/P&gt;
&lt;PRE&gt;%let start_date=15sep2017;
%let end_date=01sep2018;

data _null_;
  do i=1 to intck('month',"&amp;amp;start_date."d,"&amp;amp;end_date."d);
    call symput(cats('M',put(i,best.)),put(intnx('month',"&amp;amp;start_date."d,i,'e'),yymmn4.));
  end;
run;
%put &amp;amp;m0.;
%put &amp;amp;m1.;
%put &amp;amp;m2.;&lt;/PRE&gt;
&lt;P&gt;Do note to finish macro varaibles with a decimal point, and avoid coding in uppercase for readability.&amp;nbsp; And again, this really is not a good idea.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Sep 2018 07:57:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-series-if-macro-varaibles-for-dates-values-in-data-set/m-p/498979#M132713</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-09-26T07:57:58Z</dc:date>
    </item>
    <item>
      <title>Re: Create series if macro varaibles for dates values in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-series-if-macro-varaibles-for-dates-values-in-data-set/m-p/498980#M132714</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt; code works fine although it creates macrovariables m1 to m3.&lt;/P&gt;
&lt;P&gt;Il you want the macrovariables index to start from 0, just move the call symput&lt;/P&gt;
&lt;P&gt;above the N+1 instruction.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Sep 2018 07:59:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-series-if-macro-varaibles-for-dates-values-in-data-set/m-p/498980#M132714</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2018-09-26T07:59:41Z</dc:date>
    </item>
    <item>
      <title>Re: Create series if macro varaibles for dates values in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-series-if-macro-varaibles-for-dates-values-in-data-set/m-p/499293#M132838</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1. &lt;EM&gt;N is never initialised, therefore is always missing.&amp;nbsp;&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Not true. The increment operator works like the sum() function&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;2&lt;EM&gt;.It is also never retained anyways, so would not increment.&amp;nbsp;&amp;nbsp;&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Not true. The increment operator&amp;nbsp;takes care of this too.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;3.&lt;/SPAN&gt;&lt;EM&gt;First date value will be in macro varaible called: m1&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;second&amp;nbsp;date value will be in macro varaible called: m2&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;EM&gt;As you can see &amp;amp;m0 &amp;nbsp;&amp;amp;m1 &amp;amp;m2 ......were not created&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Not true. The program provided works as per the requirements.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let start_date=01sep2017;
%let end_date  =01sep2018;
data WANT_MONTH;
  do DATE="&amp;amp;start_date"d to "&amp;amp;end_date"d;
    DATE_CHAR=put(DATE,yymmn4.);
    output;
    N+1;
    call symput (catt('M',N),DATE_CHAR);
    DATE=intnx('month', DATE, 0, 'e');
  end;
  format DATE yymmn4.;
run;
%put &amp;amp;=m1 &amp;amp;=m3;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;M1=1709 M3=1711&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Sep 2018 02:20:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-series-if-macro-varaibles-for-dates-values-in-data-set/m-p/499293#M132838</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-09-27T02:20:46Z</dc:date>
    </item>
  </channel>
</rss>

