<?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: Replicating some SQL Queries in SAS DI in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/Replicating-some-SQL-Queries-in-SAS-DI/m-p/596632#M8150</link>
    <description>&lt;P&gt;Are you using user written transformation?&lt;/P&gt;</description>
    <pubDate>Tue, 15 Oct 2019 19:19:54 GMT</pubDate>
    <dc:creator>subin</dc:creator>
    <dc:date>2019-10-15T19:19:54Z</dc:date>
    <item>
      <title>Replicating some SQL Queries in SAS DI</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Replicating-some-SQL-Queries-in-SAS-DI/m-p/596576#M8148</link>
      <description>&lt;P&gt;I am currently working on a project and have all my queries written in SQL. I have tried replicating some of these queries using the SAS DI Studio but I've been unable to as I keep getting an error every time. I'd appreciate if anyone who has had experience with something similar can point me in the right direction of how to go about it.&lt;/P&gt;&lt;P&gt;The Query is below:&lt;/P&gt;&lt;PRE&gt;select exc.ACCOUNT_RK, exc.excess_amt 
into #temp_largest_excess
from (
select 
la.ACCOUNT_RK 
,max((fac.BALANCE_AMT - la.X_MAX_AVAILABLE_AMT)) as excess_amt
from LOAN_ACCOUNT la
inner join FINANCIAL_ACCOUNT_CHNG fac on fac.ACCOUNT_RK = la.ACCOUNT_RK and la.VALID_FROM_DTTM between fac.VALID_FROM_DTTM and fac.valid_to_dttm and fac.currency_cd = 'CAD' -- align time periods 
where fac.VALID_FROM_DTTM between DATEADD(m,-1,DATEADD(m, DATEDIFF(m,0,GETDATE()),0)) and EOMONTH(dateadd(month,-1,getdate())) -- balances between start and end of last month
and (fac.BALANCE_AMT - la.X_MAX_AVAILABLE_AMT) &amp;gt; 0 -- defn of excess
group by la.ACCOUNT_RK 
UNION
select 
la.ACCOUNT_RK 
,max((fac.BALANCE_AMT - la.X_MAX_AVAILABLE_AMT)) as excess_amt
from LEASE_ACCOUNT la
inner join FINANCIAL_ACCOUNT_CHNG fac on fac.ACCOUNT_RK = la.ACCOUNT_RK and la.VALID_FROM_DTTM between fac.VALID_FROM_DTTM and fac.valid_to_dttm and fac.currency_cd = 'CAD' -- align time periods 
where fac.VALID_FROM_DTTM between DATEADD(m,-1,DATEADD(m, DATEDIFF(m,0,GETDATE()),0)) and EOMONTH(dateadd(month,-1,getdate())) -- balances between start and end of last month
and (fac.BALANCE_AMT - la.X_MAX_AVAILABLE_AMT) &amp;gt; 0 -- defn of excess
group by la.ACCOUNT_RK 
UNION
select 
la.ACCOUNT_RK 
,max((fac.BALANCE_AMT - la.X_MAX_AVAILABLE_AMT)) as excess_amt
from MORTGAGE_ACCOUNT la
inner join FINANCIAL_ACCOUNT_CHNG fac on fac.ACCOUNT_RK = la.ACCOUNT_RK and la.VALID_FROM_DTTM between fac.VALID_FROM_DTTM and fac.valid_to_dttm and fac.currency_cd = 'CAD' -- align time periods 
where fac.VALID_FROM_DTTM between DATEADD(m,-1,DATEADD(m, DATEDIFF(m,0,GETDATE()),0)) and EOMONTH(dateadd(month,-1,getdate())) -- balances between start and end of last month
and (fac.BALANCE_AMT - la.X_MAX_AVAILABLE_AMT) &amp;gt; 0 -- defn of excess
group by la.ACCOUNT_RK 
) exc&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;select
ROW_NUMBER() OVER (ORDER BY ACCOUNT_RK,VALID_FROM_DT) AS rn,
dateadd(day, -ROW_NUMBER() OVER (ORDER BY ACCOUNT_RK,VALID_FROM_DT), VALID_FROM_DT) AS grp,
ACCOUNT_RK,
VALID_FROM_DT
into #temp_excess_groups&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyone with an idea on how best to get these replicated in SAS DI Studio?&lt;/P&gt;</description>
      <pubDate>Tue, 15 Oct 2019 18:08:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Replicating-some-SQL-Queries-in-SAS-DI/m-p/596576#M8148</guid>
      <dc:creator>Soulbroda</dc:creator>
      <dc:date>2019-10-15T18:08:20Z</dc:date>
    </item>
    <item>
      <title>Re: Replicating some SQL Queries in SAS DI</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Replicating-some-SQL-Queries-in-SAS-DI/m-p/596632#M8150</link>
      <description>&lt;P&gt;Are you using user written transformation?&lt;/P&gt;</description>
      <pubDate>Tue, 15 Oct 2019 19:19:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Replicating-some-SQL-Queries-in-SAS-DI/m-p/596632#M8150</guid>
      <dc:creator>subin</dc:creator>
      <dc:date>2019-10-15T19:19:54Z</dc:date>
    </item>
    <item>
      <title>Re: Replicating some SQL Queries in SAS DI</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Replicating-some-SQL-Queries-in-SAS-DI/m-p/596659#M8151</link>
      <description>&lt;P&gt;No. I intend to use the SQL transformations in the DI Studio.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Oct 2019 20:53:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Replicating-some-SQL-Queries-in-SAS-DI/m-p/596659#M8151</guid>
      <dc:creator>Soulbroda</dc:creator>
      <dc:date>2019-10-15T20:53:35Z</dc:date>
    </item>
    <item>
      <title>Re: Replicating some SQL Queries in SAS DI</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Replicating-some-SQL-Queries-in-SAS-DI/m-p/596730#M8153</link>
      <description>&lt;P&gt;You will need to enable explicit pass-through in order to use database specific SQL syntax in expressions.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/etlug/67323/HTML/default/viewer.htm#n1sqvkm1pyw3a1n1ik1ayutua5gu.htm" target="_blank" rel="noopener"&gt;http://support.sas.com/documentation/cdl/en/etlug/67323/HTML/default/viewer.htm#n1sqvkm1pyw3a1n1ik1ayutua5gu.htm&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the first rather complex SQL (meaning multiple tables with Unions and Joins): To set that up in a single transformation will be painful. You could consider to first create views for the joins using the SQL Join transformation and then use the SQL Set transformation for the Union. ....or you could just implement the code as user written code (within a Proc SQL as explicit pass-through code). Even if user written, you still should map source to target column - even though that won't be functional anymore it would at least still support data lineage/impact analysis on a SAS Metadata level.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2019 03:18:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Replicating-some-SQL-Queries-in-SAS-DI/m-p/596730#M8153</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-10-16T03:18:06Z</dc:date>
    </item>
  </channel>
</rss>

