<?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: mainframe SAS: code is not working please. extract(year from(add_months(&amp;amp;tera_dt1, -&amp;amp;lap in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/mainframe-SAS-code-is-not-working-please-extract-year-from-add/m-p/758839#M239683</link>
    <description>&lt;P&gt;There is neither a EXTRACT nor a ADD_MONTHS function in SAS. You should look into the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/lefunctionsref/p10v3sa3i4kfxfn1sovhi5xzxh8n.htm" target="_blank" rel="noopener"&gt;INTNX&lt;/A&gt; function for calculating intervals, and the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/lefunctionsref/p13eycdrmfb0l8n1492z3wocpt3s.htm" target="_blank" rel="noopener"&gt;YEAR&lt;/A&gt; function for getting the year from a date.&lt;/P&gt;</description>
    <pubDate>Mon, 02 Aug 2021 17:01:50 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-08-02T17:01:50Z</dc:date>
    <item>
      <title>mainframe SAS: code is not working please. extract(year from(add_months(&amp;tera_dt1, -&amp;lapse) ))</title>
      <link>https://communities.sas.com/t5/SAS-Programming/mainframe-SAS-code-is-not-working-please-extract-year-from-add/m-p/758810#M239669</link>
      <description>&lt;PRE&gt;/** Here I am trying to pull previous 5 month data from mainframe in SAS EG.&lt;BR /&gt;but getting below error, don't know what need to be done now. please help. &lt;BR /&gt;&lt;CODE class=" language-sas"&gt;/*Generate same data for previous 5 months*/

rsubmit;
%macro mons(brand, brand2, n1,lapse);

proc sql;
create table &amp;amp;brand2._OD&amp;amp;n1. as
select 
branch_no as branch           
, account_no as acct   
, "&amp;amp;brand2." as brand
, account_open_date as opened 
, min_bal_cld as minbal     
, ACCOUNT_LIMIT as odlim    
, extract_date

from &amp;amp;brand..MIS_ACC
where EXTRACT (YEAR FROM extract_date) = extract(year from(add_months(&amp;amp;rep_dt, - &amp;amp;lapse) ))    
and extract( month from extract_date) = extract(month from(add_months(&amp;amp;rep_dt, - &amp;amp;lapse) ))    
and  account_type in (&amp;amp;mtas.) 
and  ACCOUNT_LIMIT &amp;gt; 0 
and  Min_Bal_Cld &amp;lt; 0
);
quit;

/** append brands level information in one table*/
data OVD;
set &amp;amp;brand2._OD&amp;amp;n1.;
run;

proc download data=OVD out=OVD;
run;
%mend mons;
%mons(A, A , 2, 1);
%mons(A, A, 3,  2);
%mons(B, B, 2,  1);
%mons(B, B, 3, 2);
endrsubmit;

below is  error log.

&amp;nbsp;MLOGIC(MONS):  Beginning execution.
MLOGIC(MONS):  Parameter BRAND has value A
MLOGIC(MONS):  Parameter BRAND2 has value A
MLOGIC(MONS):  Parameter N1 has value 2
MLOGIC(MONS):  Parameter LAPSE has value 1
MPRINT(MONS):   proc sql;
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
SYMBOLGEN:  Macro variable BRAND2 resolves to A
SYMBOLGEN:  Macro variable N1 resolves to 2
SYMBOLGEN:  Macro variable BRAND2 resolves to A
SYMBOLGEN:  Macro variable BRAND resolves to A
NOTE: Line generated by the invoked macro "MONS".
299   (YEAR FROM extract_date) = extract(year from(add_months(&amp;amp;rep_dt, - &amp;amp;lapse) )) and extract( month from extract_date) =
            ----
            22
            202
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, (, ), *, **, +, ',', -, '.', /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, ?, AND, 
              BETWEEN, CONTAINS, EQ, EQT, GE, GET, GT, GTT, IN, IS, LE, LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, ¬, ¬=, |, ||, 
2                                                          The SAS System                               19:50 Monday, August 2, 2021

              ¯, ¯=.  

ERROR 202-322: The option or parameter is not recognized and will be ignored.

299!  (YEAR FROM extract_date) = extract(year from(add_months(&amp;amp;rep_dt, - &amp;amp;lapse) )) and extract( month from extract_date) =
                                              ----
                                              22
299! extract(month from(add_months(&amp;amp;rep_dt, - &amp;amp;lapse) ))     and  account_type in (&amp;amp;mtas.) and  ACCOUNT_LIMIT &amp;gt; 0 and  Min_Bal_Cld &amp;lt;
299!  0 );
SYMBOLGEN:  Macro variable REP_DT resolves to 01Jun2021
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, (, *, **, +, ',', -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, ?, AND, BETWEEN, 
              CONTAINS, EQ, EQT, GE, GET, GT, GTT, LE, LET, LIKE, LT, LTT, NE, NET, OR, ¬=, |, ||, ¯=.  

NOTE: Line generated by the macro variable "REP_DT".
299  01Jun2021
       -------
       22
SYMBOLGEN:  Macro variable LAPSE resolves to 1
NOTE 137-205: Line generated by the invoked macro "MONS".
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Aug 2021 19:23:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/mainframe-SAS-code-is-not-working-please-extract-year-from-add/m-p/758810#M239669</guid>
      <dc:creator>ManoharNath</dc:creator>
      <dc:date>2021-08-02T19:23:56Z</dc:date>
    </item>
    <item>
      <title>Re: mainframe SAS: code is not working please. extract(year from(add_months(&amp;tera_dt1, -&amp;lap</title>
      <link>https://communities.sas.com/t5/SAS-Programming/mainframe-SAS-code-is-not-working-please-extract-year-from-add/m-p/758817#M239672</link>
      <description>&lt;P&gt;1) No attached error&lt;/P&gt;
&lt;P&gt;2) When asking about errors we should have the log that generated the errors, not just the error.&lt;/P&gt;
&lt;P&gt;3) When the error comes out of macro coding you need to set: Options Mprint;&lt;/P&gt;
&lt;P&gt;before running the macro to generate more details in the log about the code the macro creates. Otherwise an error after a macro runs doesn't show where in the code it happened. Mprint will have the error in relation to the code, or at least better proximity.&lt;/P&gt;
&lt;P&gt;4) copy the log with all the mprint messages, the code and error and paste the text into a text box opened on the forum with the &amp;lt;/&amp;gt; icon to preserve formatting.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Aug 2021 15:34:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/mainframe-SAS-code-is-not-working-please-extract-year-from-add/m-p/758817#M239672</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-08-02T15:34:45Z</dc:date>
    </item>
    <item>
      <title>Re: mainframe SAS: code is not working please. extract(year from(add_months(&amp;tera_dt1, -&amp;lap</title>
      <link>https://communities.sas.com/t5/SAS-Programming/mainframe-SAS-code-is-not-working-please-extract-year-from-add/m-p/758830#M239679</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/17460"&gt;@ManoharNath&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;has pointed out, the log will help in the diagnosis of the issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I did notice your use of the extract() function to extract a year and a month. As extract() is not a SAS function, you might want to consider using SAS functions&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p13eycdrmfb0l8n1492z3wocpt3s.htm" target="_blank" rel="noopener"&gt;year()&lt;/A&gt;&amp;nbsp; and &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/n0bn6385z4pweqn1qrpmklqtln99.htm" target="_blank" rel="noopener"&gt;month()&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks &amp;amp; kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Aug 2021 16:30:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/mainframe-SAS-code-is-not-working-please-extract-year-from-add/m-p/758830#M239679</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2021-08-02T16:30:02Z</dc:date>
    </item>
    <item>
      <title>Re: mainframe SAS: code is not working please. extract(year from(add_months(&amp;tera_dt1, -&amp;lap</title>
      <link>https://communities.sas.com/t5/SAS-Programming/mainframe-SAS-code-is-not-working-please-extract-year-from-add/m-p/758839#M239683</link>
      <description>&lt;P&gt;There is neither a EXTRACT nor a ADD_MONTHS function in SAS. You should look into the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/lefunctionsref/p10v3sa3i4kfxfn1sovhi5xzxh8n.htm" target="_blank" rel="noopener"&gt;INTNX&lt;/A&gt; function for calculating intervals, and the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/lefunctionsref/p13eycdrmfb0l8n1492z3wocpt3s.htm" target="_blank" rel="noopener"&gt;YEAR&lt;/A&gt; function for getting the year from a date.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Aug 2021 17:01:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/mainframe-SAS-code-is-not-working-please-extract-year-from-add/m-p/758839#M239683</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-08-02T17:01:50Z</dc:date>
    </item>
    <item>
      <title>Re: mainframe SAS: code is not working please. extract(year from(add_months(&amp;tera_dt1, -&amp;lap</title>
      <link>https://communities.sas.com/t5/SAS-Programming/mainframe-SAS-code-is-not-working-please-extract-year-from-add/m-p/758924#M239707</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/17460"&gt;@ManoharNath&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where EXTRACT (YEAR FROM extract_date) = extract(year from(add_months(&amp;amp;rep_dt, - &amp;amp;lapse) ))    
and extract( month from extract_date) = extract(month from(add_months(&amp;amp;rep_dt, - &amp;amp;lapse) ))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;isn't really SAS code.&amp;nbsp; It looks more like Hive or Oracle or something.&amp;nbsp; If you use Proc SQL with a Libname, you need to use &lt;STRONG&gt;SAS syntax&lt;/STRONG&gt; for your SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to use the syntax of the data base, you need to issue a CONNECT first and then code what is referred to as "explicit pass through SQL."&amp;nbsp; If you Google "SAS explicit pass through", you should find some examples, if that's what you're trying to do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Mon, 02 Aug 2021 23:53:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/mainframe-SAS-code-is-not-working-please-extract-year-from-add/m-p/758924#M239707</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-08-02T23:53:51Z</dc:date>
    </item>
    <item>
      <title>Re: mainframe SAS: code is not working please. extract(year from(add_months(&amp;tera_dt1, -&amp;lap</title>
      <link>https://communities.sas.com/t5/SAS-Programming/mainframe-SAS-code-is-not-working-please-extract-year-from-add/m-p/759884#M240224</link>
      <description>&lt;P&gt;Hi All, I've written my code in other way and able to solve this issue. just for reference we don't have to use macro parameters all the time, as in my questions I am pulling past 5 month data, for this we just had to apply filter on required column.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;example: for June month, Start date would be 1st Jan 2021 and end date would be 31st May 2021.&lt;/P&gt;
&lt;P&gt;Just apply this date on extract column like below&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where extract date like :&amp;nbsp;extract &amp;gt;= "01Jan2021"d and&amp;nbsp;extract &amp;lt;= 31May2021"d&amp;nbsp;
and  account_type in (&amp;amp;mtas.) 
and  ACCOUNT_LIMIT &amp;gt; 0 
and  Min_Bal_Cld &amp;lt; 0&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Aug 2021 06:52:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/mainframe-SAS-code-is-not-working-please-extract-year-from-add/m-p/759884#M240224</guid>
      <dc:creator>ManoharNath</dc:creator>
      <dc:date>2021-08-06T06:52:24Z</dc:date>
    </item>
  </channel>
</rss>

