<?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 compare two dates in marcro - help in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/macro-compare-two-dates-in-marcro-help/m-p/616286#M18879</link>
    <description>&lt;P&gt;Thank's Tom, It is working now.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You also said that using the call execute, it is not the better way to do the work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create a process in SAS to create a table that will be used in a spotfire graphic. I would like to make a automatic way to do it. Do you have a suggestion to write it?&lt;/P&gt;</description>
    <pubDate>Thu, 09 Jan 2020 19:17:30 GMT</pubDate>
    <dc:creator>ph10</dc:creator>
    <dc:date>2020-01-09T19:17:30Z</dc:date>
    <item>
      <title>macro compare two dates in marcro - help</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-compare-two-dates-in-marcro-help/m-p/616274#M18872</link>
      <description>&lt;P&gt;Hello, i would like a hand to resolve this macro error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Macro:&lt;/P&gt;&lt;P&gt;---------------------------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;%MACRO datas();&lt;BR /&gt;%GLOBAL DT_sis dt_mvt DtDB2 err nr_unco_ini nr_unco_final nr_unco_tmp;&lt;/P&gt;&lt;P&gt;DATA _NUL_;&lt;BR /&gt;CALL SYMPUT("nr_unco_final", put(&amp;amp;ano, z4.) || put('9999999999999', 13.));&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;/* VERIFICA O DIA DA SEMANA PARA INICIAR OS PROCESSO DE VALIDAÇÃO DE DATAS DO MOVIMENTO, SE FOR SEGUNDA, DEVERÁ SER D-3*/&lt;BR /&gt;DATA _NUL_;&lt;BR /&gt;IF &amp;amp;SYSDAY = Monday THEN&lt;BR /&gt;CALL SYMPUT("dt_sis", PUT(INTNX("DAY",TODAY(),-3), DATE10.));&lt;BR /&gt;ELSE&lt;BR /&gt;CALL SYMPUT("dt_sis", PUT(INTNX("DAY",TODAY(),-1), DATE10.));&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;/*************************************/&lt;/P&gt;&lt;P&gt;/*IDENTIFICA A ÚLTIMA DATA DE MOVIMENTO EM */&lt;BR /&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE DATA AS&lt;BR /&gt;SELECT MAX(DT_MVT) AS DT_REF FORMAT DATE10. FROM tabela de origem&lt;BR /&gt;;&lt;BR /&gt;QUIT;&lt;BR /&gt;/*************************************/&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;/* Get the last movement in the variable dt_mvt*/&lt;BR /&gt;DATA _NULL_;&lt;BR /&gt;SET DATA;&lt;BR /&gt;FORMAT dt_mvt DATE10.;&lt;BR /&gt;INFORMAT dt_mvt DATE10.;&lt;BR /&gt;CALL SYMPUT("dt_mvt",PUT(DT_REF,DATE10.));&lt;BR /&gt;RUN;&lt;BR /&gt;/*************************************/&lt;BR /&gt;DATA _NULL_;&lt;/P&gt;&lt;P&gt;call symput("DtDB2", COMPRESS("'" || PUT(day("&amp;amp;dt_mvt"d),Z2.) || '.'&lt;BR /&gt;|| PUT(month("&amp;amp;dt_mvt"d),Z2.) || '.'&lt;BR /&gt;|| PUT(Year("&amp;amp;DT_MVT"d), Z4.) || "'"));&lt;BR /&gt;RUN;&lt;BR /&gt;%mend;&lt;BR /&gt;%datas;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data _null_;&lt;BR /&gt;call execute('%datas;');&lt;BR /&gt;If &amp;amp;dt_sis NE &amp;amp;dt_mvt then do;&lt;BR /&gt;%put 'EVG não atualizado.';&lt;BR /&gt;end;&lt;BR /&gt;else do;&lt;BR /&gt;put 'EVG atualizado.';&lt;BR /&gt;stop;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;----------------------------------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;mensagem de erro:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;26 data _null_;&lt;BR /&gt;27 call execute('%datas;');&lt;BR /&gt;SYMBOLGEN: Macro variable DT_SIS resolves to 06JAN2020&lt;BR /&gt;SYMBOLGEN: Macro variable DT_MVT resolves to 08JAN2020&lt;BR /&gt;28 If &amp;amp;dt_sis NE &amp;amp;dt_mvt then do;&lt;BR /&gt;NOTE: Line generated by the macro variable "DT_SIS".&lt;BR /&gt;28 06JAN2020&lt;BR /&gt;_______&lt;BR /&gt;22&lt;BR /&gt;NOTE: Line generated by the macro variable "DT_MVT".&lt;BR /&gt;28 08JAN2020&lt;BR /&gt;_______&lt;BR /&gt;388&lt;BR /&gt;76&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, *, **, +, -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;&amp;lt;, &amp;gt;=, AND, EQ, GE, GT, IN,&lt;BR /&gt;LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=, |, ||, ~=.&lt;/P&gt;&lt;P&gt;ERROR 388-185: Expecting an arithmetic operator.&lt;/P&gt;&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;&lt;P&gt;29 %put 'EVG não atualizado.';&lt;BR /&gt;'EVG não atualizado.'&lt;BR /&gt;30 end;&lt;BR /&gt;___&lt;BR /&gt;161&lt;BR /&gt;ERROR 161-185: No matching DO/SELECT statement.&lt;/P&gt;&lt;P&gt;31 else do;&lt;BR /&gt;32 put 'EVG atualizado.';&lt;BR /&gt;2 The SAS System 15:06 Thursday, January 9, 2020&lt;/P&gt;&lt;P&gt;33 stop;&lt;BR /&gt;34 end;&lt;BR /&gt;35 run;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jan 2020 18:36:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-compare-two-dates-in-marcro-help/m-p/616274#M18872</guid>
      <dc:creator>ph10</dc:creator>
      <dc:date>2020-01-09T18:36:56Z</dc:date>
    </item>
    <item>
      <title>Re: macro compare two dates in marcro - help</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-compare-two-dates-in-marcro-help/m-p/616277#M18873</link>
      <description>&lt;P&gt;The way to reference a date literal in SAS code is a quoted string that the DATE informat can understand with the letter D at the end.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;If "06JAN2020"d NE "08JAN2020"d  then do;
  ...
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To get your macro variables as constructed to generate code like that you need add the quotes and D into your code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;If "&amp;amp;dt_sis"d NE "&amp;amp;dt_mvt"d then do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that your use of macro and SAS code is very messed up.&amp;nbsp; For example you have replaced the ... in my example above with the macro statement %PUT.&amp;nbsp; When SAS runs your code it will evaluate the macro statement while is is reading the text and trying to compiler the data set.&amp;nbsp; So the %PUT will always run before the data step even starts running. So whether the condition in the IF statement is true or false will not matter.&amp;nbsp; If instead you used a PUT statement it might make more sense.&amp;nbsp; Also using CALL EXECUTE to try to run the macro %DATAS doesn't make any sense.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%datas;

data _null_;
  if "&amp;amp;dt_sis"d &amp;lt;= "&amp;amp;dt_mvt"d then do;
    put 'EVG não atualizado.';
  end;
  else do;
    put 'EVG atualizado.';
  end;
  stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you really do need to use those ddMMMyyyy strings in macro logic then you need to use %SYSEVALF() as the %EVAL() that macro processor normally uses to evaluate conditions in %IF statements only understands text comparisons and integer arithmetic so it does not understand date literals.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%datas;

%if %sysevalf("&amp;amp;dt_sis"d &amp;lt;= "&amp;amp;dt_mvt"d) %then %do;
    %put EVG não atualizado.;
%end;
%else %do;
    %put EVG atualizado.;
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;You might get better results not making the macro variables using any date format at all. Instead just store the string of digits that represent the number of days that SAS uses to store those dates.&amp;nbsp; So don't use the PUT() function when generating the value to put into the macro variable.&amp;nbsp; Then your code that just compared the value of the two macro variables will work in either SAS logic or macro logic.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jan 2020 18:57:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-compare-two-dates-in-marcro-help/m-p/616277#M18873</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-01-09T18:57:26Z</dc:date>
    </item>
    <item>
      <title>Re: macro compare two dates in marcro - help</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-compare-two-dates-in-marcro-help/m-p/616286#M18879</link>
      <description>&lt;P&gt;Thank's Tom, It is working now.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You also said that using the call execute, it is not the better way to do the work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create a process in SAS to create a table that will be used in a spotfire graphic. I would like to make a automatic way to do it. Do you have a suggestion to write it?&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jan 2020 19:17:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-compare-two-dates-in-marcro-help/m-p/616286#M18879</guid>
      <dc:creator>ph10</dc:creator>
      <dc:date>2020-01-09T19:17:30Z</dc:date>
    </item>
    <item>
      <title>Re: macro compare two dates in marcro - help</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-compare-two-dates-in-marcro-help/m-p/616289#M18881</link>
      <description>CALL EXECUTE() is useful if the code you want to pass needs to be built from data you have in a SAS dataset.  You might also use it conditionally generate code since you could potentially avoid the need to create a macro (or at least another macro) so that you can run macro logic.  Instead you could just use data step logic to decide which CALL EXECUTE() statements execute. Remember that the code is generated by the CALL EXECUTE() statement runs after the data step that is running the CALL EXECUTE() statement.&lt;BR /&gt;If you want more detailed help start a new question with the details of what you are trying to do and what question(s) you are having trouble with.&lt;BR /&gt;</description>
      <pubDate>Thu, 09 Jan 2020 19:26:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-compare-two-dates-in-marcro-help/m-p/616289#M18881</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-01-09T19:26:05Z</dc:date>
    </item>
    <item>
      <title>Re: macro compare two dates in marcro - help</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-compare-two-dates-in-marcro-help/m-p/616298#M18883</link>
      <description>&lt;P&gt;You make your coding so much harder by trying to turn the SAS dates (which are integers representing number of days since 1/1/1960) like 21789 into human readable text strings like 08SEP19. This part of code simply isn't necessary:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA _NULL_;

call symput("DtDB2", COMPRESS("'" || PUT(day("&amp;amp;dt_mvt"d),Z2.) || '.'
|| PUT(month("&amp;amp;dt_mvt"d),Z2.) || '.'
|| PUT(Year("&amp;amp;DT_MVT"d), Z4.) || "'"));
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;There are many other examples in your code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Leave dates as integers, unformatted. This simplifies everything and reduces the likelihood of errors. You would only want to format macro variables if they were needed for titles or labels, where humans need to see a recognizable date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jan 2020 19:33:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-compare-two-dates-in-marcro-help/m-p/616298#M18883</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-01-09T19:33:54Z</dc:date>
    </item>
    <item>
      <title>Re: macro compare two dates in marcro - help</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-compare-two-dates-in-marcro-help/m-p/616306#M18888</link>
      <description>&lt;P&gt;I used that code because if the the date of the sistem and the last the of the table are different, i will start a process to update that table and the source of that is a DB2 table, that's why i am transforming that&amp;nbsp; date. Do you suggest a better way, Tom?&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jan 2020 20:05:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-compare-two-dates-in-marcro-help/m-p/616306#M18888</guid>
      <dc:creator>ph10</dc:creator>
      <dc:date>2020-01-09T20:05:25Z</dc:date>
    </item>
    <item>
      <title>Re: macro compare two dates in marcro - help</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-compare-two-dates-in-marcro-help/m-p/616312#M18890</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/305468"&gt;@ph10&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I used that code because if the the date of the sistem and the last the of the table are different, i will start a process to update that table and the source of that is a DB2 table, that's why i am transforming that&amp;nbsp; date. Do you suggest a better way, Tom?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The details matter a lot.&amp;nbsp; No need to format the data values to compare them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let now=%sysfunc(date());
proc sql ;
  select max(rundate) into last_run from some_dataset ;
quit;

%if &amp;amp;rundate &amp;lt; &amp;amp;now %then %do;
.... code to update ...
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you are pushing date literals into DB2 then you need to know how to format them for us in your DB2 code.&amp;nbsp; For example many database systems will allow you to use a date value in yyyy-mm-dd style inside of single quotes.&amp;nbsp; So if I wanted to convert the date values in the macro variable LAST_RUN used in the above code into that form I might use code like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  call symputx('last_run_db2',quote(put(&amp;amp;last_run,yymmdd10.),"'"));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So then I could use that macro variable in my DB2 code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
connect to db2 ..... ;
execute by db2
(  ... my DB2 code ... WHERE date &amp;gt; &amp;amp;last_run_db2 .... )
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jan 2020 20:18:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-compare-two-dates-in-marcro-help/m-p/616312#M18890</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-01-09T20:18:45Z</dc:date>
    </item>
    <item>
      <title>Re: macro compare two dates in marcro - help</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-compare-two-dates-in-marcro-help/m-p/616324#M18892</link>
      <description>&lt;P&gt;i am not tryaing to put the into DB2, but extracting from a db2 table. The&amp;nbsp; whole process will write only8 SAS table, but i need to get the datas from DB2 tables, if it is not updated.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jan 2020 20:50:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-compare-two-dates-in-marcro-help/m-p/616324#M18892</guid>
      <dc:creator>ph10</dc:creator>
      <dc:date>2020-01-09T20:50:43Z</dc:date>
    </item>
  </channel>
</rss>

