<?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: Complex Query (for me at least!) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Complex-Query-for-me-at-least/m-p/52878#M11190</link>
    <description>Hmmm... You just have about a millions ways to do this with SAS.&lt;BR /&gt;
&lt;BR /&gt;
Anyway, It's just a simple grouping case, I wouldn't call it a complex problem.&lt;BR /&gt;
&lt;BR /&gt;
But for the resulting table:&lt;BR /&gt;
&lt;BR /&gt;
A B D E&lt;BR /&gt;
05-06-2009 1 20 20=&lt;X&gt;&amp;lt;30&lt;BR /&gt;
06-06-2009 1 40 x=&amp;gt;40&lt;BR /&gt;
07-06-2009 1 20 20=&lt;X&gt;&amp;lt;30&lt;BR /&gt;
05-06-2009 2 20 20=&lt;X&gt;&amp;lt;30&lt;BR /&gt;
06-06-2009 2 150 x=&amp;gt;40&lt;BR /&gt;
07-06-2009 2 10 10=&lt;X&gt;&amp;lt;20&lt;BR /&gt;
07-06-2009 3 30 30=&lt;X&gt;&amp;lt;40&lt;BR /&gt;
08-06-2009 3 30 30=&lt;X&gt;&amp;lt;40&lt;BR /&gt;
&lt;BR /&gt;
I understand that E would be the range for the group (each day), and what about D?&lt;BR /&gt;
And also which B should be chosen for each group?&lt;BR /&gt;
&lt;BR /&gt;
Just for A and E, try this:&lt;BR /&gt;
&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
create table RESULT as&lt;BR /&gt;
select A, min(C) as MINC, max(C) as MAXC from LIB.DATA;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
This will give you for each day, and the minimum and maximum values of C (range).&lt;BR /&gt;
&lt;BR /&gt;
Cheers from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;.&lt;/X&gt;&lt;/X&gt;&lt;/X&gt;&lt;/X&gt;&lt;/X&gt;&lt;/X&gt;</description>
    <pubDate>Thu, 09 Jul 2009 15:15:48 GMT</pubDate>
    <dc:creator>DanielSantos</dc:creator>
    <dc:date>2009-07-09T15:15:48Z</dc:date>
    <item>
      <title>Complex Query (for me at least!)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Complex-Query-for-me-at-least/m-p/52877#M11189</link>
      <description>hello all,&lt;BR /&gt;
&lt;BR /&gt;
I have very complex query to make (for me at least!)&lt;BR /&gt;
&lt;BR /&gt;
I have (example):&lt;BR /&gt;
A	               B	                 C&lt;BR /&gt;
05-06-2009	1	10&lt;BR /&gt;
05-06-2009	1	20&lt;BR /&gt;
05-06-2009	2	20&lt;BR /&gt;
06-06-2009	1	40&lt;BR /&gt;
06-06-2009	1	40&lt;BR /&gt;
06-06-2009	2	50&lt;BR /&gt;
06-06-2009	2	50&lt;BR /&gt;
06-06-2009	2	30&lt;BR /&gt;
06-06-2009	2	20&lt;BR /&gt;
07-06-2009	1	20&lt;BR /&gt;
07-06-2009	2	10&lt;BR /&gt;
07-06-2009	3	30&lt;BR /&gt;
08-06-2009	3	30&lt;BR /&gt;
&lt;BR /&gt;
The goal is to create a D and E column with range of amounts and accumulated total per day (A) for each (B) custumer&lt;BR /&gt;
&lt;BR /&gt;
accumulated total per day (A) for each (B) custumer has to be &amp;gt; 10&lt;BR /&gt;
&lt;BR /&gt;
ranges:&lt;BR /&gt;
10&amp;gt;= accumulated total per day (A) for each (B) custumer &amp;lt; 20&lt;BR /&gt;
20&amp;gt;= accumulated total per day (A) for each (B) custumer &amp;lt; 30&lt;BR /&gt;
and so on!&lt;BR /&gt;
&lt;BR /&gt;
A	B	D	E&lt;BR /&gt;
05-06-2009	1	20	20=&lt;X&gt;&amp;lt;30&lt;BR /&gt;
06-06-2009	1	40	x=&amp;gt;40&lt;BR /&gt;
07-06-2009	1	20	20=&lt;X&gt;&amp;lt;30&lt;BR /&gt;
05-06-2009	2	20	20=&lt;X&gt;&amp;lt;30&lt;BR /&gt;
06-06-2009	2	150	x=&amp;gt;40&lt;BR /&gt;
07-06-2009	2	10	10=&lt;X&gt;&amp;lt;20&lt;BR /&gt;
07-06-2009	3	30	30=&lt;X&gt;&amp;lt;40&lt;BR /&gt;
08-06-2009	3	30	30=&lt;X&gt;&amp;lt;40&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
It has to be done in proc sql  :s&lt;BR /&gt;
any ideas?! I'm sorry that I can't explain better but I don't have access for now to SAS&lt;BR /&gt;
&lt;BR /&gt;
thanks in advance!&lt;/X&gt;&lt;/X&gt;&lt;/X&gt;&lt;/X&gt;&lt;/X&gt;&lt;/X&gt;</description>
      <pubDate>Thu, 09 Jul 2009 14:51:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Complex-Query-for-me-at-least/m-p/52877#M11189</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-07-09T14:51:32Z</dc:date>
    </item>
    <item>
      <title>Re: Complex Query (for me at least!)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Complex-Query-for-me-at-least/m-p/52878#M11190</link>
      <description>Hmmm... You just have about a millions ways to do this with SAS.&lt;BR /&gt;
&lt;BR /&gt;
Anyway, It's just a simple grouping case, I wouldn't call it a complex problem.&lt;BR /&gt;
&lt;BR /&gt;
But for the resulting table:&lt;BR /&gt;
&lt;BR /&gt;
A B D E&lt;BR /&gt;
05-06-2009 1 20 20=&lt;X&gt;&amp;lt;30&lt;BR /&gt;
06-06-2009 1 40 x=&amp;gt;40&lt;BR /&gt;
07-06-2009 1 20 20=&lt;X&gt;&amp;lt;30&lt;BR /&gt;
05-06-2009 2 20 20=&lt;X&gt;&amp;lt;30&lt;BR /&gt;
06-06-2009 2 150 x=&amp;gt;40&lt;BR /&gt;
07-06-2009 2 10 10=&lt;X&gt;&amp;lt;20&lt;BR /&gt;
07-06-2009 3 30 30=&lt;X&gt;&amp;lt;40&lt;BR /&gt;
08-06-2009 3 30 30=&lt;X&gt;&amp;lt;40&lt;BR /&gt;
&lt;BR /&gt;
I understand that E would be the range for the group (each day), and what about D?&lt;BR /&gt;
And also which B should be chosen for each group?&lt;BR /&gt;
&lt;BR /&gt;
Just for A and E, try this:&lt;BR /&gt;
&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
create table RESULT as&lt;BR /&gt;
select A, min(C) as MINC, max(C) as MAXC from LIB.DATA;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
This will give you for each day, and the minimum and maximum values of C (range).&lt;BR /&gt;
&lt;BR /&gt;
Cheers from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;.&lt;/X&gt;&lt;/X&gt;&lt;/X&gt;&lt;/X&gt;&lt;/X&gt;&lt;/X&gt;</description>
      <pubDate>Thu, 09 Jul 2009 15:15:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Complex-Query-for-me-at-least/m-p/52878#M11190</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2009-07-09T15:15:48Z</dc:date>
    </item>
  </channel>
</rss>

