<?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: Pulling data from SQL serever for a particular month in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Pulling-data-from-SQL-serever-for-a-particular-month/m-p/411827#M67363</link>
    <description>First, have non macro version of your code working. &lt;BR /&gt;Then by using MPRINT you get the same syntax with macro logic. &lt;BR /&gt;Then I see no reason to use explicit SQL pass through here, it just complicates the code..</description>
    <pubDate>Thu, 09 Nov 2017 06:55:39 GMT</pubDate>
    <dc:creator>LinusH</dc:creator>
    <dc:date>2017-11-09T06:55:39Z</dc:date>
    <item>
      <title>Pulling data from SQL serever for a particular month</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Pulling-data-from-SQL-serever-for-a-particular-month/m-p/411602#M67358</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to run this code to pull data from a sql server for 08/31/2017 month particularly. That's why I specify the WHERE statement.&amp;nbsp;I looked at the Source data, the field PORTFOLIO (to specify the month) is text file in format of 083117. The &amp;amp;adate has the same format as 083117 but I don't why it still did not pull the data for me. I tried this&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%nrbquote&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(')&amp;amp;adate&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%nrbquote&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(')and still did not work. Can someone help me please?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;%macro&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; loopthrough(from_date=, to_date=);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%local&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; filedate;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; filedate=&amp;amp;from_date &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%to&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;to_date;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%if&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%substr&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(&amp;amp;filedate,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;5&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;) ge &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;01&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; AND &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%substr&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(&amp;amp;filedate,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;5&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;) le &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;12&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_ print;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;tmp = intnx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'month'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,input(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"&amp;amp;filedate"&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;yymmn6.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;),&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'e'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;call symput(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'adate'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;, put(tmp, &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;mmddyy7.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;adate.;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;CONNECT TO SQLSVR (...);&lt;/P&gt;&lt;P&gt;　&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;CREATE TABLE DATA_&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;filedate.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; AS SELECT * FROM CONNECTION TO sasqrm&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(SELECT *&lt;/P&gt;&lt;P&gt;FROM&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;source data goes here&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;WHERE&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;PORTFOLIO = &amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;adate.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;%&lt;STRONG&gt;&lt;I&gt;loopthrough&lt;/I&gt;&lt;/STRONG&gt;(from_date=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;201708&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;, to_date=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;201708&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Nov 2017 17:33:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Pulling-data-from-SQL-serever-for-a-particular-month/m-p/411602#M67358</guid>
      <dc:creator>tampham92</dc:creator>
      <dc:date>2017-11-08T17:33:46Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling data from SQL serever for a particular month</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Pulling-data-from-SQL-serever-for-a-particular-month/m-p/411789#M67361</link>
      <description>&lt;P&gt;This SQL will pull for a specific year/month combination. I think that is what you needed, but one thing to check:&lt;/P&gt;
&lt;P&gt;our SQL db has DateTimes and Dates, make sure of which one you are working with before using the "datepart" function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt; create table tmp as&lt;BR /&gt; select myDate from myTable where put(datepart(myDate), yymmn6.)='201708';&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Nov 2017 01:26:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Pulling-data-from-SQL-serever-for-a-particular-month/m-p/411789#M67361</guid>
      <dc:creator>morgalr</dc:creator>
      <dc:date>2017-11-09T01:26:44Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling data from SQL serever for a particular month</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Pulling-data-from-SQL-serever-for-a-particular-month/m-p/411827#M67363</link>
      <description>First, have non macro version of your code working. &lt;BR /&gt;Then by using MPRINT you get the same syntax with macro logic. &lt;BR /&gt;Then I see no reason to use explicit SQL pass through here, it just complicates the code..</description>
      <pubDate>Thu, 09 Nov 2017 06:55:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Pulling-data-from-SQL-serever-for-a-particular-month/m-p/411827#M67363</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2017-11-09T06:55:39Z</dc:date>
    </item>
  </channel>
</rss>

