<?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: Can we write SQL in SAS intelligent Decision? in Decisioning</title>
    <link>https://communities.sas.com/t5/Decisioning/Can-we-write-SQL-in-SAS-intelligent-Decision/m-p/937207#M117</link>
    <description>&lt;P&gt;It seem I need to use that code in sas studio. Can I use it in SAS ID?&lt;/P&gt;</description>
    <pubDate>Fri, 26 Jul 2024 09:20:57 GMT</pubDate>
    <dc:creator>Mayt</dc:creator>
    <dc:date>2024-07-26T09:20:57Z</dc:date>
    <item>
      <title>Can we write SQL in SAS intelligent Decision?</title>
      <link>https://communities.sas.com/t5/Decisioning/Can-we-write-SQL-in-SAS-intelligent-Decision/m-p/936982#M113</link>
      <description>&lt;P&gt;Currently, I am working on a SAS Intelligent Decision(SAS ID) project. The project needs to do some tasks involving using datagrid. In this project we use oracle database.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know that SAS ID has sql code file. But it seems we can only perform simple sql statement to table in database. (&lt;A href="https://documentation.sas.com/doc/en/edmcdc/5.3/edmug/p0zqdi1bacsmexn1va2096e6i5or.htm" target="_self"&gt;ref sas doc&lt;/A&gt;&amp;nbsp;) I want to perform tasks such as receive datagrid as input then manipulate data and return output. So, I guess I may need to use ds2/custom functions in&amp;nbsp;SAS ID.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unfortunately, I find it very difficult to write ds2/custom functions to perform datagrid tasks such as join with condition. I tried to use datagrid functions, but it can’t replace SQL 100%. I doubt that can we write SQL within ds2 code files?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have been suggested to write python in SAS ID to call function in oracle. But for some reason I can’t use python right now.&lt;/P&gt;
&lt;P&gt;Here my questions:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Can I write SQL within ds2 code files? &amp;nbsp;&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;Is there anyway to perform sql statement to datagrid?&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Or if you have any other suggestion please tell me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are example tasks that I want to perform in SAS ID:&lt;/P&gt;
&lt;P&gt;an example is written in microsoft sql language. It's quite simple, but there are some tasks that more complex and it would be easier to code in sql. That why I want to use SQL.&lt;/P&gt;
&lt;PRE&gt;CREATE FUNCTION [dbo].[function_A]
(
	-- Add the parameters for the function here
	@Appkey NVARCHAR(34)
)
RETURNS SMALLINT
AS
BEGIN
	DECLARE @Counter SMALLINT
	
		SELECT @Counter = SUM(
			CASE WHEN COL_A &amp;gt; 0  THEN 1
				WHEN COL_B &amp;gt; 0 THEN 1
				WHEN COL_C &amp;gt; 0 THEN 1
				WHEN COL_D &amp;gt; 0 THEN 1
		ELSE 0 END) FROM TABLE_A a left join TABLE_B b on a.col_name = b.col_name WITH (NOLOCK) WHERE Appkey = @Appkey
	

	-- Return the result of the function
	RETURN @Counter

END

GO&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Jul 2024 14:33:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Decisioning/Can-we-write-SQL-in-SAS-intelligent-Decision/m-p/936982#M113</guid>
      <dc:creator>Mayt</dc:creator>
      <dc:date>2024-07-24T14:33:05Z</dc:date>
    </item>
    <item>
      <title>Re: Can we write SQL in SAS intelligent Decision?</title>
      <link>https://communities.sas.com/t5/Decisioning/Can-we-write-SQL-in-SAS-intelligent-Decision/m-p/937000#M114</link>
      <description>&lt;P&gt;The DS2 SET statement will accept the result of a FedSQL query as input, and can subsequently process each of the rows returned.&amp;nbsp; For example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Make some test data */
data one;
	do ID=1 to 20;
		Text1='One';
		output;
	end;
run;
data two;
	do ID=1 to 20 by 2;
		Text2='Two';
		output;
	end;
run;

/* Process SQL join result in DS2 */
proc ds2;
data result/overwrite=yes;
	method run();
		set {select one.ID, coalescec(text2,text1) as Text 
				  from one left join two
				  on one.ID=two.ID};
	end;
enddata;
run;
quit;
proc print data=result;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Jul 2024 15:10:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Decisioning/Can-we-write-SQL-in-SAS-intelligent-Decision/m-p/937000#M114</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2024-07-24T15:10:22Z</dc:date>
    </item>
    <item>
      <title>Re: Can we write SQL in SAS intelligent Decision?</title>
      <link>https://communities.sas.com/t5/Decisioning/Can-we-write-SQL-in-SAS-intelligent-Decision/m-p/937073#M115</link>
      <description>&lt;P&gt;What you have posted is an example of creating a function in SQL Server. Since your database is Oracle, there is nothing stopping you from creating a similar function in that database. You will find plenty of examples on the Oracle website including this one:&amp;nbsp;&lt;A href="https://blogs.oracle.com/developers/post/anonymous-plsql-function-in-sql" target="_blank"&gt;https://blogs.oracle.com/developers/post/anonymous-plsql-function-in-sql&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can then use SQL Passthru similar to this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname SQLSRVR odbc noprompt = "server=MyServer;DRIVER=SQL Server Native Client 18.0;Trusted_Connection=yes;" DATABASE = MyDatabase;

proc sql noprint;
  connect using SQLSRVR;
execute (exec Myfunction();) by SQLSRVR;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jul 2024 01:46:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Decisioning/Can-we-write-SQL-in-SAS-intelligent-Decision/m-p/937073#M115</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2024-07-25T01:46:36Z</dc:date>
    </item>
    <item>
      <title>Re: Can we write SQL in SAS intelligent Decision?</title>
      <link>https://communities.sas.com/t5/Decisioning/Can-we-write-SQL-in-SAS-intelligent-Decision/m-p/937206#M116</link>
      <description>&lt;P&gt;I can't use it in ds2 in SAS ID&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;package "${PACKAGE_NAME}" /inline;
    method execute();
    /* Make some test data */
data one;
	do ID=1 to 20;
		Text1='One';
		output;
	end;
run;
data two;
	do ID=1 to 20 by 2;
		Text2='Two';
		output;
	end;
run;

/* Process SQL join result in DS2 */
proc ds2;
data result/overwrite=yes;
	method run();
		set {select one.ID, coalescec(text2,text1) as Text 
				  from one left join two
				  on one.ID=two.ID};
	end;
enddata;
run;
quit;
proc print data=result;
run;
   end;
endpackage;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Mayt_0-1721985504191.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/98739i3168678AF02B63D6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Mayt_0-1721985504191.png" alt="Mayt_0-1721985504191.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jul 2024 09:18:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Decisioning/Can-we-write-SQL-in-SAS-intelligent-Decision/m-p/937206#M116</guid>
      <dc:creator>Mayt</dc:creator>
      <dc:date>2024-07-26T09:18:36Z</dc:date>
    </item>
    <item>
      <title>Re: Can we write SQL in SAS intelligent Decision?</title>
      <link>https://communities.sas.com/t5/Decisioning/Can-we-write-SQL-in-SAS-intelligent-Decision/m-p/937207#M117</link>
      <description>&lt;P&gt;It seem I need to use that code in sas studio. Can I use it in SAS ID?&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jul 2024 09:20:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Decisioning/Can-we-write-SQL-in-SAS-intelligent-Decision/m-p/937207#M117</guid>
      <dc:creator>Mayt</dc:creator>
      <dc:date>2024-07-26T09:20:57Z</dc:date>
    </item>
    <item>
      <title>Re: Can we write SQL in SAS intelligent Decision?</title>
      <link>https://communities.sas.com/t5/Decisioning/Can-we-write-SQL-in-SAS-intelligent-Decision/m-p/937251#M118</link>
      <description>&lt;P&gt;PROC SQL doesn't run in MAS or CAS - only in the Compute Server. However, the Federated SQL that does run there is pretty ANSI standard.&lt;BR /&gt;Check out the Intelligent Decisioning docs for &lt;A href="https://pubshelpcenter.unx.sas.com/test/doc/en/edmcdc/v_049/edmug/p0zqdi1bacsmexn1va2096e6i5or.htm#n0c2rsngfl1n7un1ek74eg4v8kki" target="_self"&gt;Developing SQL Code&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jul 2024 13:57:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Decisioning/Can-we-write-SQL-in-SAS-intelligent-Decision/m-p/937251#M118</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2024-07-26T13:57:28Z</dc:date>
    </item>
  </channel>
</rss>

