<?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: Do loop over proc step - How to store the results of all the iterations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-over-proc-step-How-to-store-the-results-of-all-the/m-p/478141#M123260</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/220996"&gt;@Sabeth&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Thank you for your44 comment, Paige Miller. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;My intention was to set a date (with the do Loop) and select all the objects with a prior&amp;nbsp;date (not only January and February).&amp;nbsp;Therefore,&amp;nbsp;the where clause&amp;nbsp;was not correct. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;I converted the numeric variables eyear and emonth (eyearmax and eyearmonth)&amp;nbsp;into&amp;nbsp; date variables edate (edatemax). But now I have no idea how to&amp;nbsp;integrate them in the where clause as macrovariables. I have some problems with the&amp;nbsp;format. &amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; edate=01/12/2008;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;proc summary data=work.have (where=(edatemax &amp;lt; (&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#800080"&gt;"&amp;amp;edate"&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;ddmmyy10.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;))) nway sum;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So you want a macro to store all of these results in a dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro do_all;
    %let date=%sysfunc(mdy(12,1,2006));
    %do %while(&amp;amp;date&amp;lt;%sysfunc(mdy(12,1,2009)));
         %let date=%sysfunc(intnx(month,&amp;amp;date,1,b));
         proc summary data=have(where=(edatemax&amp;lt;=&amp;amp;date)) nway;
             class id;
             var duration edatemax;
             output out=work.duration sum(duration)= max(edatemax)=;
         run;
         proc append base=all_duration new=duration;
         run;
    %end;
%mend;

proc datasets library=work nolist;
    delete all_duration;
run; quit;
%do_all

         &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 14 Jul 2018 23:47:46 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2018-07-14T23:47:46Z</dc:date>
    <item>
      <title>Do loop over proc step - How to store the results of all the iterations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-over-proc-step-How-to-store-the-results-of-all-the/m-p/478057#M123221</link>
      <description>&lt;P&gt;&lt;FONT size="2" face="Courier New" color="#000080"&gt;&lt;STRONG&gt;Dear SAS Community,&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2" face="Courier New" color="#000080"&gt;&lt;STRONG&gt;I would like to calculate the mean of a variable for each year and month in a specific time period. I programed a do loop over a proc summary step to do so.&amp;nbsp;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2" face="Courier New" color="#000080"&gt;&lt;STRONG&gt;The problem is that I only get back the results for the last iteration of the loop. But I need the results of all the iteration.&lt;BR /&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2" face="Courier New" color="#000080"&gt;&lt;STRONG&gt;I suppose that the loop overwrites the results of former iterations. Do you know a possibility to store the results of each iteration? Or would you suggest a data step with an output statement?&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2" face="Courier New" color="#000080"&gt;&lt;STRONG&gt;The dataset includes some numeric variables that represent the date as well as a duration variable. For example:&amp;nbsp; &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2" face="Courier New" color="#000080"&gt;&lt;STRONG&gt;ID eyearmax emonthmax eyear eyear duration&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2" face="Courier New" color="#000080"&gt;&lt;STRONG&gt;1&amp;nbsp; 2007&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2007&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2" face="Courier New" color="#000080"&gt;&lt;STRONG&gt;1&amp;nbsp; 2007&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2007&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 15&lt;BR /&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2" face="Courier New" color="#000080"&gt;&lt;STRONG&gt;1&amp;nbsp; 2007&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2007&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 28&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2" face="Courier New" color="#000080"&gt;&lt;STRONG&gt;2&amp;nbsp; 2008&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2007 &amp;nbsp;&amp;nbsp;&amp;nbsp; 5 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2" face="Courier New" color="#000080"&gt;&lt;STRONG&gt;3&amp;nbsp; 2007&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 11&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2006&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 11&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2" face="Courier New" color="#000080"&gt;&lt;STRONG&gt;3&amp;nbsp; 2007 &amp;nbsp;&amp;nbsp;&amp;nbsp; 11&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2007&amp;nbsp;&amp;nbsp;&amp;nbsp; 11 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 19&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2" face="Courier New" color="#000080"&gt;&lt;STRONG&gt;4&amp;nbsp; 2008&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2008 &amp;nbsp;&amp;nbsp;&amp;nbsp; 1 &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; 7&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;&lt;P&gt;&lt;FONT size="2" face="Courier New" color="#000080"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT size="2" face="Courier New"&gt; test (eyear=, emonth=,);&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" face="Courier New" color="#0000FF"&gt;%DO&lt;/FONT&gt;&lt;FONT size="2" face="Courier New"&gt; eyear = &lt;/FONT&gt;&lt;FONT size="2" face="Courier New" color="#008080"&gt;&lt;STRONG&gt;2007&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT size="2" face="Courier New"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;FONT size="2" face="Courier New" color="#0000FF"&gt;%TO&lt;/FONT&gt;&lt;FONT size="2" face="Courier New"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;FONT size="2" face="Courier New" color="#008080"&gt;&lt;STRONG&gt;2009&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT size="2" face="Courier New"&gt;;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2" face="Courier New" color="#0000FF"&gt;%DO&lt;/FONT&gt;&lt;FONT size="2" face="Courier New"&gt; emonth = &lt;/FONT&gt;&lt;FONT size="2" face="Courier New" color="#008080"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT size="2" face="Courier New"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;FONT size="2" face="Courier New" color="#0000FF"&gt;%TO&lt;/FONT&gt;&lt;FONT size="2" face="Courier New"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;FONT size="2" face="Courier New" color="#008080"&gt;&lt;STRONG&gt;12&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT size="2" face="Courier New"&gt;;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" face="Courier New"&gt;proc summary data=work.want (where=(eyearmax&amp;lt;=&amp;amp;&lt;/FONT&gt;&lt;FONT size="2" face="Courier New" color="#008080"&gt;eyear.&lt;/FONT&gt;&lt;FONT size="2" face="Courier New"&gt;&amp;nbsp;and emonthmax&amp;lt;=&amp;amp;&lt;/FONT&gt;&lt;FONT size="2" face="Courier New" color="#008080"&gt;emonth.&lt;/FONT&gt;&lt;FONT size="2" face="Courier New"&gt;)) nway sum;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2" face="Courier New"&gt;class id;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2" face="Courier New"&gt;output out=work.duration&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2" face="Courier New"&gt;sum(duration)=;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2" face="Courier New"&gt;run;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" face="Courier New"&gt;proc summary data=work.duration mean;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2" face="Courier New"&gt;output out=work.meanduration (drop=_freq_ _type_)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2" face="Courier New"&gt;mean (duration)=;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2" face="Courier New"&gt;run;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" face="Courier New" color="#0000FF"&gt;%end&lt;/FONT&gt;&lt;FONT size="2" face="Courier New"&gt;;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2" face="Courier New" color="#0000FF"&gt;%end&lt;/FONT&gt;&lt;FONT size="2" face="Courier New"&gt;;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2" face="Courier New" color="#000080"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT size="2" face="Courier New"&gt; test;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2" face="Courier New"&gt;%&lt;/FONT&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;STRONG&gt;&lt;I&gt;test&lt;/I&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT size="2" face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2" face="Courier New"&gt;Thank you very much for your help!&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2" face="Courier New"&gt;Best regards, &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2" face="Courier New"&gt;Sabeth&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jul 2018 22:10:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-over-proc-step-How-to-store-the-results-of-all-the/m-p/478057#M123221</guid>
      <dc:creator>Sabeth</dc:creator>
      <dc:date>2018-07-13T22:10:06Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop over proc step - How to store the results of all the iterations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-over-proc-step-How-to-store-the-results-of-all-the/m-p/478058#M123222</link>
      <description>&lt;P&gt;It's not clear to me what you want, or if this line is correct:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;(where=(eyearmax&amp;lt;=&amp;amp;eyear. and emonthmax&amp;lt;=&amp;amp;emonth.))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;because then when &amp;amp;eyear is 2009 and &amp;amp;emonth is 1, you get the mean of all January data where year is less than 2009; in other words the mean of many different Januaries. When &amp;amp;emonth is 2, you get the mean of January and February over many months and many years. And so on. If that's what you want, you may need a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if you want what you said, which is "the mean of a variable for each year and month", that sounds like something different, and no macros are needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So which is it? What do you really want to do?&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jul 2018 22:19:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-over-proc-step-How-to-store-the-results-of-all-the/m-p/478058#M123222</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-07-13T22:19:26Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop over proc step - How to store the results of all the iterations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-over-proc-step-How-to-store-the-results-of-all-the/m-p/478062#M123225</link>
      <description>&lt;P&gt;Maybe&lt;/P&gt;
&lt;PRE&gt;proc summary data=work.want nway ;
class id eyear emonth;
var duration  ;
output out=work.duration  sum= mean= /autoname;

run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which will create variables duration_sum and duration_mean to hold the statistics. The /autoname option suffixes a variable with the statistic to name the resulting output variable within the 32 character name limit.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want summaries by eyear and emonth without considering Id then remove the NWAY and use the desired values for the _type_ variable or add a types statement.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jul 2018 22:37:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-over-proc-step-How-to-store-the-results-of-all-the/m-p/478062#M123225</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-07-13T22:37:11Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop over proc step - How to store the results of all the iterations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-over-proc-step-How-to-store-the-results-of-all-the/m-p/478080#M123234</link>
      <description>&lt;P&gt;These are moving averages, is that what you want?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so, I would recommend PROC EXPAND instead, if you have SAS/ETS. You can check using:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc product_status;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If not, an example of wrapping this in a macro is here:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://gist.github.com/statgeek/e5e43ff45a4ba1f64d0873ff3bc35974" target="_blank"&gt;https://gist.github.com/statgeek/e5e43ff45a4ba1f64d0873ff3bc35974&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also look at the ODS OUTPUT option along with the PERSIST option.&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/220996"&gt;@Sabeth&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;Dear SAS Community,&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;I would like to calculate the mean of a variable for each year and month in a specific time period. I programed a do loop over a proc summary step to do so.&amp;nbsp;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;The problem is that I only get back the results for the last iteration of the loop. But I need the results of all the iteration.&lt;BR /&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;I suppose that the loop overwrites the results of former iterations. Do you know a possibility to store the results of each iteration? Or would you suggest a data step with an output statement?&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;The dataset includes some numeric variables that represent the date as well as a duration variable. For example:&amp;nbsp; &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;ID eyearmax emonthmax eyear eyear duration&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;1&amp;nbsp; 2007&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2007&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;1&amp;nbsp; 2007&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2007&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 15&lt;BR /&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;1&amp;nbsp; 2007&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2007&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 28&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;2&amp;nbsp; 2008&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2007 &amp;nbsp;&amp;nbsp;&amp;nbsp; 5 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;3&amp;nbsp; 2007&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 11&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2006&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 11&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;3&amp;nbsp; 2007 &amp;nbsp;&amp;nbsp;&amp;nbsp; 11&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2007&amp;nbsp;&amp;nbsp;&amp;nbsp; 11 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 19&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;4&amp;nbsp; 2008&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2008 &amp;nbsp;&amp;nbsp;&amp;nbsp; 1 &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; 7&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;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; test (eyear=, emonth=,);&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="Courier New" size="2" color="#0000FF"&gt;%DO&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; eyear = &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;&lt;STRONG&gt;2007&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000FF"&gt;%TO&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;&lt;STRONG&gt;2009&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="Courier New" size="2" color="#0000FF"&gt;%DO&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; emonth = &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000FF"&gt;%TO&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;&lt;STRONG&gt;12&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="Courier New" size="2"&gt;proc summary data=work.want (where=(eyearmax&amp;lt;=&amp;amp;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;eyear.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;and emonthmax&amp;lt;=&amp;amp;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;emonth.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;)) nway sum;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="Courier New" size="2"&gt;class id;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="Courier New" size="2"&gt;output out=work.duration&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="Courier New" size="2"&gt;sum(duration)=;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="Courier New" size="2"&gt;run;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="Courier New" size="2"&gt;proc summary data=work.duration mean;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="Courier New" size="2"&gt;output out=work.meanduration (drop=_freq_ _type_)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="Courier New" size="2"&gt;mean (duration)=;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="Courier New" size="2"&gt;run;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="Courier New" size="2" color="#0000FF"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="Courier New" size="2" color="#0000FF"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; test;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="Courier New" size="2"&gt;%&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;STRONG&gt;&lt;I&gt;test&lt;/I&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;Thank you very much for your help!&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;Best regards, &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;Sabeth&lt;/FONT&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Jul 2018 00:51:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-over-proc-step-How-to-store-the-results-of-all-the/m-p/478080#M123234</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-07-14T00:51:08Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop over proc step - How to store the results of all the iterations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-over-proc-step-How-to-store-the-results-of-all-the/m-p/478131#M123253</link>
      <description>&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Thank you for your comment, Paige Miller. &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;My intention was to set a date (with the do Loop) and select all the objects with a prior&amp;nbsp;date (not only January and February).&amp;nbsp;Therefore,&amp;nbsp;the where clause&amp;nbsp;was not correct. &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;I converted the numeric variables eyear and emonth (eyearmax and eyearmonth)&amp;nbsp;into&amp;nbsp; date variables edate (edatemax). But now I have no idea how to&amp;nbsp;integrate them in the where clause as macrovariables. I have some problems with the&amp;nbsp;format. &amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; edate=01/12/2008;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;proc summary data=work.have (where=(edatemax &amp;lt; (&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"&amp;amp;edate"&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;ddmmyy10.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;))) nway sum;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;You mentioned that no macros are needed for my "Iteration Problem". Could you please explain how&amp;nbsp;the problem&amp;nbsp;could be solved without a macro?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;Thank you in advance!&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;Sabeth&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Jul 2018 18:07:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-over-proc-step-How-to-store-the-results-of-all-the/m-p/478131#M123253</guid>
      <dc:creator>Sabeth</dc:creator>
      <dc:date>2018-07-14T18:07:02Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop over proc step - How to store the results of all the iterations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-over-proc-step-How-to-store-the-results-of-all-the/m-p/478141#M123260</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/220996"&gt;@Sabeth&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Thank you for your44 comment, Paige Miller. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;My intention was to set a date (with the do Loop) and select all the objects with a prior&amp;nbsp;date (not only January and February).&amp;nbsp;Therefore,&amp;nbsp;the where clause&amp;nbsp;was not correct. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;I converted the numeric variables eyear and emonth (eyearmax and eyearmonth)&amp;nbsp;into&amp;nbsp; date variables edate (edatemax). But now I have no idea how to&amp;nbsp;integrate them in the where clause as macrovariables. I have some problems with the&amp;nbsp;format. &amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; edate=01/12/2008;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;proc summary data=work.have (where=(edatemax &amp;lt; (&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#800080"&gt;"&amp;amp;edate"&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;ddmmyy10.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;))) nway sum;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So you want a macro to store all of these results in a dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro do_all;
    %let date=%sysfunc(mdy(12,1,2006));
    %do %while(&amp;amp;date&amp;lt;%sysfunc(mdy(12,1,2009)));
         %let date=%sysfunc(intnx(month,&amp;amp;date,1,b));
         proc summary data=have(where=(edatemax&amp;lt;=&amp;amp;date)) nway;
             class id;
             var duration edatemax;
             output out=work.duration sum(duration)= max(edatemax)=;
         run;
         proc append base=all_duration new=duration;
         run;
    %end;
%mend;

proc datasets library=work nolist;
    delete all_duration;
run; quit;
%do_all

         &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Jul 2018 23:47:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-over-proc-step-How-to-store-the-results-of-all-the/m-p/478141#M123260</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-07-14T23:47:46Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop over proc step - How to store the results of all the iterations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-over-proc-step-How-to-store-the-results-of-all-the/m-p/478968#M123575</link>
      <description>&lt;P&gt;Thank you! The date macro variables and the proc append step solved my problem.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 09:26:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-over-proc-step-How-to-store-the-results-of-all-the/m-p/478968#M123575</guid>
      <dc:creator>Sabeth</dc:creator>
      <dc:date>2018-07-18T09:26:28Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop over proc step - How to store the results of all the iterations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-over-proc-step-How-to-store-the-results-of-all-the/m-p/478970#M123577</link>
      <description>&lt;P&gt;Thank you all for your support!&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 09:36:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-over-proc-step-How-to-store-the-results-of-all-the/m-p/478970#M123577</guid>
      <dc:creator>Sabeth</dc:creator>
      <dc:date>2018-07-18T09:36:04Z</dc:date>
    </item>
  </channel>
</rss>

