<?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 list of dates in macro variable list - SQL where date = in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/list-of-dates-in-macro-variable-list-SQL-where-date/m-p/104578#M21825</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a very large time series dataset where I am trying to generate plots grouped by day.&amp;nbsp; Because of the size of the data, I cannot do BY without running out of memory.&amp;nbsp; So my thought was to create a macro that cycles through distinct dates and creates temporary subsets of data by day, then creates various plots by day.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;My dataset key fields:&lt;/P&gt;&lt;P&gt;datetime&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; valueX&lt;/P&gt;&lt;P&gt;23APR13:14:47:00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2013-04-23&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 48.6&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My Code:&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select distinct date&amp;nbsp; &lt;STRONG&gt; /*&amp;nbsp; also tried DATEPART(datetime)FORMAT=YYMMDD10. */&lt;/STRONG&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; INTO :date_list separated by ","&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from myDataset;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;/* if I use %PUT &amp;amp;date_list, the data looks correct - matches the date and format of the date field&amp;nbsp; */&lt;/STRONG&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%Let i =1;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;/*&amp;nbsp; Will do a macro do while loop, but have to get the first proc sql working first&amp;nbsp; */&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;%PUT %scan(%bquote(&amp;amp;date_list), &amp;amp;i, %str(,));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt; create table work._temp as&lt;BR /&gt; select datetime, date, valueX&lt;BR /&gt; from myDataset&lt;BR /&gt; where date = %scan(%bquote(&amp;amp;date_list), &amp;amp;i, %str(,))&lt;BR /&gt; order by datetime;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The proc sql query runs but 0 rows returned.&amp;nbsp; Obviously the date is not matching the %scan.&amp;nbsp; But when you look individually, it appears as if they match.&amp;nbsp; I have tried a number of other formatting options.&amp;nbsp; Any suggestions?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Fred&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 12 Jun 2013 20:02:22 GMT</pubDate>
    <dc:creator>FredGIII</dc:creator>
    <dc:date>2013-06-12T20:02:22Z</dc:date>
    <item>
      <title>list of dates in macro variable list - SQL where date =</title>
      <link>https://communities.sas.com/t5/SAS-Programming/list-of-dates-in-macro-variable-list-SQL-where-date/m-p/104578#M21825</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a very large time series dataset where I am trying to generate plots grouped by day.&amp;nbsp; Because of the size of the data, I cannot do BY without running out of memory.&amp;nbsp; So my thought was to create a macro that cycles through distinct dates and creates temporary subsets of data by day, then creates various plots by day.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;My dataset key fields:&lt;/P&gt;&lt;P&gt;datetime&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; valueX&lt;/P&gt;&lt;P&gt;23APR13:14:47:00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2013-04-23&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 48.6&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My Code:&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select distinct date&amp;nbsp; &lt;STRONG&gt; /*&amp;nbsp; also tried DATEPART(datetime)FORMAT=YYMMDD10. */&lt;/STRONG&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; INTO :date_list separated by ","&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from myDataset;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;/* if I use %PUT &amp;amp;date_list, the data looks correct - matches the date and format of the date field&amp;nbsp; */&lt;/STRONG&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%Let i =1;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;/*&amp;nbsp; Will do a macro do while loop, but have to get the first proc sql working first&amp;nbsp; */&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;%PUT %scan(%bquote(&amp;amp;date_list), &amp;amp;i, %str(,));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt; create table work._temp as&lt;BR /&gt; select datetime, date, valueX&lt;BR /&gt; from myDataset&lt;BR /&gt; where date = %scan(%bquote(&amp;amp;date_list), &amp;amp;i, %str(,))&lt;BR /&gt; order by datetime;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The proc sql query runs but 0 rows returned.&amp;nbsp; Obviously the date is not matching the %scan.&amp;nbsp; But when you look individually, it appears as if they match.&amp;nbsp; I have tried a number of other formatting options.&amp;nbsp; Any suggestions?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Fred&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Jun 2013 20:02:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/list-of-dates-in-macro-variable-list-SQL-where-date/m-p/104578#M21825</guid>
      <dc:creator>FredGIII</dc:creator>
      <dc:date>2013-06-12T20:02:22Z</dc:date>
    </item>
    <item>
      <title>Re: list of dates in macro variable list - SQL where date =</title>
      <link>https://communities.sas.com/t5/SAS-Programming/list-of-dates-in-macro-variable-list-SQL-where-date/m-p/104579#M21826</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The problem may be specifying the dates in a format that SAS understands, e.g the date literal format:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select distinct date format=date9. &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; into :date_list separated by "," &lt;/P&gt;&lt;P&gt;from sashelp.stocks;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%put &amp;amp;date_list;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Jun 2013 20:35:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/list-of-dates-in-macro-variable-list-SQL-where-date/m-p/104579#M21826</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2013-06-12T20:35:18Z</dc:date>
    </item>
    <item>
      <title>Re: list of dates in macro variable list - SQL where date =</title>
      <link>https://communities.sas.com/t5/SAS-Programming/list-of-dates-in-macro-variable-list-SQL-where-date/m-p/104580#M21827</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Reeza,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I changed the format as you suggested to pull the distinct list, but still having issues matching the literal format in the follow up query.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I changed the follow up query to :&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt; create table work._temp as&lt;/P&gt;&lt;P&gt; select datetime, date FORMAT=date9., valueX&lt;/P&gt;&lt;P&gt; from myDataset&lt;/P&gt;&lt;P&gt; where date = %scan(%bquote(&amp;amp;date_list), &amp;amp;i, %str(,))&lt;/P&gt;&lt;P&gt; order by datetime;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and I get the error:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;NOTE: Line generated by the macro function "SCAN".&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 24APR2013&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -------&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 22&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 76&lt;/P&gt;&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, *, **, +, -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =, &amp;gt;, &amp;gt;=, AND, EQ, EQT, GE, GET, GROUP, GT, GTT, HAVING, LE, LET, LT, LTT, NE,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NET, OR, ^=, |, ||, ~=.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you not put dates in macro variable list? &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Jun 2013 20:59:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/list-of-dates-in-macro-variable-list-SQL-where-date/m-p/104580#M21827</guid>
      <dc:creator>FredGIII</dc:creator>
      <dc:date>2013-06-12T20:59:36Z</dc:date>
    </item>
    <item>
      <title>Re: list of dates in macro variable list - SQL where date =</title>
      <link>https://communities.sas.com/t5/SAS-Programming/list-of-dates-in-macro-variable-list-SQL-where-date/m-p/104581#M21828</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can but this line of the code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;where date = %scan(%bquote(&amp;amp;date_list), &amp;amp;i, %str(,))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;isn't appropriate SAS syntax.&lt;/P&gt;&lt;P&gt;It translates to:&lt;/P&gt;&lt;P&gt;where date= 01Apr2011&lt;/P&gt;&lt;P&gt;and and needs to be &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;where date="01Apr2011"d&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I don't know if you can just wrap it or need to grab the variable ahead of time. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. where date="%scan(%bquote(&amp;amp;date_list), &amp;amp;i, %str(,))"d&lt;/P&gt;&lt;P&gt;2. %let date_current=%scan(%bquote(&amp;amp;date_list), &amp;amp;i, %str(,));&lt;/P&gt;&lt;P&gt;where date="&amp;amp;date_current"d&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Jun 2013 21:02:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/list-of-dates-in-macro-variable-list-SQL-where-date/m-p/104581#M21828</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2013-06-12T21:02:56Z</dc:date>
    </item>
    <item>
      <title>Re: list of dates in macro variable list - SQL where date =</title>
      <link>https://communities.sas.com/t5/SAS-Programming/list-of-dates-in-macro-variable-list-SQL-where-date/m-p/104582#M21829</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Whew, that did it!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt; create table work._temp as&lt;/P&gt;&lt;P&gt; select datetime, date FORMAT=date9., valueX&lt;/P&gt;&lt;P&gt; from myDataset&lt;/P&gt;&lt;P&gt; where date = "%scan(%bquote(&amp;amp;date_list), &amp;amp;i, %str(,))"d&lt;/P&gt;&lt;P&gt; order by datetime;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am finding that dealing with date and time formats within SAS is a royal pain in the .......&amp;nbsp; Thanks for your suggestions!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Jun 2013 21:10:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/list-of-dates-in-macro-variable-list-SQL-where-date/m-p/104582#M21829</guid>
      <dc:creator>FredGIII</dc:creator>
      <dc:date>2013-06-12T21:10:59Z</dc:date>
    </item>
    <item>
      <title>Re: list of dates in macro variable list - SQL where date =</title>
      <link>https://communities.sas.com/t5/SAS-Programming/list-of-dates-in-macro-variable-list-SQL-where-date/m-p/104583#M21830</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you are just going to use them to drive a WHERE clause there is no need for them to be human readable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;select distinct date format=10. into :date_list separated by ' '&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%let n=&amp;amp;sqlobs;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%do i=1 %to &amp;amp;n;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;where date=%scan(&amp;amp;date_list,&amp;amp;i)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%end;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Jun 2013 21:34:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/list-of-dates-in-macro-variable-list-SQL-where-date/m-p/104583#M21830</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-06-12T21:34:41Z</dc:date>
    </item>
    <item>
      <title>Re: list of dates in macro variable list - SQL where date =</title>
      <link>https://communities.sas.com/t5/SAS-Programming/list-of-dates-in-macro-variable-list-SQL-where-date/m-p/104584#M21831</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why not split it into lots of small datasets ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Jun 2013 06:10:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/list-of-dates-in-macro-variable-list-SQL-where-date/m-p/104584#M21831</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2013-06-17T06:10:32Z</dc:date>
    </item>
  </channel>
</rss>

