<?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 Iterate through dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Iterate-through-dates/m-p/642337#M191586</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a macro (Proc SQL) which takes a date as an input (e.g. '31/03/2020'), and I want to execute this macro on several dates.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried a %do loop on a list of dates (e.g. '31/01/2020' '31/03/2020'), but it seems that it is not recognized as a date when I use the scan function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyone has an idea on how to declare this list of dates and how to iterate through it ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Clément&lt;/P&gt;</description>
    <pubDate>Thu, 23 Apr 2020 16:38:41 GMT</pubDate>
    <dc:creator>Gluttony</dc:creator>
    <dc:date>2020-04-23T16:38:41Z</dc:date>
    <item>
      <title>Iterate through dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iterate-through-dates/m-p/642337#M191586</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a macro (Proc SQL) which takes a date as an input (e.g. '31/03/2020'), and I want to execute this macro on several dates.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried a %do loop on a list of dates (e.g. '31/01/2020' '31/03/2020'), but it seems that it is not recognized as a date when I use the scan function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyone has an idea on how to declare this list of dates and how to iterate through it ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Clément&lt;/P&gt;</description>
      <pubDate>Thu, 23 Apr 2020 16:38:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iterate-through-dates/m-p/642337#M191586</guid>
      <dc:creator>Gluttony</dc:creator>
      <dc:date>2020-04-23T16:38:41Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate through dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iterate-through-dates/m-p/642342#M191588</link>
      <description>&lt;P&gt;Please show the code you attempted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to have a literal date provided as value then it likely needs to appear as "01JAN2020"D unless your variable is character,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Macro %do iterators do not allow lists of values like the data step Do loop. Adjustments to get something similar to what you want requires having some basic code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Scan will not recognize anything as a "date" since it is a character function.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Apr 2020 17:15:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iterate-through-dates/m-p/642342#M191588</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-04-23T17:15:17Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate through dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iterate-through-dates/m-p/642344#M191590</link>
      <description>&lt;P&gt;CALL EXECUTE()?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data demo;

do i='31Jan2020'd to '31Mar2020'd;
%*creates a string that looks like myMacro("31/01/2020");;;
str = catt('%myMacro("', put(i, ddmmyys10.), '");');
*runs the macro;
call execute(str);
end;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Apr 2020 17:17:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iterate-through-dates/m-p/642344#M191590</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-04-23T17:17:29Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate through dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iterate-through-dates/m-p/642345#M191591</link>
      <description>&lt;P&gt;here is how I would declare a list of dates&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Specify start and end dates*/
%let start_date=%str(31JAN2020);
%let end_date=%str(31MAR2020);

data mnthrnge;
	date_N="&amp;amp;start_date"d;

	do while (date_N&amp;lt;="&amp;amp;end_date"d);
		output;
		date_N=intnx('month', date_N, 1, 's');
	end;
	format date_N date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Using for example, a Call Execute or DOSUBL construct,&amp;nbsp; you can cycle through the dates and run your code for each month&lt;/P&gt;</description>
      <pubDate>Thu, 23 Apr 2020 17:20:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iterate-through-dates/m-p/642345#M191591</guid>
      <dc:creator>ghosh</dc:creator>
      <dc:date>2020-04-23T17:20:09Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate through dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iterate-through-dates/m-p/642356#M191597</link>
      <description>&lt;P&gt;What types of values does the macro want? All macro parameters are strings, so how the macro code uses the parameter determines what types of strings it can handle.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What does your list of dates look like?&amp;nbsp; What you showed were character strings.&amp;nbsp; The date value for the last day of march 2020 is the number 22,005 since that is how many days since the start of 1960.&amp;nbsp; You can represent a specific date in SAS code with a date literal. A quoted string tht the DATE informat can interpret followed by the letter d.&amp;nbsp; "31MAR2020"d for example.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Apr 2020 18:17:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iterate-through-dates/m-p/642356#M191597</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-23T18:17:32Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate through dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iterate-through-dates/m-p/642473#M191669</link>
      <description>&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;After reading your answers, it turns out that my SQL ("SELECT ... WHERE DATE IN ( &amp;amp;date.)") needs $date. to be in these following formats : '31/03/2020' or '31-03-2020', which seem to be strings in SAS (&lt;EM&gt;but recognized as date by Oracle&lt;/EM&gt;).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My macro selects data from DB, processes them and exports an excel file.&lt;/P&gt;&lt;P&gt;How can I execute this macro on several strings ? ('31/01/2020' '31/03/2020')&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ex :&lt;/P&gt;&lt;PRE&gt;%LET list_dates = '31/01/2020','31/03/2020';

%macro main(list_dates);
%do i=1 %to 2;
%macroSQL(%scan(&amp;amp;list_dates.,&amp;amp;i,','));
%end;
%mend;&lt;BR /&gt;&lt;BR /&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: &lt;BR /&gt;'31/03/2020' &lt;BR /&gt;ERROR: Argument 2 to macro function %SCAN is not a number.&lt;BR /&gt;ERROR: The macro macroSQL will stop executing.&lt;/PRE&gt;&lt;P&gt;does not seem to work&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macroSQL('31/01/2020');&lt;/PRE&gt;&lt;P&gt;But this works&lt;/P&gt;</description>
      <pubDate>Fri, 24 Apr 2020 08:42:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iterate-through-dates/m-p/642473#M191669</guid>
      <dc:creator>Gluttony</dc:creator>
      <dc:date>2020-04-24T08:42:07Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate through dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iterate-through-dates/m-p/642483#M191676</link>
      <description>&lt;P&gt;Ok, I tried a different separator in the list, removed the quotes in the scan function and it worked !!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%LET list_dates = '31/01/2020'&lt;STRONG&gt;-&lt;/STRONG&gt;'31/03/2020';

%macro main(list_dates);
%do i=1 %to 2;
%macroSQL(%scan(&amp;amp;list_dates.,&amp;amp;i,&lt;STRONG&gt;-&lt;/STRONG&gt;));
%end;
%mend;

&lt;/PRE&gt;&lt;P&gt;Thank you all,&lt;/P&gt;&lt;P&gt;Gluttony&lt;/P&gt;</description>
      <pubDate>Fri, 24 Apr 2020 08:55:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iterate-through-dates/m-p/642483#M191676</guid>
      <dc:creator>Gluttony</dc:creator>
      <dc:date>2020-04-24T08:55:47Z</dc:date>
    </item>
  </channel>
</rss>

