<?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 write values generated in a macro statement to a global macro list? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-values-generated-in-a-macro-statement-to-a-global/m-p/675540#M203565</link>
    <description>&lt;P&gt;If you want to make things more efficient, don't use macro-code in cases that are easily solved by using simple data-steps.&lt;/P&gt;</description>
    <pubDate>Mon, 10 Aug 2020 06:53:17 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2020-08-10T06:53:17Z</dc:date>
    <item>
      <title>How to write values generated in a macro statement to a global macro list?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-values-generated-in-a-macro-statement-to-a-global/m-p/675538#M203564</link>
      <description>&lt;P&gt;Dear SAS-experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to make my progamming code more efficient by generating a list of date values from a %macro program. Based on two date value macro's (startdate and enddate) I would like to end up getting a macro-value (&amp;amp;date2) that holds a list of five years on the 1st of January that I can then use in other programs as list values.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So far I came up with:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let startdate = 01-01-2017;&lt;/P&gt;&lt;P&gt;%let enddate = 01-01-2021;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro date_test;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let start=%sysfunc(inputn(&amp;amp;startdate,ddmmyy10.));&lt;/P&gt;&lt;P&gt;%let end=%sysfunc(inputn(&amp;amp;enddate,ddmmyy10.));&lt;/P&gt;&lt;P&gt;%let diff=%sysfunc(intck(year,&amp;amp;start,&amp;amp;end));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%do i=0 %to &amp;amp;diff;&lt;/P&gt;&lt;P&gt;%global date2;&lt;/P&gt;&lt;P&gt;%let date=%sysfunc(intnx(year,&amp;amp;start,&amp;amp;i,b),ddmmyy10.);&lt;/P&gt;&lt;P&gt;%let date2=&amp;amp;date;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%put &amp;amp;date2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%mend date_test;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%date_test&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the %do statement it performs well, but I just don't know how to write and retain these values. Can anyone please help me or guide me in the right direction?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Ferdinand&lt;/P&gt;</description>
      <pubDate>Mon, 10 Aug 2020 06:33:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-values-generated-in-a-macro-statement-to-a-global/m-p/675538#M203564</guid>
      <dc:creator>Felix_Gartner</dc:creator>
      <dc:date>2020-08-10T06:33:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to write values generated in a macro statement to a global macro list?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-values-generated-in-a-macro-statement-to-a-global/m-p/675540#M203565</link>
      <description>&lt;P&gt;If you want to make things more efficient, don't use macro-code in cases that are easily solved by using simple data-steps.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Aug 2020 06:53:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-values-generated-in-a-macro-statement-to-a-global/m-p/675540#M203565</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-08-10T06:53:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to write values generated in a macro statement to a global macro list?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-values-generated-in-a-macro-statement-to-a-global/m-p/675541#M203566</link>
      <description>&lt;P&gt;Why don't you create the series of dates wherever you need them for program control? It's only a DO or %DO loop.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Aug 2020 07:15:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-values-generated-in-a-macro-statement-to-a-global/m-p/675541#M203566</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-10T07:15:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to write values generated in a macro statement to a global macro list?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-values-generated-in-a-macro-statement-to-a-global/m-p/675545#M203568</link>
      <description>&lt;P&gt;One solution is to create a macro that generates the list on the fly:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro date_list(startdate,enddate,informat=ddmmyy10.,format=ddmmyy10.,increment=year,delim=%str(,));
  %local start end diff i;
  %let start=%sysfunc(inputn(&amp;amp;startdate,&amp;amp;informat));
  %let end=%sysfunc(inputn(&amp;amp;enddate,&amp;amp;informat));
  %let diff=%sysfunc(intck(&amp;amp;increment,&amp;amp;start,&amp;amp;end));
  %do;%sysfunc(putn(&amp;amp;start,&amp;amp;format))%end;
  %do i=1 %to &amp;amp;diff;&amp;amp;delim%sysfunc(intnx(year,&amp;amp;start,&amp;amp;i,b),&amp;amp;format)%end;
%mend;

%put %date_list(01-01-2017,01-01-2021);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I made the macro a bit more flexible by adding some parameters (with defaults):&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;INFORMAT is the informat used to read STARTDATE and ENDDATE.&lt;/LI&gt;
&lt;LI&gt;FORMAT is the format used on the output, if you use e.g. 5.0, you will get a list of raw SAS dates, which can be used in an IN clause.&lt;/LI&gt;
&lt;LI&gt;INCREMENT is the increment used in INTNX, so that the macro can also be used to generate e.g. a list of monthly dates.&lt;/LI&gt;
&lt;LI&gt;DELIM is the output delimiter.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Aug 2020 09:30:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-values-generated-in-a-macro-statement-to-a-global/m-p/675545#M203568</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-08-10T09:30:29Z</dc:date>
    </item>
  </channel>
</rss>

