<?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 Macro date not bringing correct date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-date-not-bringing-correct-date/m-p/372859#M276138</link>
    <description>I have a macro that looks into a daily file with yesterday date .I need to import it which works but if I need to bring last month data it keeps giving me july date here is macro&lt;BR /&gt;&lt;BR /&gt;Option symbolgen ;&lt;BR /&gt;%let day2 =%sysfunc (day ( %sysfunc (intnx (day, "&amp;amp;sysdate"d,-3,b))));&lt;BR /&gt;Symbolgen: Macro variable sysdate resolves to 03jul17&lt;BR /&gt;%let month=.;&lt;BR /&gt;%let month2=%sysfunc (month ("&amp;amp;sysdate"d));&lt;BR /&gt;Symbolgen : macro variable sysdate resolves to 03jul17&lt;BR /&gt;%let month=.;&lt;BR /&gt;%let year=% sysfunc (year ("&amp;amp;sysdate"d));&lt;BR /&gt;Symbolgen: macro variable sysdate resolves to 03nul17&lt;BR /&gt;%let dash=_;&lt;BR /&gt;%put &amp;amp;day2 &amp;amp;month2 &amp;amp;year2 ;&lt;BR /&gt;Symbolgen: macro variable day2 resolves to 30&lt;BR /&gt;Symbolgen: Macro variable month2 resolves to 7&lt;BR /&gt;Symbolgen: macro variable year resolve to 2017&lt;BR /&gt;30 7 2017&lt;BR /&gt;% macro setdates;&lt;BR /&gt;%if &amp;amp;day2 &amp;lt;10 %then %let day=0days2.;&lt;BR /&gt;%else %let day=&amp;amp;day2.;&lt;BR /&gt;%if &amp;amp;month2 &amp;lt;10 %then %let month=0&amp;amp;month2.;&lt;BR /&gt;%else %let month=&amp;amp;month2.;&lt;BR /&gt;%put &amp;amp;day &amp;amp;month &amp;amp;year ;&lt;BR /&gt;%mend;&lt;BR /&gt;I need it to pull data from June it keeps bringing july data&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Mon, 03 Jul 2017 21:11:25 GMT</pubDate>
    <dc:creator>Gil_</dc:creator>
    <dc:date>2017-07-03T21:11:25Z</dc:date>
    <item>
      <title>Macro date not bringing correct date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-date-not-bringing-correct-date/m-p/372859#M276138</link>
      <description>I have a macro that looks into a daily file with yesterday date .I need to import it which works but if I need to bring last month data it keeps giving me july date here is macro&lt;BR /&gt;&lt;BR /&gt;Option symbolgen ;&lt;BR /&gt;%let day2 =%sysfunc (day ( %sysfunc (intnx (day, "&amp;amp;sysdate"d,-3,b))));&lt;BR /&gt;Symbolgen: Macro variable sysdate resolves to 03jul17&lt;BR /&gt;%let month=.;&lt;BR /&gt;%let month2=%sysfunc (month ("&amp;amp;sysdate"d));&lt;BR /&gt;Symbolgen : macro variable sysdate resolves to 03jul17&lt;BR /&gt;%let month=.;&lt;BR /&gt;%let year=% sysfunc (year ("&amp;amp;sysdate"d));&lt;BR /&gt;Symbolgen: macro variable sysdate resolves to 03nul17&lt;BR /&gt;%let dash=_;&lt;BR /&gt;%put &amp;amp;day2 &amp;amp;month2 &amp;amp;year2 ;&lt;BR /&gt;Symbolgen: macro variable day2 resolves to 30&lt;BR /&gt;Symbolgen: Macro variable month2 resolves to 7&lt;BR /&gt;Symbolgen: macro variable year resolve to 2017&lt;BR /&gt;30 7 2017&lt;BR /&gt;% macro setdates;&lt;BR /&gt;%if &amp;amp;day2 &amp;lt;10 %then %let day=0days2.;&lt;BR /&gt;%else %let day=&amp;amp;day2.;&lt;BR /&gt;%if &amp;amp;month2 &amp;lt;10 %then %let month=0&amp;amp;month2.;&lt;BR /&gt;%else %let month=&amp;amp;month2.;&lt;BR /&gt;%put &amp;amp;day &amp;amp;month &amp;amp;year ;&lt;BR /&gt;%mend;&lt;BR /&gt;I need it to pull data from June it keeps bringing july data&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 03 Jul 2017 21:11:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-date-not-bringing-correct-date/m-p/372859#M276138</guid>
      <dc:creator>Gil_</dc:creator>
      <dc:date>2017-07-03T21:11:25Z</dc:date>
    </item>
    <item>
      <title>Re: Macro date not bringing correct date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-date-not-bringing-correct-date/m-p/372871#M276139</link>
      <description>&lt;P&gt;What do you want as final output? The day/month/year for last month?&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jul 2017 21:53:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-date-not-bringing-correct-date/m-p/372871#M276139</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-03T21:53:55Z</dc:date>
    </item>
    <item>
      <title>Re: Macro date not bringing correct date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-date-not-bringing-correct-date/m-p/372872#M276140</link>
      <description>&lt;P&gt;You're making something that is relatively easy appear to be incredibly difficult. &amp;nbsp;Why not start with this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let cutoff_date = %eval("&amp;amp;sysdate9"d - 3);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need to (and there is no guarantee that you need to do this ... you haven't shown us what follows to extract data):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let cutoff_date = %sysfunc(putn(&amp;amp;cutoff_date, date9));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could use this instead, but it's not very useful for selecting observations in subsequent steps:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let cutoff_date = %sysfunc(putn(&amp;amp;cutoff_date, yymmdd10));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jul 2017 22:03:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-date-not-bringing-correct-date/m-p/372872#M276140</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-07-03T22:03:13Z</dc:date>
    </item>
    <item>
      <title>Re: Macro date not bringing correct date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-date-not-bringing-correct-date/m-p/372873#M276141</link>
      <description>Correct for example if I do a -5 based on today date bring back 6/ 28/17 ...</description>
      <pubDate>Mon, 03 Jul 2017 22:04:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-date-not-bringing-correct-date/m-p/372873#M276141</guid>
      <dc:creator>Gil_</dc:creator>
      <dc:date>2017-07-03T22:04:22Z</dc:date>
    </item>
    <item>
      <title>Re: Macro date not bringing correct date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-date-not-bringing-correct-date/m-p/372874#M276142</link>
      <description>Astounding sorry I inherited the code it was working when we were in June and now in July it just just brings july data</description>
      <pubDate>Mon, 03 Jul 2017 22:06:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-date-not-bringing-correct-date/m-p/372874#M276142</guid>
      <dc:creator>Gil_</dc:creator>
      <dc:date>2017-07-03T22:06:45Z</dc:date>
    </item>
    <item>
      <title>Re: Macro date not bringing correct date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-date-not-bringing-correct-date/m-p/372875#M276143</link>
      <description>&lt;P&gt;You may have to explain this in words. &amp;nbsp;If the program runs today, what date would you like it to return? &amp;nbsp;You had hard-coded -3 in your original post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When it comes to selecting data, you will have to show the portion of your code that uses the results to select data as well. &amp;nbsp;This section just creates macro variables that are used to select data at a later (unknown to us) point.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jul 2017 22:08:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-date-not-bringing-correct-date/m-p/372875#M276143</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-07-03T22:08:21Z</dc:date>
    </item>
    <item>
      <title>Re: Macro date not bringing correct date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-date-not-bringing-correct-date/m-p/372877#M276144</link>
      <description>The script runs daily -1 I noticed I was missing dates in June so I counted backwards to get dated I need --5,-7-9...</description>
      <pubDate>Mon, 03 Jul 2017 22:09:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-date-not-bringing-correct-date/m-p/372877#M276144</guid>
      <dc:creator>Gil_</dc:creator>
      <dc:date>2017-07-03T22:09:30Z</dc:date>
    </item>
    <item>
      <title>Re: Macro date not bringing correct date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-date-not-bringing-correct-date/m-p/372878#M276145</link>
      <description>It seems like the month portion is just looking at current month doesn't allow to go further than july</description>
      <pubDate>Mon, 03 Jul 2017 22:10:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-date-not-bringing-correct-date/m-p/372878#M276145</guid>
      <dc:creator>Gil_</dc:creator>
      <dc:date>2017-07-03T22:10:35Z</dc:date>
    </item>
    <item>
      <title>Re: Macro date not bringing correct date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-date-not-bringing-correct-date/m-p/372879#M276146</link>
      <description />
      <pubDate>Mon, 03 Jul 2017 22:10:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-date-not-bringing-correct-date/m-p/372879#M276146</guid>
      <dc:creator>Gil_</dc:creator>
      <dc:date>2017-07-03T22:10:51Z</dc:date>
    </item>
    <item>
      <title>Re: Macro date not bringing correct date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-date-not-bringing-correct-date/m-p/372880#M276147</link>
      <description>&lt;P&gt;You will have to explain a little more. &amp;nbsp;For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"If I run the program on any day during July, I want it to return a date that is the last date in June."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If that is what you want, it's easy enough to do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let cutoff_date = %sysfunc(intnx(month, "&amp;amp;sysdate9"d, -1, e));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you haven't yet described if that is what you need, and you absolutely need to show the later code that uses this date because the format of &amp;amp;CUTOFF_DATE will have to be adjusted to fit the format expected by the program.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jul 2017 22:16:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-date-not-bringing-correct-date/m-p/372880#M276147</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-07-03T22:16:18Z</dc:date>
    </item>
    <item>
      <title>Re: Macro date not bringing correct date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-date-not-bringing-correct-date/m-p/372883#M276148</link>
      <description>Normally it will run -1 for yesterday date ... so if I need to back track 5 days I would pull by change day -1 To -5 To get that date.i will try your suggestion see if that works once it id the correct date it looks for it in the directory for that date and imports in file with the date i select -1 or-5 that works...its id the correct date</description>
      <pubDate>Mon, 03 Jul 2017 22:44:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-date-not-bringing-correct-date/m-p/372883#M276148</guid>
      <dc:creator>Gil_</dc:creator>
      <dc:date>2017-07-03T22:44:32Z</dc:date>
    </item>
    <item>
      <title>Re: Macro date not bringing correct date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-date-not-bringing-correct-date/m-p/372885#M276149</link>
      <description>&lt;P&gt;SYSDATE is the date which your session started running. You may want to use the DATE() function to return todays date.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;gt;Contains the date on which a SAS job or session began executing.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/69726/HTML/default/viewer.htm#n08zfkx3lmiagpn11fctkfvfx1sg.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/69726/HTML/default/viewer.htm#n08zfkx3lmiagpn11fctkfvfx1sg.htm&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jul 2017 23:34:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-date-not-bringing-correct-date/m-p/372885#M276149</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-03T23:34:15Z</dc:date>
    </item>
    <item>
      <title>Re: Macro date not bringing correct date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-date-not-bringing-correct-date/m-p/372927#M276150</link>
      <description>&lt;P&gt;You never got June in your month because you set it once from &amp;amp;sysdate, but did not manipulate it the way you did with &amp;amp;day2.&lt;/P&gt;
&lt;P&gt;And you have lots of confusion regarding day, day2, month, month2, year, year2.&lt;/P&gt;
&lt;P&gt;Basically, that code is a total abomination. Discard it completely and rewrite it from scratch, according to what you need in the end.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, to get year, month and day, I'd do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
todays_date = today() - 5;
day = day(todays_date);
month = month(todays_date);
year = year(todays_date);
call symput('day',put(day,z2.));
call symput('month',put(month,z2.));
call symput('year',put(year,z4.));
run;
%put &amp;amp;day &amp;amp;month &amp;amp;year;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that you don't need the intnx function if you just want to subtract days.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jul 2017 06:46:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-date-not-bringing-correct-date/m-p/372927#M276150</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-07-04T06:46:08Z</dc:date>
    </item>
    <item>
      <title>Re: Macro date not bringing correct date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-date-not-bringing-correct-date/m-p/372928#M276151</link>
      <description>&lt;P&gt;Oh yeah, and use the {i} button to post a log. The {i} subwindow uses a fixed font and preserves all original formatting and characters.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jul 2017 06:51:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-date-not-bringing-correct-date/m-p/372928#M276151</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-07-04T06:51:28Z</dc:date>
    </item>
    <item>
      <title>Re: Macro date not bringing correct date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-date-not-bringing-correct-date/m-p/373076#M276152</link>
      <description>&lt;P&gt;You are calculating the MONTH and YEAR from the wrong date. &amp;nbsp;Also no need for macro logic to get zero padded numbers, just use a format when you generate the macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let mydate=%sysfunc(intnx(day,"&amp;amp;sysdate9"d,-3),date9);
%let day=%sysfunc(day("&amp;amp;mydate"d),z2);
%let month=%sysfunc(month("&amp;amp;mydate"d),z2);
%let year=%sysfunc(year("&amp;amp;mydate"d),z4);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;%put &amp;amp;=sysdate9 &amp;amp;=mydate &amp;amp;=day &amp;amp;=month &amp;amp;=year ;
SYSDATE9=02JUL2017 MYDATE=29JUN2017 DAY=29 MONTH=06 YEAR=2017&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Jul 2017 18:59:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-date-not-bringing-correct-date/m-p/373076#M276152</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-07-04T18:59:26Z</dc:date>
    </item>
  </channel>
</rss>

