<?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 Create a macro to obtain date of monday for a given date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-to-obtain-date-of-monday-for-a-given-date/m-p/530924#M145213</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create a macro variable that generates a date (which will be Monday of that week) when I run the code on any given day of that week.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So here is an example,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;lets take I am running the macro today(29_01_2019), output should be Jan_29_2019 .&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Suggestions are appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;Vigneswar&lt;/P&gt;</description>
    <pubDate>Tue, 29 Jan 2019 11:51:16 GMT</pubDate>
    <dc:creator>Vigneswar</dc:creator>
    <dc:date>2019-01-29T11:51:16Z</dc:date>
    <item>
      <title>Create a macro to obtain date of monday for a given date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-to-obtain-date-of-monday-for-a-given-date/m-p/530923#M145210</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create a macro variable that generates a date (which will be Monday of that week) when I run the code on any given day of that week.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So here is an example,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;lets take I am running the macro today(29_01_2019), output should be Jan_29_2019 .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Suggestions are appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;Vigneswar&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jan 2019 11:49:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-to-obtain-date-of-monday-for-a-given-date/m-p/530923#M145210</guid>
      <dc:creator>Vigneswar</dc:creator>
      <dc:date>2019-01-29T11:49:13Z</dc:date>
    </item>
    <item>
      <title>Create a macro to obtain date of monday for a given date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-to-obtain-date-of-monday-for-a-given-date/m-p/530924#M145213</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create a macro variable that generates a date (which will be Monday of that week) when I run the code on any given day of that week.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So here is an example,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;lets take I am running the macro today(29_01_2019), output should be Jan_29_2019 .&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Suggestions are appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;Vigneswar&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jan 2019 11:51:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-to-obtain-date-of-monday-for-a-given-date/m-p/530924#M145213</guid>
      <dc:creator>Vigneswar</dc:creator>
      <dc:date>2019-01-29T11:51:16Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro to obtain date of monday for a given date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-to-obtain-date-of-monday-for-a-given-date/m-p/530937#M145214</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;output should be Jan_29_2019 .&amp;nbsp; &amp;nbsp;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;But January 29, 2019 is not a Monday.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, you haven't really defined the problem in a way specific enough to be programmed. How do you determine the "week" in order to determine the Monday of the week? Do weeks begin on Sunday? Do weeks begin on Monday? Something else?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's very hard to generalize and write actual code given your brief comments.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And ... NO MACRO NEEDED, regardless.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jan 2019 13:09:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-to-obtain-date-of-monday-for-a-given-date/m-p/530937#M145214</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-01-29T13:09:01Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro to obtain date of monday for a given date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-to-obtain-date-of-monday-for-a-given-date/m-p/530941#M145215</link>
      <description>&lt;P&gt;Please keep your questions in a single thread. It makes it much easier to keep track of answers and proposed solutions.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jan 2019 13:14:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-to-obtain-date-of-monday-for-a-given-date/m-p/530941#M145215</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-01-29T13:14:04Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro to obtain date of monday for a given date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-to-obtain-date-of-monday-for-a-given-date/m-p/530943#M145217</link>
      <description>Paige Miller,&lt;BR /&gt;&lt;BR /&gt;Sorry that was a good catch. I wanted my output as Jan_28_2019 .&lt;BR /&gt;&lt;BR /&gt;Let me summarize again.&lt;BR /&gt;&lt;BR /&gt;Lets take I am running a ODS code that generates an xml file and the name of the file should be in this format mon_dd_yyyy. Let it be I run the code on any day in a week, the output date should be monday of that week.&lt;BR /&gt;&lt;BR /&gt;Is the requirement clear enough?&lt;BR /&gt;&lt;BR /&gt;Thanks for your response.</description>
      <pubDate>Tue, 29 Jan 2019 13:20:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-to-obtain-date-of-monday-for-a-given-date/m-p/530943#M145217</guid>
      <dc:creator>Vigneswar</dc:creator>
      <dc:date>2019-01-29T13:20:11Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro to obtain date of monday for a given date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-to-obtain-date-of-monday-for-a-given-date/m-p/530950#M145221</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/117082"&gt;@Vigneswar&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Paige Miller,&lt;BR /&gt;&lt;BR /&gt;Sorry that was a good catch. I wanted my output as Jan_28_2019 .&lt;BR /&gt;&lt;BR /&gt;Let me summarize again.&lt;BR /&gt;&lt;BR /&gt;Lets take I am running a ODS code that generates an xml file and the name of the file should be in this format mon_dd_yyyy. Let it be I run the code on any day in a week, the output date should be monday of that week.&lt;BR /&gt;&lt;BR /&gt;Is the requirement clear enough?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No, it is not clear. You have not defined what you mean by "week". Does it begin on Sunday? Does it being on Monday? Or something else? Please tell us the algorithm by which you have an input date, and you wind up with another date which should be Monday.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jan 2019 13:35:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-to-obtain-date-of-monday-for-a-given-date/m-p/530950#M145221</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-01-29T13:35:32Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro to obtain date of monday for a given date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-to-obtain-date-of-monday-for-a-given-date/m-p/530951#M145222</link>
      <description>&lt;P&gt;Datasteps are far better at manipulating this sort of information and you would be better off not using a macro for this at all. Regardless this should do what you want. I have used the weekdate format so that you can see the Monday. Feel free to modify it to how you want your result to be.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro datein(date="1JAN2019"d);


data _null_;
	/*weekdate format allows us to see the day of the week*/
	format 	HaveDate weekdate.
			WantDate weekdate.
			;

	HaveDate = &amp;amp;date.;
	/*find out how many days away from previous monday*/
	WeekDayNum = mod(weekday(HaveDate) + 5,7);
	/*subtract those dates*/
	WantDate = HaveDate - WeekDayNum;
	/* format the date as desired */
	result=put(WantDate,weekdate.);
	/*save as a macro result*/
	call symputx('WantDate',result,'L');
run;

%put &amp;amp;WantDate.;

%mend;

%datein(date="1JAN2019"d);
%datein(date="10JAN2019"d);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jan 2019 13:33:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-to-obtain-date-of-monday-for-a-given-date/m-p/530951#M145222</guid>
      <dc:creator>DanielLangley</dc:creator>
      <dc:date>2019-01-29T13:33:52Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro to obtain date of monday for a given date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-to-obtain-date-of-monday-for-a-given-date/m-p/530956#M145226</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let t=%sysfunc(today());
%let want=%sysfunc(intnx(week.2,&amp;amp;t,0,b),date9.);
%let want2=%substr(&amp;amp;want,3,3)_%substr(&amp;amp;want,1,2)_%substr(&amp;amp;want,6);
%put &amp;amp;want &amp;amp;want2;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Jan 2019 13:36:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-to-obtain-date-of-monday-for-a-given-date/m-p/530956#M145226</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-01-29T13:36:57Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro to obtain date of monday for a given date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-to-obtain-date-of-monday-for-a-given-date/m-p/530961#M145231</link>
      <description>Thank you so much Ksharp!</description>
      <pubDate>Tue, 29 Jan 2019 13:43:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-to-obtain-date-of-monday-for-a-given-date/m-p/530961#M145231</guid>
      <dc:creator>Vigneswar</dc:creator>
      <dc:date>2019-01-29T13:43:55Z</dc:date>
    </item>
  </channel>
</rss>

