<?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 Creating Variables for Filter with Condition in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-Variables-for-Filter-with-Condition/m-p/704745#M37834</link>
    <description>&lt;P&gt;Hi, everyone!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm working on SAS Guide&amp;nbsp;8.1 Update 1 (8.1.1.4580).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've identified a flaw on my code now that we're going to the next year. It's objective is to create two date variables that I use on a query as a filter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	FORMAT dtini dtfim DATETIME20.;
	dtini_aux = INTNX('YEAR', TODAY(), -1,'B');
	dtfim_aux = INTNX('MONTH', TODAY(), -1,'E');
	dtini=DHMS(dtini_aux,0,0,0);
	dtfim=DHMS(dtfim_aux,23,59,59);
	CALL SYMPUT ('DTINICIAL',dtini);
	CALL SYMPUT ('DTFINAL',dtfim);
RUN;

%PUT &amp;amp;DTINICIAL.;
%PUT &amp;amp;DTFINAL.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;amp;DTINICIAL = initial date&lt;BR /&gt;&amp;amp;DTFINAL = final date&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's currently working as intended, filtering the data from the beginning of the last year until last month. But when we enter 2021, it'll filter only the data from 2020, since the result of&amp;nbsp;&lt;CODE class=" language-sas"&gt;dtini_aux&lt;/CODE&gt;&amp;nbsp;will be Jan/2020. Considering that my result should bring only data from months that are "finished", the correct filter should be Jan/2019 until Dec/2020.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've tried to create a conditional function inside the script above, but it doesn't work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;dtini_aux = CASE WHEN MONTH(TODAY()) = 1 THEN INTNX('YEAR', TODAY(), -2,'B')
	ELSE INTNX('YEAR', TODAY(), -1,'B')
END;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Does anyone know how to adapt this part of the code to solve this problem?&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Wed, 09 Dec 2020 14:44:32 GMT</pubDate>
    <dc:creator>Renan_Crepaldi</dc:creator>
    <dc:date>2020-12-09T14:44:32Z</dc:date>
    <item>
      <title>Creating Variables for Filter with Condition</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-Variables-for-Filter-with-Condition/m-p/704745#M37834</link>
      <description>&lt;P&gt;Hi, everyone!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm working on SAS Guide&amp;nbsp;8.1 Update 1 (8.1.1.4580).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've identified a flaw on my code now that we're going to the next year. It's objective is to create two date variables that I use on a query as a filter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	FORMAT dtini dtfim DATETIME20.;
	dtini_aux = INTNX('YEAR', TODAY(), -1,'B');
	dtfim_aux = INTNX('MONTH', TODAY(), -1,'E');
	dtini=DHMS(dtini_aux,0,0,0);
	dtfim=DHMS(dtfim_aux,23,59,59);
	CALL SYMPUT ('DTINICIAL',dtini);
	CALL SYMPUT ('DTFINAL',dtfim);
RUN;

%PUT &amp;amp;DTINICIAL.;
%PUT &amp;amp;DTFINAL.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;amp;DTINICIAL = initial date&lt;BR /&gt;&amp;amp;DTFINAL = final date&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's currently working as intended, filtering the data from the beginning of the last year until last month. But when we enter 2021, it'll filter only the data from 2020, since the result of&amp;nbsp;&lt;CODE class=" language-sas"&gt;dtini_aux&lt;/CODE&gt;&amp;nbsp;will be Jan/2020. Considering that my result should bring only data from months that are "finished", the correct filter should be Jan/2019 until Dec/2020.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've tried to create a conditional function inside the script above, but it doesn't work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;dtini_aux = CASE WHEN MONTH(TODAY()) = 1 THEN INTNX('YEAR', TODAY(), -2,'B')
	ELSE INTNX('YEAR', TODAY(), -1,'B')
END;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Does anyone know how to adapt this part of the code to solve this problem?&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 09 Dec 2020 14:44:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-Variables-for-Filter-with-Condition/m-p/704745#M37834</guid>
      <dc:creator>Renan_Crepaldi</dc:creator>
      <dc:date>2020-12-09T14:44:32Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Variables for Filter with Condition</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-Variables-for-Filter-with-Condition/m-p/704755#M37835</link>
      <description>&lt;P&gt;CASE/WHEN is SQL syntax, in a data step you use IF/THEN/ELSE:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
FORMAT dtini dtfim DATETIME20.;
if month(today()) = 1
then dtini_aux = INTNX('YEAR', TODAY(), -2,'B');
else dtini_aux = INTNX('YEAR', TODAY(), -1,'B'); 
dtfim_aux = INTNX('MONTH', TODAY(), -1,'E');
dtini=DHMS(dtini_aux,0,0,0);
dtfim=DHMS(dtfim_aux,23,59,59);
CALL SYMPUT ('DTINICIAL',dtini);
CALL SYMPUT ('DTFINAL',dtfim);
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Big hint for the future: do not use tabs in code; set your Enhanced Editor to replace tabs with blanks.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Dec 2020 14:55:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-Variables-for-Filter-with-Condition/m-p/704755#M37835</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-12-09T14:55:31Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Variables for Filter with Condition</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-Variables-for-Filter-with-Condition/m-p/704756#M37836</link>
      <description>Thank you very much, Kurt!&lt;BR /&gt;&lt;BR /&gt;And I'll take the advice.&lt;BR /&gt;&lt;BR /&gt;Regards, Renan</description>
      <pubDate>Wed, 09 Dec 2020 14:58:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-Variables-for-Filter-with-Condition/m-p/704756#M37836</guid>
      <dc:creator>Renan_Crepaldi</dc:creator>
      <dc:date>2020-12-09T14:58:42Z</dc:date>
    </item>
  </channel>
</rss>

