<?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: Max date (DATA SET) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Max-date-DATA-SET/m-p/339767#M77549</link>
    <description>&lt;P&gt;Few remarks to your code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) You can join the first two steps into one:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA DUTIL_MENOS_2;
	ATTRIB DIA_MENOS_2 FORMAT=DDMMYY10.                  
                      INFORMAT=DDMMYY10. LENGTH=8.;
       DIA_MENOS_2 = INTNX('WEEKDAY',TODAY(),-2);
       CALL SYMPUT("DIA_MENOS_2", DIA_MENOS_2);
RUN;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;2) What did you mean by next line:&lt;/P&gt;
&lt;PRE&gt;MAIOR_DIA = MAX(DATA_FORMALIZACAO);&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;sas is working row by row. Redaing first row , if it isn't the date - you enter the sleep mode.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;Besides you have a mismach of datastep statement (do until) with macro code (%do %until).&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;You can't use it as you have done.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3) to calculate max value of a column, you can use sql:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
     select  MAX(DATA_FORMALIZACAO) into: MAIOR_DIA 
      from BASE_X;&lt;BR /&gt;quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; then you can check in a separate datastep if to continue or sleep.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;4) Did you mean to sleap 60 seconds, and then what do you want to do ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Iguess you want next code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO VERIFICAR_DIA();
   DATA DUTIL_MENOS_2;
        ATTRIB DIA_MENOS_2 FORMAT=DDMMYY10. 
        INFORMAT=DDMMYY10. LENGTH=8.;
	DIA_MENOS_2 = INTNX('WEEKDAY',TODAY(),-2);
	CALL SYMPUT("DIA_MENOS_2", DIA_MENOS_2);
   RUN;
&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;   proc sql;
     select  MAX(DATA_FORMALIZACAO) into: MAIOR_DIA 
      from BASE_X;&lt;BR /&gt;   quit;&lt;BR /&gt;&lt;BR /&gt;   data _NULL_;&lt;BR /&gt;      dia_menos_2 = symget(&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;"DIA_MENOS_2");&lt;BR /&gt;&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;      MAIOR_DIA = symget("MAIOR_DIA");&lt;BR /&gt;      if maior_dia = dia_menos_2 then call symput('SLEEP','NO');&lt;BR /&gt;      else call symput('SLEEP','YES');&lt;BR /&gt;   run;&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;&lt;BR /&gt;   %if &amp;amp;sleep = NO %then %do;&lt;BR /&gt;&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;       DATA TESTE; &lt;BR /&gt;         SET BASE_X; &lt;BR /&gt;         ATTRIB MAIOR_DIA FORMAT=DDMMYY10. INFORMAT=DDMMYY10. LENGTH=8.; &lt;BR /&gt;         MAIOR_DIA =&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;symget("MAIOR_DIA");&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;&lt;BR /&gt;       run;&lt;BR /&gt;   %end; %else %do;&lt;BR /&gt;      data _NULL_;&lt;BR /&gt;         CALL SLEEP(60); &lt;BR /&gt;      run;&lt;BR /&gt;    %END; &lt;BR /&gt;%MEND;&lt;BR /&gt;%VERIFICAR_DIA();&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;5) Have you considered a situation where&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;maior_dia &amp;gt; dia_menos_2&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 09 Mar 2017 20:12:23 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2017-03-09T20:12:23Z</dc:date>
    <item>
      <title>Max date (DATA SET)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Max-date-DATA-SET/m-p/339735#M77540</link>
      <description>&lt;P&gt;I'm trying to verify if a database is refreshed in businessday -2. I have used the following code, but when I run the program it always stays in sleep mode! What can I do to solve this problem? &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%DO %UNTIL(&amp;amp;DIA_MENOS_2. = MAIOR_DIA);&lt;BR /&gt;MAIOR_DIA = MAX(DATA_FORMALIZACAO);&lt;BR /&gt;CALL SLEEP(60);&lt;BR /&gt;%END;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FULL CODE:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO VERIFICAR_DIA();&lt;BR /&gt;DATA DUTIL_MENOS_2;

		ATTRIB DIA_MENOS_2 FORMAT=DDMMYY10. INFORMAT=DDMMYY10. LENGTH=8.;

		DIA_MENOS_2 = INTNX('WEEKDAY',TODAY(),-2);

	RUN;

	DATA _null_;
		SET WORK.DUTIL_MENOS_2;

		CALL SYMPUT("DIA_MENOS_2", DIA_MENOS_2);
	RUN;

	DATA TESTE;
		SET BASE_X;
		
		ATTRIB MAIOR_DIA FORMAT=DDMMYY10. INFORMAT=DDMMYY10. LENGTH=8.;
		MAIOR_DIA = MAX(DATA_FORMALIZACAO);
		
		%DO %UNTIL(&amp;amp;DIA_MENOS_2. = MAIOR_DIA);
			MAIOR_DIA = MAX(DATA_FORMALIZACAO);
			CALL SLEEP(60);
		%END;
	RUN;&lt;BR /&gt;%MEND;&lt;BR /&gt;%VERIFICAR_DIA();&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Mar 2017 18:53:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Max-date-DATA-SET/m-p/339735#M77540</guid>
      <dc:creator>Bottoni</dc:creator>
      <dc:date>2017-03-09T18:53:01Z</dc:date>
    </item>
    <item>
      <title>Re: Max date (DATA SET)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Max-date-DATA-SET/m-p/339767#M77549</link>
      <description>&lt;P&gt;Few remarks to your code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) You can join the first two steps into one:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA DUTIL_MENOS_2;
	ATTRIB DIA_MENOS_2 FORMAT=DDMMYY10.                  
                      INFORMAT=DDMMYY10. LENGTH=8.;
       DIA_MENOS_2 = INTNX('WEEKDAY',TODAY(),-2);
       CALL SYMPUT("DIA_MENOS_2", DIA_MENOS_2);
RUN;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;2) What did you mean by next line:&lt;/P&gt;
&lt;PRE&gt;MAIOR_DIA = MAX(DATA_FORMALIZACAO);&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;sas is working row by row. Redaing first row , if it isn't the date - you enter the sleep mode.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;Besides you have a mismach of datastep statement (do until) with macro code (%do %until).&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;You can't use it as you have done.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3) to calculate max value of a column, you can use sql:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
     select  MAX(DATA_FORMALIZACAO) into: MAIOR_DIA 
      from BASE_X;&lt;BR /&gt;quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; then you can check in a separate datastep if to continue or sleep.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;4) Did you mean to sleap 60 seconds, and then what do you want to do ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Iguess you want next code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO VERIFICAR_DIA();
   DATA DUTIL_MENOS_2;
        ATTRIB DIA_MENOS_2 FORMAT=DDMMYY10. 
        INFORMAT=DDMMYY10. LENGTH=8.;
	DIA_MENOS_2 = INTNX('WEEKDAY',TODAY(),-2);
	CALL SYMPUT("DIA_MENOS_2", DIA_MENOS_2);
   RUN;
&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;   proc sql;
     select  MAX(DATA_FORMALIZACAO) into: MAIOR_DIA 
      from BASE_X;&lt;BR /&gt;   quit;&lt;BR /&gt;&lt;BR /&gt;   data _NULL_;&lt;BR /&gt;      dia_menos_2 = symget(&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;"DIA_MENOS_2");&lt;BR /&gt;&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;      MAIOR_DIA = symget("MAIOR_DIA");&lt;BR /&gt;      if maior_dia = dia_menos_2 then call symput('SLEEP','NO');&lt;BR /&gt;      else call symput('SLEEP','YES');&lt;BR /&gt;   run;&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;&lt;BR /&gt;   %if &amp;amp;sleep = NO %then %do;&lt;BR /&gt;&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;       DATA TESTE; &lt;BR /&gt;         SET BASE_X; &lt;BR /&gt;         ATTRIB MAIOR_DIA FORMAT=DDMMYY10. INFORMAT=DDMMYY10. LENGTH=8.; &lt;BR /&gt;         MAIOR_DIA =&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;symget("MAIOR_DIA");&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;&lt;BR /&gt;       run;&lt;BR /&gt;   %end; %else %do;&lt;BR /&gt;      data _NULL_;&lt;BR /&gt;         CALL SLEEP(60); &lt;BR /&gt;      run;&lt;BR /&gt;    %END; &lt;BR /&gt;%MEND;&lt;BR /&gt;%VERIFICAR_DIA();&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;5) Have you considered a situation where&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;maior_dia &amp;gt; dia_menos_2&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Mar 2017 20:12:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Max-date-DATA-SET/m-p/339767#M77549</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-03-09T20:12:23Z</dc:date>
    </item>
    <item>
      <title>Re: Max date (DATA SET)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Max-date-DATA-SET/m-p/339769#M77550</link>
      <description>&lt;P&gt;Much confusion this code has!&lt;/P&gt;
&lt;P&gt;Not too sure what you are attempting to do, but at least these 2 things raise questions:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1-You cannot use %do %until and test a dataset variable.&lt;/P&gt;
&lt;P&gt;The macro&amp;nbsp;statements&amp;nbsp;will be executed before any data is read.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2-Note that:&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;MAIOR_DIA &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;MAX&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;DATA_FORMALIZACAO&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;does nothing more than &lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;MAIOR_DIA &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; DATA_FORMALIZACAO&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Mar 2017 20:13:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Max-date-DATA-SET/m-p/339769#M77550</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-03-09T20:13:29Z</dc:date>
    </item>
    <item>
      <title>Re: Max date (DATA SET)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Max-date-DATA-SET/m-p/339781#M77553</link>
      <description>&lt;P&gt;Thank you very much Shmuel.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;"Did you mean to sleap 60 seconds, and then what do you want to do ?" After that, I want verify again if the data has refreshed and run a "query". Otherwise I call the funcion sleep again.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"Have you considered a situation where"&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;maior_dia &lt;SPAN class="token operator"&gt;&amp;gt;&lt;/SPAN&gt; dia_menos_2&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Yes, I do. The data refreshes each two days, because of that maior_dia (last day that appears in the data) will never be greater than dia_menos_2 (today - 2).&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Mar 2017 20:57:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Max-date-DATA-SET/m-p/339781#M77553</guid>
      <dc:creator>Bottoni</dc:creator>
      <dc:date>2017-03-09T20:57:15Z</dc:date>
    </item>
  </channel>
</rss>

