<?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: Loop through months in variable in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Loop-through-months-in-variable/m-p/522653#M32721</link>
    <description>&lt;P&gt;Some people think they are not in a situation where they can use BY processing or PROC SUMMARY to do calculations across many group, when in reality they are in such a situation. So we need to know exactly what calculations need to be done here.&lt;/P&gt;</description>
    <pubDate>Wed, 19 Dec 2018 17:51:32 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2018-12-19T17:51:32Z</dc:date>
    <item>
      <title>Loop through months in variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Loop-through-months-in-variable/m-p/522611#M32714</link>
      <description>&lt;P&gt;Folks I need to create some summary monthly statistics for the same procedure each month.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Start_date and end_date will always be the first of the given month and last of the given month.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;While end_date1 will be the last day of the previous month.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there an easy way to set up a macro which would carry this out say for the whole year of 2017?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let start_date='01aug2017'd; *First day of analysis month;
%let end_date='31aug2017'd; * Last day of analysis month;
%let end_date1='31jul2017'd; *Last day of lookback month month previous to above;


data testa;
set test;
if in_rppi=' ' then delete;
run;

data i;
set testa;
 if &amp;amp;start_date &amp;lt;= dt_filed &amp;lt;=&amp;amp;end_date then result="match";
 if result='match' then output i;
run;&lt;BR /&gt;&lt;BR /&gt;data u;&lt;BR /&gt; set test;&lt;BR /&gt;&lt;BR /&gt;where dt_filed between '01JAN2010'd and &amp;amp;end_date;&lt;BR /&gt;&lt;BR /&gt; if substr(csoppsn,1,1) in ('X') then&lt;BR /&gt; delete;&lt;BR /&gt;&lt;BR /&gt; if dc_type_participant='Vendor' and dc_type_property ='Residential' then&lt;BR /&gt; output vendors;&lt;BR /&gt;run;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Dec 2018 16:11:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Loop-through-months-in-variable/m-p/522611#M32714</guid>
      <dc:creator>Sean_OConnor</dc:creator>
      <dc:date>2018-12-19T16:11:45Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through months in variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Loop-through-months-in-variable/m-p/522617#M32715</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/116786"&gt;@Sean_OConnor&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Folks I need to create some summary monthly statistics for the same procedure each month.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;PROC SUMMARY is the easiest way, not macros.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
     set have;
     month = mdy(month(dt_filed),1,year(dt_filed));
    format month monyy.;
run;
proc summary data=have1;
    class month;
    var yourvariablename;
    output out=_stats_ sum=; /* Or if you want the average, use mean= */
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Dec 2018 16:18:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Loop-through-months-in-variable/m-p/522617#M32715</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-12-19T16:18:38Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through months in variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Loop-through-months-in-variable/m-p/522618#M32716</link>
      <description>Do you have to do the calculations individually or can you use BY group processing instead?</description>
      <pubDate>Wed, 19 Dec 2018 16:18:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Loop-through-months-in-variable/m-p/522618#M32716</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-12-19T16:18:21Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through months in variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Loop-through-months-in-variable/m-p/522619#M32717</link>
      <description>&lt;P&gt;I have to do the calculations individually in the sense that the dataset is not processed already.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've omitted some datasteps from below and have just shown the ones where we subset the datasets for given periods.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Dec 2018 16:20:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Loop-through-months-in-variable/m-p/522619#M32717</guid>
      <dc:creator>Sean_OConnor</dc:creator>
      <dc:date>2018-12-19T16:20:46Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through months in variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Loop-through-months-in-variable/m-p/522622#M32718</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/116786"&gt;@Sean_OConnor&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have to do the calculations individually in the sense that the dataset is not processed already.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've omitted some datasteps from below and have just shown the ones where we subset the datasets for given periods.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This really isn't explained. Many situations (not all) can be processed all at once.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We don't know if you are in a situation where they can be processed all at once. So let's be specific ... what "calculations" do you want to do on this data, by month?&lt;/P&gt;</description>
      <pubDate>Wed, 19 Dec 2018 16:27:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Loop-through-months-in-variable/m-p/522622#M32718</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-12-19T16:27:01Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through months in variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Loop-through-months-in-variable/m-p/522623#M32719</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data _null_;

	start_date=put(intnx('month',today(),0,'B'),date9.);
	end_date=put(intnx('month',today(),0,'E'),date9.);
	end_date1=put(intnx('month',today(),-1,'E'),date9.);
	start_yr=put(intnx('year',today(),0,'B'),date9.);

	call symputx('start_date',start_date);
	call symputx('end_date',end_date);
	call symputx('end_date1',end_date1);
	call symputx('start_yr',start_yr);
run;

%put &amp;amp;=start_date &amp;amp;=end_date &amp;amp;=end_date1 &amp;amp;start_yr;


data testa;
set test;
if in_rppi=' ' then delete;
run;

data i;
set testa;
 if "&amp;amp;start_date"d &amp;lt;= dt_filed &amp;lt;="&amp;amp;end_date"d then result="match";
 if result='match' then output i;
run;

data u; 
set test;
where dt_filed between "start_yr"d and "&amp;amp;end_date"d; 
if substr(csoppsn,1,1) in ('X') then delete; 
if dc_type_participant='Vendor' and dc_type_property ='Residential' then output vendors;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Dec 2018 16:28:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Loop-through-months-in-variable/m-p/522623#M32719</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2018-12-19T16:28:33Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through months in variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Loop-through-months-in-variable/m-p/522625#M32720</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/116786"&gt;@Sean_OConnor&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have to do the calculations individually in the sense that the dataset is not processed already.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've omitted some datasteps from below and have just shown the ones where we subset the datasets for given periods.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Then we can't really answer your question beyond saying turn it into a macro. Being able to use BY groups would be more efficient, but if you need to convert this to a macro, follow these instructions:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Dec 2018 16:36:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Loop-through-months-in-variable/m-p/522625#M32720</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-12-19T16:36:38Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through months in variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Loop-through-months-in-variable/m-p/522653#M32721</link>
      <description>&lt;P&gt;Some people think they are not in a situation where they can use BY processing or PROC SUMMARY to do calculations across many group, when in reality they are in such a situation. So we need to know exactly what calculations need to be done here.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Dec 2018 17:51:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Loop-through-months-in-variable/m-p/522653#M32721</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-12-19T17:51:32Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through months in variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Loop-through-months-in-variable/m-p/522666#M32722</link>
      <description>&lt;PRE&gt;data u; 
set test;
where dt_filed between "start_yr"d and "&amp;amp;end_date"d; 
if substr(csoppsn,1,1) in ('X') then delete; 
if dc_type_participant='Vendor' and dc_type_property ='Residential' then output &lt;STRONG&gt;&lt;FONT color="#ff0000" size="4"&gt;vendors&lt;/FONT&gt;&lt;/STRONG&gt;;
run;&lt;/PRE&gt;
&lt;P&gt;The above data step fails with an error as you do not have the data set VENDORS on the DATA statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Dec 2018 18:22:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Loop-through-months-in-variable/m-p/522666#M32722</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-12-19T18:22:37Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through months in variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Loop-through-months-in-variable/m-p/528285#M32882</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;

	start_date=put(intnx('month',today(),0,'B'),date9.);
	end_date=put(intnx('month',today(),0,'E'),date9.);
	end_date1=put(intnx('month',today(),-1,'E'),date9.);
	start_yr=put(intnx('year',today(),0,'B'),date9.);

	call symputx('start_date',start_date);
	call symputx('end_date',end_date);
	call symputx('end_date1',end_date1);
	call symputx('start_yr',start_yr);
run;

%put &amp;amp;=start_date &amp;amp;=end_date &amp;amp;=end_date1 &amp;amp;start_yr;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Could someone provide some information as how I would&amp;nbsp; change the following code start for august 2018 and work backwards.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The above starts for the first day of the current month but I would like to start my analysis in august 2018.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jan 2019 12:09:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Loop-through-months-in-variable/m-p/528285#M32882</guid>
      <dc:creator>Sean_OConnor</dc:creator>
      <dc:date>2019-01-18T12:09:23Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through months in variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Loop-through-months-in-variable/m-p/528352#M32888</link>
      <description>&lt;P&gt;What do you mean by:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Could someone provide some information as how I would&amp;nbsp; change the following code start for august 2018&lt;STRONG&gt; and work backwards.&lt;/STRONG&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;You can replace today() with '01AUG2018'd and it will replace today().&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or better yet, make it take a variable and set the variable at the top of the data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data _null_;
        *&lt;FONT size="4" color="#FF0000"&gt;&lt;STRONG&gt;myDate = today();&lt;/STRONG&gt;&lt;/FONT&gt;
        &lt;FONT size="4" color="#FF0000"&gt;&lt;STRONG&gt;myDate = '01Aug2018'd;&lt;/STRONG&gt;&lt;/FONT&gt;

	start_date=put(intnx('month', &lt;FONT color="#800080"&gt;&lt;STRONG&gt;myDate&lt;/STRONG&gt;&lt;/FONT&gt;, 0, 'B'), date9.);
	end_date=put(intnx('month', &lt;STRONG&gt;&lt;FONT color="#800080"&gt;myDate&lt;/FONT&gt;&lt;/STRONG&gt;, 0, 'E'), date9.);
	end_date1=put(intnx('month', &lt;STRONG&gt;&lt;FONT color="#800080"&gt;myDate&lt;/FONT&gt;&lt;/STRONG&gt;, -1, 'E'), date9.);
	start_yr=put(intnx('year', &lt;STRONG&gt;&lt;FONT color="#800080"&gt;myDate&lt;/FONT&gt;&lt;/STRONG&gt;, 0, 'B'), date9.);

	call symputx('start_date', start_date);
	call symputx('end_date', end_date);
	call symputx('end_date1', end_date1);
	call symputx('start_yr', start_yr);
run;

%put &amp;amp;=start_date &amp;amp;=end_date &amp;amp;=end_date1 &amp;amp;start_yr;&lt;/PRE&gt;
&lt;P&gt;Make sure to comment out one of the dates, so only the one you need works.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/116786"&gt;@Sean_OConnor&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;

	start_date=put(intnx('month',today(),0,'B'),date9.);
	end_date=put(intnx('month',today(),0,'E'),date9.);
	end_date1=put(intnx('month',today(),-1,'E'),date9.);
	start_yr=put(intnx('year',today(),0,'B'),date9.);

	call symputx('start_date',start_date);
	call symputx('end_date',end_date);
	call symputx('end_date1',end_date1);
	call symputx('start_yr',start_yr);
run;

%put &amp;amp;=start_date &amp;amp;=end_date &amp;amp;=end_date1 &amp;amp;start_yr;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Could someone provide some information as how I would&amp;nbsp; change the following code start for august 2018 and work backwards.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The above starts for the first day of the current month but I would like to start my analysis in august 2018.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jan 2019 16:04:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Loop-through-months-in-variable/m-p/528352#M32888</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-01-18T16:04:10Z</dc:date>
    </item>
  </channel>
</rss>

