<?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: macro variable of a date in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/macro-variable-of-a-date/m-p/704812#M26194</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/353308"&gt;@SASlearner97&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello everyone, I hopeyou are doing great!&lt;BR /&gt;i want to make a date throught this code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;_null_;&lt;/P&gt;
&lt;P&gt;call&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;symput('week_begins',put(input((today()-weekday(today())+&lt;STRONG&gt;2&lt;/STRONG&gt;-(weekday(today())=&lt;STRONG&gt;0&lt;/STRONG&gt;)),anydtdte10.&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;),date9.)) ;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;%put&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;week_begins;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to get the first day of the current week&lt;/P&gt;
&lt;P&gt;the result of&amp;nbsp;%put&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;week_begins; would be 07/12/2020&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;please help,&lt;/P&gt;
&lt;P&gt;thank you&lt;/P&gt;
&lt;P style="font-weight: 400;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;said, the results you would get in your code once you fix the INTNX function would be 12jul2020 (i.e. the date9 format), which doesn't match your desired format.&amp;nbsp; However, I think you're better off staying with the date9. format.&amp;nbsp; The reason is that it can be used, without further transformation as a &lt;EM&gt;&lt;STRONG&gt;date literal&lt;/STRONG&gt;&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For instance, I would suggest:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data&amp;nbsp;_null_;
  call symputx('week_begins',put(today(),date9.));
run;
%put&amp;nbsp;week_begins;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;because then all you have to do to, (for instance, get a subset) is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data subset;
  set mylib.mydata;
  if date&amp;gt;="&amp;amp;week_begins"d;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This is simply a matter of enclosing the macrovar in double quotes and appending the letter d.&amp;nbsp; It would be slightly messier if the macrovar were in any other date format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 09 Dec 2020 17:15:51 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2020-12-09T17:15:51Z</dc:date>
    <item>
      <title>macro variable of a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-variable-of-a-date/m-p/704769#M26176</link>
      <description>&lt;P&gt;Hello everyone, I hopeyou are doing great!&lt;BR /&gt;i want to make a date throught this code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;_null_;&lt;/P&gt;
&lt;P&gt;call&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;symput('week_begins',put(input((today()-weekday(today())+&lt;STRONG&gt;2&lt;/STRONG&gt;-(weekday(today())=&lt;STRONG&gt;0&lt;/STRONG&gt;)),anydtdte10.&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;),date9.)) ;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;%put&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;week_begins;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to get the first day of the current week&lt;/P&gt;
&lt;P&gt;the result of&amp;nbsp;%put&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;week_begins; would be 07/12/2020&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;please help,&lt;/P&gt;
&lt;P&gt;thank you&lt;/P&gt;
&lt;P style="font-weight: 400;"&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Dec 2020 15:48:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-variable-of-a-date/m-p/704769#M26176</guid>
      <dc:creator>SASlearner97</dc:creator>
      <dc:date>2020-12-09T15:48:06Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable of a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-variable-of-a-date/m-p/704771#M26177</link>
      <description>&lt;P&gt;If you want the first day of the week using the INTNX() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;week_begins=intnx('week',today(),0,'b');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want the string of characters in the macro variable WEEK_BEGINS to be 07/12/2020 why would you use the DATE9 format to generate the string?&amp;nbsp; That will make either 07DEC2020 or 12JUL2020 depending on whether 7 in you example is the day or the month.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call symputx('week_begins',put(...,mmddyys10.));
call symputx('week_begins',put(...,ddmmyys10.));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;How are you planning to USE the macro variable?&amp;nbsp; If you are going to use the value in code to assign or test date values it would be better to just have the raw integer that represents that date.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call symputx('week_begins',...);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Dec 2020 15:59:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-variable-of-a-date/m-p/704771#M26177</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-12-09T15:59:55Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable of a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-variable-of-a-date/m-p/704784#M26179</link>
      <description>when i try &lt;BR /&gt;&lt;BR /&gt;data _null_;&lt;BR /&gt;call symput('week_begins',input((today()weekday(today())+2-(weekday(today())=0)),anydtdte10. )) ;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;it doesnt work either</description>
      <pubDate>Wed, 09 Dec 2020 16:26:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-variable-of-a-date/m-p/704784#M26179</guid>
      <dc:creator>SASlearner97</dc:creator>
      <dc:date>2020-12-09T16:26:16Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable of a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-variable-of-a-date/m-p/704787#M26182</link>
      <description>&lt;P&gt;Please explain with "doesn't work" means.&amp;nbsp; Did you get an error message? Post the lines from the SAS log with the data step and any error message.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What did you think this part of the code meant?&amp;nbsp; It is currently not valid SAS syntax.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;(today()weekday(today())+2-(weekday(today())=0))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Dec 2020 16:34:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-variable-of-a-date/m-p/704787#M26182</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-12-09T16:34:07Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable of a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-variable-of-a-date/m-p/704795#M26186</link>
      <description>by that part of the code i want to get the first day of the week's date, &lt;BR /&gt;but actually that's not a valid SAS syntax</description>
      <pubDate>Wed, 09 Dec 2020 16:48:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-variable-of-a-date/m-p/704795#M26186</guid>
      <dc:creator>SASlearner97</dc:creator>
      <dc:date>2020-12-09T16:48:21Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable of a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-variable-of-a-date/m-p/704804#M26190</link>
      <description>&lt;P&gt;Use INTNX().&amp;nbsp; This will return the date for the Sunday of the current week.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;intnx('week',today(),0,'b')&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Dec 2020 16:57:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-variable-of-a-date/m-p/704804#M26190</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-12-09T16:57:12Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable of a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-variable-of-a-date/m-p/704807#M26191</link>
      <description>i want the starting day of the week to be Monday</description>
      <pubDate>Wed, 09 Dec 2020 17:01:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-variable-of-a-date/m-p/704807#M26191</guid>
      <dc:creator>SASlearner97</dc:creator>
      <dc:date>2020-12-09T17:01:17Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable of a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-variable-of-a-date/m-p/704809#M26192</link>
      <description>&lt;P&gt;Monday is the day after Sunday.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;intnx('week',today(),0,'b')+1&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Dec 2020 17:06:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-variable-of-a-date/m-p/704809#M26192</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-12-09T17:06:01Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable of a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-variable-of-a-date/m-p/704811#M26193</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/353308"&gt;@SASlearner97&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you consider &lt;EM&gt;Monday&lt;/EM&gt; the first day of the week, use&lt;/P&gt;
&lt;PRE&gt;&lt;FONT size="4"&gt;intnx('week&lt;STRONG&gt;&lt;FONT color="#00CCFF"&gt;.2&lt;/FONT&gt;&lt;/STRONG&gt;',today(),0,'b')&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;or shorter (since &lt;FONT face="courier new,courier"&gt;'b'&lt;/FONT&gt; is the default):&lt;/P&gt;
&lt;PRE&gt;&lt;FONT size="4"&gt;intnx('week.2',today(),0)&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;An equivalent of this expression using the WEEKDAY function is&lt;/P&gt;
&lt;PRE&gt;today()-weekday(today())+2-7*(weekday(today())=1)&lt;/PRE&gt;
&lt;P&gt;Perhaps you meant that (but you definitely wouldn't want to apply the INPUT function with a date informat to a SAS date value).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: Note that just adding 1 to the Sunday (which SAS considers the first day of the week, i.e., of the &lt;FONT face="courier new,courier"&gt;'week'&lt;/FONT&gt; interval of the INTNX function) is not equivalent to using the shifted interval &lt;FONT face="courier new,courier"&gt;'week.2'&lt;/FONT&gt;: If "today" is Sunday, the "+1" will lead to the first day of (your)&amp;nbsp;&lt;EM&gt;next&lt;/EM&gt; week.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Dec 2020 17:33:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-variable-of-a-date/m-p/704811#M26193</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-12-09T17:33:48Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable of a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-variable-of-a-date/m-p/704812#M26194</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/353308"&gt;@SASlearner97&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello everyone, I hopeyou are doing great!&lt;BR /&gt;i want to make a date throught this code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;_null_;&lt;/P&gt;
&lt;P&gt;call&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;symput('week_begins',put(input((today()-weekday(today())+&lt;STRONG&gt;2&lt;/STRONG&gt;-(weekday(today())=&lt;STRONG&gt;0&lt;/STRONG&gt;)),anydtdte10.&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;),date9.)) ;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;%put&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;week_begins;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to get the first day of the current week&lt;/P&gt;
&lt;P&gt;the result of&amp;nbsp;%put&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;week_begins; would be 07/12/2020&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;please help,&lt;/P&gt;
&lt;P&gt;thank you&lt;/P&gt;
&lt;P style="font-weight: 400;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;said, the results you would get in your code once you fix the INTNX function would be 12jul2020 (i.e. the date9 format), which doesn't match your desired format.&amp;nbsp; However, I think you're better off staying with the date9. format.&amp;nbsp; The reason is that it can be used, without further transformation as a &lt;EM&gt;&lt;STRONG&gt;date literal&lt;/STRONG&gt;&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For instance, I would suggest:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data&amp;nbsp;_null_;
  call symputx('week_begins',put(today(),date9.));
run;
%put&amp;nbsp;week_begins;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;because then all you have to do to, (for instance, get a subset) is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data subset;
  set mylib.mydata;
  if date&amp;gt;="&amp;amp;week_begins"d;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This is simply a matter of enclosing the macrovar in double quotes and appending the letter d.&amp;nbsp; It would be slightly messier if the macrovar were in any other date format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Dec 2020 17:15:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-variable-of-a-date/m-p/704812#M26194</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-12-09T17:15:51Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable of a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-variable-of-a-date/m-p/704815#M26195</link>
      <description>&lt;P&gt;The difference is how it treats Sunday.&lt;/P&gt;
&lt;PRE&gt;4875  data _null_;
4876  do today=3 to 10;
4877    week_b1 = intnx('week',today,0,'b')+1;
4878    week_b2 = intnx('week.2',today,0,'b');
4879    put today downame.-l +1 (today week:) ( = date9.);
4880  end;
4881  run;

Monday    today=04JAN1960 week_b1=04JAN1960 week_b2=04JAN1960
Tuesday   today=05JAN1960 week_b1=04JAN1960 week_b2=04JAN1960
Wednesday today=06JAN1960 week_b1=04JAN1960 week_b2=04JAN1960
Thursday  today=07JAN1960 week_b1=04JAN1960 week_b2=04JAN1960
Friday    today=08JAN1960 week_b1=04JAN1960 week_b2=04JAN1960
Saturday  today=09JAN1960 week_b1=04JAN1960 week_b2=04JAN1960
&lt;FONT color="#FF0000"&gt;Sunday    today=10JAN1960 week_b1=11JAN1960 week_b2=04JAN1960&lt;/FONT&gt;
Monday    today=11JAN1960 week_b1=11JAN1960 week_b2=11JAN1960
&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Dec 2020 17:27:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-variable-of-a-date/m-p/704815#M26195</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-12-09T17:27:01Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable of a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-variable-of-a-date/m-p/704816#M26196</link>
      <description>data _null_;&lt;BR /&gt;  call symputx('week_begins',put(intnx('week.2',today(),0,'b'),date9.));&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;this what works for me &lt;BR /&gt;&lt;BR /&gt;thank you everyone</description>
      <pubDate>Wed, 09 Dec 2020 17:27:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-variable-of-a-date/m-p/704816#M26196</guid>
      <dc:creator>SASlearner97</dc:creator>
      <dc:date>2020-12-09T17:27:09Z</dc:date>
    </item>
  </channel>
</rss>

