<?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 SQL query in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SQL-query/m-p/512123#M137895</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have following query where we are pulling the data of current and next month for a particular year.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;select id as&lt;BR /&gt;from table1 A inner join table2 B on A.id=B.id&lt;BR /&gt;where year(date)&amp;gt;=2017&lt;BR /&gt;and (month(date)=month(today())+1 or month(date)=month(today()));&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But this will not work for December (12+1 becomes 13).&amp;nbsp;Please suggest how can the code work for December onward.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 12 Nov 2018 09:16:44 GMT</pubDate>
    <dc:creator>UshaLatha</dc:creator>
    <dc:date>2018-11-12T09:16:44Z</dc:date>
    <item>
      <title>SQL query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-query/m-p/512123#M137895</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have following query where we are pulling the data of current and next month for a particular year.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;select id as&lt;BR /&gt;from table1 A inner join table2 B on A.id=B.id&lt;BR /&gt;where year(date)&amp;gt;=2017&lt;BR /&gt;and (month(date)=month(today())+1 or month(date)=month(today()));&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But this will not work for December (12+1 becomes 13).&amp;nbsp;Please suggest how can the code work for December onward.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Nov 2018 09:16:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-query/m-p/512123#M137895</guid>
      <dc:creator>UshaLatha</dc:creator>
      <dc:date>2018-11-12T09:16:44Z</dc:date>
    </item>
    <item>
      <title>Re: SQL query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-query/m-p/512125#M137896</link>
      <description>&lt;P&gt;I assume that this is not pass through to a database, in which case intnx should be used for this:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  select id
  from   table1 a 
  inner join table2 b 
  on     a.id=b.id
  where intnx("month",today(),0,"b") &amp;lt;= date &amp;lt;= intnx("month",today(),1,"e");
quit;&lt;/PRE&gt;
&lt;P&gt;So I take lower bound as start of this month, and end bound as end of next month.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Nov 2018 09:25:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-query/m-p/512125#M137896</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-11-12T09:25:05Z</dc:date>
    </item>
    <item>
      <title>Re: SQL query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-query/m-p/512128#M137897</link>
      <description>&lt;P&gt;This is a pass-through to database.. intnx is not working&lt;/P&gt;</description>
      <pubDate>Mon, 12 Nov 2018 09:36:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-query/m-p/512128#M137897</guid>
      <dc:creator>UshaLatha</dc:creator>
      <dc:date>2018-11-12T09:36:16Z</dc:date>
    </item>
    <item>
      <title>Re: SQL query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-query/m-p/512130#M137898</link>
      <description>&lt;P&gt;Then move intnx to a macro-variable&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let startDate = %sysfunc(intnx("month",today(),0,"b"));
%let untilDate = %sysfunc(intnx("month",today(),1,"e"));

proc sql;
  select id
  from   table1 a 
  inner join table2 b 
  on     a.id=b.id
  where &amp;amp;startDate. &amp;lt;= date &amp;lt;= &amp;amp;untilDate.;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 12 Nov 2018 09:42:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-query/m-p/512130#M137898</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2018-11-12T09:42:39Z</dc:date>
    </item>
    <item>
      <title>Re: SQL query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-query/m-p/512137#M137901</link>
      <description>&lt;P&gt;This is the kind of information that would be useful upfront.&amp;nbsp; If this is pass through then you need to use syntax which the database is happy to process.&amp;nbsp; So you can passthrough a date string, as shown by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;using a macro variable.&amp;nbsp; Essentially this works out the date range before the SQL, and then passes that in as well.&amp;nbsp; Alternatively there will be functions on the database (I assume) which will handle dates.&amp;nbsp; Without even knowing which database however I can't help further.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Nov 2018 10:05:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-query/m-p/512137#M137901</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-11-12T10:05:13Z</dc:date>
    </item>
    <item>
      <title>Re: SQL query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-query/m-p/512139#M137902</link>
      <description>&lt;P&gt;Not sure if that would work directly.&amp;nbsp; Would not the macro variables store the number of day since cuttoff?&amp;nbsp; If so the database would not know what that number is.&amp;nbsp; What you might need to is to pass in date strings, maybe something like:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  call symputx("startdate",put(intnx("month",today(),0,"b"),date9.);
  call symputx("untildate",put(intnx("month",today(),1,"b"),date9.);
run;&lt;BR /&gt;proc sql;&lt;BR /&gt;...&lt;BR /&gt;  where to_date("&amp;amp;startdate.") &amp;lt;= date &amp;lt;= to_date("&amp;amp;untildate.")&lt;BR /&gt;...&lt;/PRE&gt;
&lt;P&gt;Just a thought (oracle syntax above by the way).&lt;/P&gt;</description>
      <pubDate>Mon, 12 Nov 2018 10:08:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-query/m-p/512139#M137902</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-11-12T10:08:48Z</dc:date>
    </item>
    <item>
      <title>Re: SQL query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-query/m-p/512143#M137903</link>
      <description>&lt;P&gt;Its DB2.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Nov 2018 10:39:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-query/m-p/512143#M137903</guid>
      <dc:creator>UshaLatha</dc:creator>
      <dc:date>2018-11-12T10:39:41Z</dc:date>
    </item>
    <item>
      <title>Re: SQL query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-query/m-p/512144#M137904</link>
      <description>&lt;P&gt;can you explain how does this work:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;where to_date("&amp;amp;startdate.") &amp;lt;= date &amp;lt;= to_date("&amp;amp;untildate.")&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;as to_date() is not a sas or sql function that I know of. Please correct me if I am wrong.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Nov 2018 10:47:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-query/m-p/512144#M137904</guid>
      <dc:creator>UshaLatha</dc:creator>
      <dc:date>2018-11-12T10:47:04Z</dc:date>
    </item>
    <item>
      <title>Re: SQL query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-query/m-p/512145#M137905</link>
      <description>&lt;P&gt;Please see the note below that code, I was taking Oracle DB syntax as I did not know your database at the time.&amp;nbsp; Quick search shows:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/19500912/to-pull-records-between-two-dates-in-db2" target="_blank"&gt;https://stackoverflow.com/questions/19500912/to-pull-records-between-two-dates-in-db2&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Which would seem to indicate you do not need functions, and simply putting the date to text will work.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Nov 2018 10:54:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-query/m-p/512145#M137905</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-11-12T10:54:10Z</dc:date>
    </item>
  </channel>
</rss>

