<?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: Convert SQL / teradata code to SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-SQL-teradata-code-to-SAS/m-p/858493#M339202</link>
    <description>&lt;P&gt;The QUALIFY statement means that we are only taking the first row from each group. I think the easiest way to do this is to take all the data out in the order we want it, and then use a data step to get the first row in each partition:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table temp as
select GEN_ID, AU_GEN_ID, TYPE_2_DESC,
TYPE_5_DESC, TYPE_8_DESC,  DATA_OUTSTANDING_AMT, 
DATA_TOTAL_COMMITMENT_AMT
from COMMERCIAL_V3.DATA_F
order by GEN_ID, AU_GEN_ID, DATA_OUTSTANDING_AMT desc,
DATA_TOTAL_COMMITMENT_AMT desc, DATA_GEN_ID desc;
quit;

data want;
  set temp;
  by GEN_ID AU_GEN_ID;
  if first.AU_GEN_ID;
  drop DATA_OUTSTANDING_AMT DATA_TOTAL_COMMITMENT_AMT;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This assumes that your input data has been moved to a SAS library. If it is still in Teradata, you may be better off using SQL passthrough to Teradata.&lt;/P&gt;</description>
    <pubDate>Mon, 13 Feb 2023 10:52:14 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2023-02-13T10:52:14Z</dc:date>
    <item>
      <title>Convert SQL / teradata code to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-SQL-teradata-code-to-SAS/m-p/858479#M339192</link>
      <description>&lt;P&gt;I have the following code which I need to convert in SAS form:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;create volatile table gl as (&lt;BR /&gt;select GEN_ID, AU_GEN_ID, TYPE_2_DESC,&lt;BR /&gt;TYPE_5_DESC, TYPE_8_DESC&lt;BR /&gt;from COMMERCIAL_V3.DATA_F&lt;BR /&gt;qualify row_number() over&lt;BR /&gt;(partition by , GEN_ID, AU_GEN_ID order by DATA_OUTSTANDING_AMT desc,&lt;BR /&gt;DATA_TOTAL_COMMITMENT_AMT desc, DATA_GEN_ID desc)=1&lt;BR /&gt;) with data on commit preserve rows;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please share your inputs. TIA.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2023 07:41:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-SQL-teradata-code-to-SAS/m-p/858479#M339192</guid>
      <dc:creator>rahulsaha2127</dc:creator>
      <dc:date>2023-02-13T07:41:31Z</dc:date>
    </item>
    <item>
      <title>Re: Convert SQL / teradata code to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-SQL-teradata-code-to-SAS/m-p/858482#M339194</link>
      <description>&lt;P&gt;S lets's break into parts:&lt;/P&gt;
&lt;P&gt;- volatile table: it's equivalent to store a table (SAS dataset) in the WORK library.&lt;/P&gt;
&lt;P&gt;- row_number: in SAS PROC SQL there's an undocumented (hence not supported) function monotonic(). If you need to keep track on row numbers using supported functionality you need to use the data step instead of SQL (automatic _n_ variable).&lt;/P&gt;
&lt;P&gt;- qualify / partition by: can you explain what this does? I know about window functions but haven't really used them? Perhaps you need to attach an example of "have" data and what't the output.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2023 08:33:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-SQL-teradata-code-to-SAS/m-p/858482#M339194</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2023-02-13T08:33:29Z</dc:date>
    </item>
    <item>
      <title>Re: Convert SQL / teradata code to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-SQL-teradata-code-to-SAS/m-p/858493#M339202</link>
      <description>&lt;P&gt;The QUALIFY statement means that we are only taking the first row from each group. I think the easiest way to do this is to take all the data out in the order we want it, and then use a data step to get the first row in each partition:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table temp as
select GEN_ID, AU_GEN_ID, TYPE_2_DESC,
TYPE_5_DESC, TYPE_8_DESC,  DATA_OUTSTANDING_AMT, 
DATA_TOTAL_COMMITMENT_AMT
from COMMERCIAL_V3.DATA_F
order by GEN_ID, AU_GEN_ID, DATA_OUTSTANDING_AMT desc,
DATA_TOTAL_COMMITMENT_AMT desc, DATA_GEN_ID desc;
quit;

data want;
  set temp;
  by GEN_ID AU_GEN_ID;
  if first.AU_GEN_ID;
  drop DATA_OUTSTANDING_AMT DATA_TOTAL_COMMITMENT_AMT;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This assumes that your input data has been moved to a SAS library. If it is still in Teradata, you may be better off using SQL passthrough to Teradata.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2023 10:52:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-SQL-teradata-code-to-SAS/m-p/858493#M339202</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2023-02-13T10:52:14Z</dc:date>
    </item>
    <item>
      <title>Re: Convert SQL / teradata code to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-SQL-teradata-code-to-SAS/m-p/858497#M339206</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*
You'd better post a INPUT dataset and a OUTPUT dataset
to explain what you are looking for.
If I was right,try this code:
*/
proc sort data=have out=temp;
by 
 GEN_ID
 AU_GEN_ID 
 descending DATA_OUTSTANDING_AMT 
 descending DATA_TOTAL_COMMITMENT_AMT 
 descending DATA_GEN_ID 
;
run;
proc sort data=temp out=want nodupkey;
by 
 GEN_ID
 AU_GEN_ID 
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Feb 2023 11:48:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-SQL-teradata-code-to-SAS/m-p/858497#M339206</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-02-13T11:48:31Z</dc:date>
    </item>
    <item>
      <title>Re: Convert SQL / teradata code to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-SQL-teradata-code-to-SAS/m-p/858575#M339232</link>
      <description>&lt;P&gt;It's not clear what your actual use case is here. What data source will you be working with once you convert the Teradata code. Will it still be Teradata or will your data source change to SAS as well? If you continue to use Teradata as your data source then there is no need to rewrite your Teradata code. Just wrap it in a SAS SQL Passthru step and run it unchanged.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2023 19:09:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-SQL-teradata-code-to-SAS/m-p/858575#M339232</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-02-13T19:09:40Z</dc:date>
    </item>
  </channel>
</rss>

