<?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: SAS to SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL/m-p/82446#M256697</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If the database you are using supports the "Rank" OLAP functionality, this would allow you to control exactly how to order your desired results by an arbitrary number of columns.&amp;nbsp; The OLAP functions use "Qualify" to include/reject rows.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;An example from Teradata is below, and you will probably need to research the syntax from your database vendor.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style=": ; color: #0000ff; font-size: 8pt;"&gt;QUALIFY&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RANK&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;() &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;OVER&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style=": ; color: #0000ff; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PARTITION&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;STRONG style=": ; color: #0000ff; font-size: 8pt;"&gt;BY&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; task_nbr&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;acct_nbr&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style=": ; color: #0000ff; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ORDER&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;STRONG style=": ; color: #0000ff; font-size: 8pt;"&gt;BY&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; vldtn_diff_eff_day_to_min&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;STRONG style=": ; color: #0000ff; font-size: 8pt;"&gt;DESC&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;EM style=": ; color: #008000; font-size: 8pt;"&gt;/*ASC*/&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style=": ; color: #008000; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ) = &lt;/EM&gt;&lt;SPAN style="color: #ff00ff; font-size: 8pt;"&gt;1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 18 Jul 2013 18:28:29 GMT</pubDate>
    <dc:creator>cal4gORl3ndU</dc:creator>
    <dc:date>2013-07-18T18:28:29Z</dc:date>
    <item>
      <title>SAS to SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL/m-p/82439#M256690</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have code using&lt;/P&gt;&lt;P&gt;order by&lt;/P&gt;&lt;P&gt;if not first. and last. then output unique&lt;/P&gt;&lt;P&gt;else output duplicate&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like to do the same thing using sql but don't know how.&amp;nbsp; I cannot use 'group by count &amp;gt; 1' because the dataset has a lot of variables and I only want to 'order by' and 'group by' two of the variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'll attach the code if that helps, look at the bottom, that little 'group by' is what I'm trying, I know it won't work but that general idea is what I'd like.&amp;nbsp; I need the second column, if duplicated within the first column,&amp;nbsp; to spit out to another dataset, so I'll be forming two datasets instead of one.&amp;nbsp; One of them will be 'having count&amp;gt;1', the other will be 'having count=1'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hopefully that makes sense.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Jul 2013 15:38:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL/m-p/82439#M256690</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2013-07-17T15:38:42Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL/m-p/82440#M256691</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry I'm not following, but could you give an example with before and after data that you have and need?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It seems to me like you are saying you want all keys that have more than 1 record (by a set of unique keys) to be output into one dataset, and all keys that have only 1 record to be output into another dataset? Is this correct?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Aka if you have loan, date, balance, term, etc... and your original key is Loan + date, then you want all loans and dates that are dupliated (01, january) into one dataset with everything else into another?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the clarification!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Jul 2013 15:58:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL/m-p/82440#M256691</guid>
      <dc:creator>Anotherdream</dc:creator>
      <dc:date>2013-07-17T15:58:14Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL/m-p/82441#M256692</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The attached is the SQL that doesn't work? It would be easier if you provided the SAS that does work and a dataset that shows what you have versus want.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Jul 2013 16:07:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL/m-p/82441#M256692</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2013-07-17T16:07:28Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL/m-p/82442#M256693</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;the sql works, it's just that last line that I'm questioning, the group by&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Jul 2013 17:16:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL/m-p/82442#M256693</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2013-07-17T17:16:08Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL/m-p/82443#M256694</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry, the sql works without that last line, with the last line it won't work because I only want to group by two variables.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Jul 2013 17:16:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL/m-p/82443#M256694</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2013-07-17T17:16:43Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL/m-p/82444#M256695</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So why don't you create the file, and then group by the two variables to get your list, and then just re-join to your data as a subset if that's all you want... Or just do a group by 2 variables, you can group by as many varaibles as you like within sas, you don't have to group by everything in a select clause (strange because you do have too in sql if it's not in an aggregation clause).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am still not understanding what you actually need. Again if you have some data, or the data step that works it would help a lot.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Jul 2013 20:19:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL/m-p/82444#M256695</guid>
      <dc:creator>Anotherdream</dc:creator>
      <dc:date>2013-07-17T20:19:43Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL/m-p/82445#M256696</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Based on your code I suspect you are trying to run this in a different SQL dialect than proc sql.&amp;nbsp; Your use of the decode and lpad functions suggests that to me&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you are running in a different SQL dialect, 'group by' aggregation works a little differently.&amp;nbsp; This has caused me confusion in the past. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Some other dialects of sql do not allow you to have any fields in the select clause except for the group by variables and aggregate functions.&amp;nbsp; SAS Proc SQL lets you do this.&amp;nbsp; So as&amp;nbsp; examples, the following queries will work in SAS SQL but not some other dialects:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;create table count as&lt;/P&gt;&lt;P&gt;select a&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,b&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,count(*) as cnt&lt;/P&gt;&lt;P&gt;&amp;nbsp; from myTable&lt;/P&gt;&lt;P&gt;group by a ; &lt;/P&gt;&lt;P&gt;create table dups as&lt;/P&gt;&lt;P&gt;select *&lt;/P&gt;&lt;P&gt;&amp;nbsp; from myTable&lt;/P&gt;&lt;P&gt;group by a&lt;/P&gt;&lt;P&gt;having count(*) &amp;gt; 1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If there is no need to do in another SQL dialect then you can do this within SAS, but some of the functions will need to be converted.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you need to do this in another SQL dialect, you will need to do some variation on AnotherDream's last suggestion.&amp;nbsp; Two ways of doing this are&lt;/P&gt;&lt;P&gt;1.&amp;nbsp; Join the original table with a sub-query of the original table with the group by in the sub-query&lt;/P&gt;&lt;P&gt;2. Create a temporary table from the group by and then join temporary table to original table. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Jul 2013 14:35:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL/m-p/82445#M256696</guid>
      <dc:creator>LarryWorley</dc:creator>
      <dc:date>2013-07-18T14:35:25Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL/m-p/82446#M256697</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If the database you are using supports the "Rank" OLAP functionality, this would allow you to control exactly how to order your desired results by an arbitrary number of columns.&amp;nbsp; The OLAP functions use "Qualify" to include/reject rows.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;An example from Teradata is below, and you will probably need to research the syntax from your database vendor.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style=": ; color: #0000ff; font-size: 8pt;"&gt;QUALIFY&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RANK&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;() &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;OVER&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style=": ; color: #0000ff; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PARTITION&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;STRONG style=": ; color: #0000ff; font-size: 8pt;"&gt;BY&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; task_nbr&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;acct_nbr&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style=": ; color: #0000ff; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ORDER&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;STRONG style=": ; color: #0000ff; font-size: 8pt;"&gt;BY&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; vldtn_diff_eff_day_to_min&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;STRONG style=": ; color: #0000ff; font-size: 8pt;"&gt;DESC&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;EM style=": ; color: #008000; font-size: 8pt;"&gt;/*ASC*/&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style=": ; color: #008000; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ) = &lt;/EM&gt;&lt;SPAN style="color: #ff00ff; font-size: 8pt;"&gt;1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Jul 2013 18:28:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL/m-p/82446#M256697</guid>
      <dc:creator>cal4gORl3ndU</dc:creator>
      <dc:date>2013-07-18T18:28:29Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL/m-p/82447#M256698</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If I understand your question correctly, you want to use SQL to create two data sets at the same time. SQL (including SAS' PROC SQL) can only create one table at a time.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 19 Jul 2013 22:07:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL/m-p/82447#M256698</guid>
      <dc:creator>Fugue</dc:creator>
      <dc:date>2013-07-19T22:07:28Z</dc:date>
    </item>
  </channel>
</rss>

