<?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 perform a set of procedures for a specific time interval? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-perform-a-set-of-procedures-for-a-specific-time-interval/m-p/619410#M19384</link>
    <description>&lt;P&gt;The first one is built from the supplied month and year, with day 1. The second is the beginning of the next month.&lt;/P&gt;
&lt;P&gt;Since those dates are used in code, they need not be formatted.&lt;/P&gt;</description>
    <pubDate>Thu, 23 Jan 2020 05:20:13 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-01-23T05:20:13Z</dc:date>
    <item>
      <title>How to perform a set of procedures for a specific time interval?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-perform-a-set-of-procedures-for-a-specific-time-interval/m-p/619033#M19317</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset with dates ranging from Feb2018 to Feb2019. I need to exclude the data corresponding to each month and perform some procedures for the data of the remaining months (i.e., I need to do this 12 times). For example my code for running a logistic regression excluding the data of Nov2018 is as follows. Anybody can help to automate this process (instead of manually changing dates in the "where"&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc logistic data=have (where=(Date_r &amp;gt;= '01Dec2018'd  | Date_r &amp;lt;'1Nov2018'd));
model High_level (event='1')= Score_r Length_r;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;statement)? Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jan 2020 04:05:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-perform-a-set-of-procedures-for-a-specific-time-interval/m-p/619033#M19317</guid>
      <dc:creator>Bright</dc:creator>
      <dc:date>2020-01-22T04:05:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform a set of procedures for a specific time interval?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-perform-a-set-of-procedures-for-a-specific-time-interval/m-p/619036#M19319</link>
      <description>&lt;P&gt;&lt;STRONG&gt;UCLA introductory tutorial on macro variables and macros&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Tutorial on converting a working program to a macro&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;This method is pretty robust and helps prevent errors and makes it much easier to debug your code. Obviously biased, because I wrote it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&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;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;The UCLA has some tutorials on macros that can help you with this.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that you can simplify your WHERE clause to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where put(date_r, yymmn6.) NE "201812";

where month(date) ne 12 and year(date) ne 2018;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;Examples of common macro usage - including how to loop through dates in a macro.&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*create macro;
%macro runMyCode(myMonth = );
title "Regression for Month= &amp;amp;myMonth";
proc logistic data=have (where=put(date_r, yymmn6.) ne "&amp;amp;myMonth.";
model High_level (event='1')= Score_r Length_r;
run;
title;
%mend;

data demo;

*set start date;
start_date = '01Jan2018'd;

*loop through 12 months of the year;
*change here to include longer periods;
do i=1 to 12;
   *find date of the month;
   date = intnx('month', start_date, i-1, 'b');
   *format to correct format for macro;
   macro_param = put(date, yymmn6.);

    *create macro call;
    str = catt('%runMyCode(myMonth=', macro_param, ');');
   
     *execute macro, currently commented out;
     *call execute(str);
end;


run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested but should give you a good idea of what you need, if it doesn't work, the links above have everything you need to build your own or debug it.&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/307632"&gt;@Bright&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a dataset with dates ranging from Feb2018 to Feb2019. I need to exclude the data corresponding to each month and perform some procedures for the data of the remaining months (i.e., I need to do this 12 times). For example my code for running a logistic regression excluding the data of Nov2018 is as follows. Anybody can help to automate this process (instead of manually changing dates in the "where"&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc logistic data=have (where=(Date_r &amp;gt;= '01Dec2018'd  | Date_r &amp;lt;'1Nov2018'd));
model High_level (event='1')= Score_r Length_r;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;statement)? Thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jan 2020 04:23:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-perform-a-set-of-procedures-for-a-specific-time-interval/m-p/619036#M19319</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-01-22T04:23:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform a set of procedures for a specific time interval?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-perform-a-set-of-procedures-for-a-specific-time-interval/m-p/619073#M19329</link>
      <description>&lt;P&gt;A slightly different approach, using your original code with minimal changes, to show creation of macro variables from parameters:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro logit(year,month);

%let from = %sysfunc(mdy(&amp;amp;month.,1,&amp;amp;year.));
%let to = %sysfunc(intnx(month,&amp;amp;from,1,b));

proc logistic data=have (where=(Date_r &amp;gt;= &amp;amp;to. | Date_r &amp;lt; &amp;amp;from.));
model High_level (event='1')= Score_r Length_r;
run;

%mend;

data _null_;
date = '01feb2018'd;
do until (date &amp;gt; '01feb2019'd);
  call execute(cats('%nrstr(%logit(',year(date),',',month(date),'))'));
  date = intnx('month',date,1,'b');
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The %nrstr in the call execute is necessary to prevent premature resolution of macro statements within the macro.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jan 2020 09:46:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-perform-a-set-of-procedures-for-a-specific-time-interval/m-p/619073#M19329</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-01-22T09:46:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform a set of procedures for a specific time interval?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-perform-a-set-of-procedures-for-a-specific-time-interval/m-p/619075#M19330</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro runit(month=,year=);
	proc logistic data=have (where=(month(Date_r) = &amp;amp;month. and year(Date_r) =&amp;amp;year.));
	model High_level (event='1')= Score_r Length_r;
	run;
%mend runit;

proc sql noprint;
create table have1 as
select distinct month(Date_r) as m, year(Date_r) as y from have;
quit;

data _null_;
set have1;
call execute('%runit(month='||put(m,8.)||',year='||put(y,8.)||');');
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Please let us know if it worked for you.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jan 2020 09:54:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-perform-a-set-of-procedures-for-a-specific-time-interval/m-p/619075#M19330</guid>
      <dc:creator>Satish_Parida</dc:creator>
      <dc:date>2020-01-22T09:54:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform a set of procedures for a specific time interval?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-perform-a-set-of-procedures-for-a-specific-time-interval/m-p/619390#M19380</link>
      <description>&lt;P&gt;Thanks for the reply. I guess there is a mismatch between dates. I need to exclude one month and run the regression on the data of remaining months. So I guess I need to change this line of your code as follows, correct?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc logistic data=have (where=(month(Date_r) ne &amp;amp;month. and year(Date_r) ne &amp;amp;year.));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jan 2020 01:07:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-perform-a-set-of-procedures-for-a-specific-time-interval/m-p/619390#M19380</guid>
      <dc:creator>Bright</dc:creator>
      <dc:date>2020-01-23T01:07:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform a set of procedures for a specific time interval?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-perform-a-set-of-procedures-for-a-specific-time-interval/m-p/619391#M19381</link>
      <description>Thanks for the reply. Could you please explain the dates you used in %let.</description>
      <pubDate>Thu, 23 Jan 2020 01:11:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-perform-a-set-of-procedures-for-a-specific-time-interval/m-p/619391#M19381</guid>
      <dc:creator>Bright</dc:creator>
      <dc:date>2020-01-23T01:11:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform a set of procedures for a specific time interval?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-perform-a-set-of-procedures-for-a-specific-time-interval/m-p/619410#M19384</link>
      <description>&lt;P&gt;The first one is built from the supplied month and year, with day 1. The second is the beginning of the next month.&lt;/P&gt;
&lt;P&gt;Since those dates are used in code, they need not be formatted.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jan 2020 05:20:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-perform-a-set-of-procedures-for-a-specific-time-interval/m-p/619410#M19384</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-01-23T05:20:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform a set of procedures for a specific time interval?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-perform-a-set-of-procedures-for-a-specific-time-interval/m-p/619414#M19387</link>
      <description>&lt;P&gt;No, The exclusion must happen in the calling system. See comments bellow.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro runit(month=,year=);
	proc logistic data=have (where=(month(Date_r) = &amp;amp;month. and year(Date_r) =&amp;amp;year.));
	model High_level (event='1')= Score_r Length_r;
	run;
%mend runit;

proc sql noprint;
create table have1 as
select distinct month(Date_r) as m, year(Date_r) as y from have
    where month(Date_r) ne '2' and  year(Date_r) ne '2019'; 
/*Please put your choice of month and year to exclude in this where block instead*/
quit;

data _null_;
set have1;
call execute('%runit(month='||put(m,8.)||',year='||put(y,8.)||');');
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please let us know if it worked for you.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jan 2020 06:10:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-perform-a-set-of-procedures-for-a-specific-time-interval/m-p/619414#M19387</guid>
      <dc:creator>Satish_Parida</dc:creator>
      <dc:date>2020-01-23T06:10:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform a set of procedures for a specific time interval?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-perform-a-set-of-procedures-for-a-specific-time-interval/m-p/619416#M19389</link>
      <description>&lt;P&gt;The OP wants to run the procedure for 11 months at a time, your code can only run it for 1 month at a time.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jan 2020 06:43:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-perform-a-set-of-procedures-for-a-specific-time-interval/m-p/619416#M19389</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-01-23T06:43:12Z</dc:date>
    </item>
  </channel>
</rss>

