<?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: Problem with dates and conditions in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Problem-with-dates-and-conditions/m-p/616228#M18866</link>
    <description>&lt;P&gt;What is that it is NOT doing? Seems to work for me since today is 09JAN2020.&lt;/P&gt;
&lt;PRE&gt;1051  %let _date=%sysfunc(today(),DDMMYY10.); /* equals to 09/01/2020 in my case */
1052  %let my=%sysfunc(today(),MMYYS.); /* equals to 01/2020 in my case */
1053  %Macro date_success(rc=);
1054  %put &amp;amp;=rc &amp;amp;=_date &amp;amp;=my ;
1055  %if &amp;amp;rc.=0 and &amp;amp;_date.=09/&amp;amp;my. %then %do; /*Here we have normally rc=0 AND _date = 09/&amp;amp;my. =
1055! 09/01/2020*/
1056    %put "====== SUCCESS =============";
1057  %end;
1058  %else %do;
1059    %put "=========== FAILED =========";
1060    %put "10/&amp;amp;my.";
1061  %end;
1062  %mend;
1063
1064  %date_success(rc=1)
RC=1 _DATE=09/01/2020 MY=01/2020
"=========== FAILED ========="
"10/01/2020"
1065  %date_success(rc=0)
RC=0 _DATE=09/01/2020 MY=01/2020
"====== SUCCESS ============="
&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Where do the real values of _DATE and MY come from?&amp;nbsp; Is 09 really in the code?&amp;nbsp; Note that to SAS the string '9/01/2020' is not the same as the string '09/01/2020' so you need to generate those leading zeros consistently.&lt;/P&gt;</description>
    <pubDate>Thu, 09 Jan 2020 15:33:18 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-01-09T15:33:18Z</dc:date>
    <item>
      <title>Problem with dates and conditions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Problem-with-dates-and-conditions/m-p/616218#M18864</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hello everyone,&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to send an email if a file is in a directory or not on the 10th day of the month.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a macro (rc) that is equal to 1 if the file exists, or equal to 0 if the file doesn't exist.&lt;/P&gt;&lt;P&gt;I have a problem when the file doesn't exist and if we are the 10th day of the month.&lt;/P&gt;&lt;P&gt;I did a test with today's date.&lt;/P&gt;&lt;P&gt;Here is my code :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let _date=%sysfunc(today(),DDMMYY10.); /* equals to 09/01/2020 in my case */
%let my=%sysfunc(today(),MMYYS.); /* equals to 01/2020 in my case */
%Macro date_success(rc=);
%if &amp;amp;rc.=0 and &amp;amp;_date.=09/&amp;amp;my. %then %do; /*Here we have normally rc=0 AND _date = 09/&amp;amp;my. = 09/01/2020*/
	%put "====== SUCCESS =============";
%end;
%else %do;
	%put "=========== FAILED =========";
	%put "10/&amp;amp;my.";
%end;
%mend;

%date_success(rc=1) /*Return FAILED as normally planed*/
%date_success(rc=0) /*Doesn't return success, it seems that &amp;amp;_date.=09/&amp;amp;my. doesnt work */&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance for your help !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jan 2020 14:48:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Problem-with-dates-and-conditions/m-p/616218#M18864</guid>
      <dc:creator>Mick_lb</dc:creator>
      <dc:date>2020-01-09T14:48:18Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with dates and conditions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Problem-with-dates-and-conditions/m-p/616222#M18865</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/303367"&gt;@Mick_lb&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is never a good idea to format your macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an attempt to avoid this issue:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let _date=%sysfunc(today());

%Macro date_success(rc=);

%if &amp;amp;rc.=0 and %sysfunc(day(&amp;amp;_date.)) ne 10 %then %do;
	%put "====== SUCCESS =============";
%end;

%else %do;
	%put "=========== FAILED =========";
	%put %sysfunc(putn(&amp;amp;_date.,date9.));
%end;

%mend;

%date_success(rc=1)
%date_success(rc=0)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Jan 2020 15:05:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Problem-with-dates-and-conditions/m-p/616222#M18865</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-01-09T15:05:24Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with dates and conditions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Problem-with-dates-and-conditions/m-p/616228#M18866</link>
      <description>&lt;P&gt;What is that it is NOT doing? Seems to work for me since today is 09JAN2020.&lt;/P&gt;
&lt;PRE&gt;1051  %let _date=%sysfunc(today(),DDMMYY10.); /* equals to 09/01/2020 in my case */
1052  %let my=%sysfunc(today(),MMYYS.); /* equals to 01/2020 in my case */
1053  %Macro date_success(rc=);
1054  %put &amp;amp;=rc &amp;amp;=_date &amp;amp;=my ;
1055  %if &amp;amp;rc.=0 and &amp;amp;_date.=09/&amp;amp;my. %then %do; /*Here we have normally rc=0 AND _date = 09/&amp;amp;my. =
1055! 09/01/2020*/
1056    %put "====== SUCCESS =============";
1057  %end;
1058  %else %do;
1059    %put "=========== FAILED =========";
1060    %put "10/&amp;amp;my.";
1061  %end;
1062  %mend;
1063
1064  %date_success(rc=1)
RC=1 _DATE=09/01/2020 MY=01/2020
"=========== FAILED ========="
"10/01/2020"
1065  %date_success(rc=0)
RC=0 _DATE=09/01/2020 MY=01/2020
"====== SUCCESS ============="
&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Where do the real values of _DATE and MY come from?&amp;nbsp; Is 09 really in the code?&amp;nbsp; Note that to SAS the string '9/01/2020' is not the same as the string '09/01/2020' so you need to generate those leading zeros consistently.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jan 2020 15:33:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Problem-with-dates-and-conditions/m-p/616228#M18866</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-01-09T15:33:18Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with dates and conditions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Problem-with-dates-and-conditions/m-p/616475#M18913</link>
      <description>&lt;P&gt;You are right, this comparison will not work properly:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;amp;_date.=09/&amp;amp;my.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;SAS interprets the slash as division, so it computes 9 divided by &amp;amp;my.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because macro language performs integer arithmetic (dropping any remainders), it is quite likely that 09/&amp;amp;my. yields the exact same result as 10/&amp;amp;my.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your macro variables have no leading or trailing blanks, you can get around that by adding double quotes:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;"&amp;amp;_date."="09/&amp;amp;my."&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jan 2020 14:15:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Problem-with-dates-and-conditions/m-p/616475#M18913</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-01-10T14:15:23Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with dates and conditions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Problem-with-dates-and-conditions/m-p/616479#M18914</link>
      <description>&lt;P&gt;Right.&amp;nbsp; The implicit %EVAL() function call that %IF statement uses will evaluate strings that look like integer arithmetic.&lt;/P&gt;
&lt;P&gt;For your&amp;nbsp; DD/MM/YYYY pattern that is big problem as whatever value day/month gives once you divide it by the much larger year value and you will end up with zero on both sides of the comparison operator.&lt;/P&gt;
&lt;PRE&gt;1160  %put 09/01/2019 -&amp;gt; %eval(09/01/2019) ;
09/01/2019 -&amp;gt; 0
&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 Jan 2020 14:19:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Problem-with-dates-and-conditions/m-p/616479#M18914</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-01-10T14:19:47Z</dc:date>
    </item>
  </channel>
</rss>

