<?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: Using a Teradata UDF in SAS Implicit Sql Pass Thru in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-a-Teradata-UDF-in-SAS-Implicit-Sql-Pass-Thru/m-p/266831#M52671</link>
    <description>&lt;P&gt;hi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did you check whether the function was passed down to the DBMS?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From your description it sounds like this did not happen.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why not, I have no idea.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I used the example I showed to implement this as you describe, so that SAS Enterprise Guide users could use the query builder with the UDF function within the database.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bruno&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 27 Apr 2016 19:26:35 GMT</pubDate>
    <dc:creator>BrunoMueller</dc:creator>
    <dc:date>2016-04-27T19:26:35Z</dc:date>
    <item>
      <title>Using a Teradata UDF in SAS Implicit Sql Pass Thru</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-Teradata-UDF-in-SAS-Implicit-Sql-Pass-Thru/m-p/266454#M52527</link>
      <description>&lt;P&gt;I am trying to use a Teradata UDF (User Defined Function) in a SAS Implicit SQL which establishes the connection to Teradata using LIBNAME Statement. Assume that the function is called &lt;STRONG&gt;PTY_DECRYPT&lt;/STRONG&gt; and is defined in a Database called &lt;STRONG&gt;TEST&lt;/STRONG&gt; in Teradata. The Purpose of this function is to decrypt values in a Column of a View in Teradata.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What works is using the UDF in an Explicit Sql .Below I am using the function on a column called &lt;STRONG&gt;SSN_NBR&lt;/STRONG&gt; in a view called &lt;STRONG&gt;V_TEST_PERS&lt;/STRONG&gt; present in the Database called &lt;STRONG&gt;SAMPLE&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Explcit Sql (This Works!):&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Options debug=DBMS_TIMERS sastrace=',,,d'
sastraceloc=saslog no$stsuffix fullstimer;


Proc Sql;
Connect to TERADATA(User=XXXXX pwd=XXXXX server=XXXXX);
Create Table Final as
select * from connection to teradata
(
Select
sub_id, 
SSN_NBR,
TEST.PTY_DECRYPT(SSN_NBR,'T_ssn_test',400,0,0 ) as SSN_NBR_Decrypt
from SAMPLE.V_TEST_PERS
);
disconnect from teradata;
Quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I would like to use the same function in an Implicit SQL but it does not work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Implicit Sql (This does not Work)&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Options debug=DBMS_TIMERS sastrace=',,,d'
sastraceloc=saslog no$stsuffix fullstimer;

Libname Td Teradata User=XXXXX pwd=XXXXX server=XXXXX database=SAMPLE ;

Proc sql;
Create table Final as
select
sub_id, 
SSN_NBR,
TEST.PTY_DECRYPT(SSN_NBR,'T_ssn_test',400,0,0 ) as SSN_NBR_Decrypt
from Td.V_TEST_PERS;
Quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Any ideas as &amp;nbsp;to how to make &amp;nbsp;this &amp;nbsp;Function work in Implicit Sql &amp;nbsp;with minimum changes? &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I &amp;nbsp;am using SAS 9.4M3 on AIX 64bit . &amp;nbsp; Not sure if there are any &amp;nbsp;SAS/ACCESS Libname specific Options which can do the trick.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2016 17:23:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-Teradata-UDF-in-SAS-Implicit-Sql-Pass-Thru/m-p/266454#M52527</guid>
      <dc:creator>pchegoor</dc:creator>
      <dc:date>2016-04-26T17:23:17Z</dc:date>
    </item>
    <item>
      <title>Re: Using a Teradata UDF in SAS Implicit Sql Pass Thru</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-Teradata-UDF-in-SAS-Implicit-Sql-Pass-Thru/m-p/266504#M52538</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is possible to do this. Check this doc &lt;A href="http://support.sas.com/documentation/cdl/en/acreldb/68028/HTML/default/viewer.htm#n0k1cax0gzsdxdn1a3466l1gwtk9.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/acreldb/68028/HTML/default/viewer.htm#n0k1cax0gzsdxdn1a3466l1gwtk9.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Find below some old code sample I found, please note it is not tested, but should give you a starting point.&lt;/P&gt;
&lt;P&gt;Here are the basic steps:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;create a SAS function using Proc FCMP that has the same number and types of arguments, the function does not need anything to do, it is just so that the name is recognized&lt;/LI&gt;
&lt;LI&gt;add the function information to a SAS data set&lt;/LI&gt;
&lt;LI&gt;specifiy this data set with SQL_FUNCTIONS= option of the LIBNAME statement&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* First create an UDF function in Teradata called plusudf with bteq/sql query assistant*/
/*create dummysas function with FCMP procedure*/
proc fcmp outlib=work.funcs.trial;
  function dummysas(X, Y);
    return (n);
  endsub;
run;

options cmplib=work.funcs;

/* Test the new function in sas*/
data _null_;
  x=dummysas(1,2);
  put x=;
run;

/*add function to sql dictionnary*/
data work.newfunc;
  SASFUNCNAME = "dummysas";
  SASFUNCNAMELEN = 8;
  DBMSFUNCNAME = "plusudf";
  DBMSFUNCNAMELEN = 7;
  FUNCTION_CATEGORY = "SCALAR";
  FUNC_USAGE_CONTEXT = "SELECT_LIST";
  FUNCTION_RETURNTYP = "INTEGER";
  FUNCTION_NUM_ARGS = 2;
  CONVERT_ARGS = 0;
  ENGINEINDEX = 0;
  output;
run;

/*Test the UDF function in Teradata*/
libname financ teradata server=dbc schema="financial" user=tduser pwd=tduser 
  SQL_FUNCTIONS="EXTERNAL_APPEND=work.newfunc"
  SQL_FUNCTIONS_COPY= saslog
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bruno&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2016 19:21:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-Teradata-UDF-in-SAS-Implicit-Sql-Pass-Thru/m-p/266504#M52538</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2016-04-26T19:21:51Z</dc:date>
    </item>
    <item>
      <title>Re: Using a Teradata UDF in SAS Implicit Sql Pass Thru</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-Teradata-UDF-in-SAS-Implicit-Sql-Pass-Thru/m-p/266581#M52569</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32"&gt;@BrunoMueller﻿&lt;/a&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Thank You for your &amp;nbsp;Reply .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried your solution &amp;nbsp;but &amp;nbsp;i &amp;nbsp;do not &amp;nbsp;get &amp;nbsp;desired result . &amp;nbsp;Instead &amp;nbsp;i just get a blank value .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The &amp;nbsp;Teradata &amp;nbsp;UDF in my Original &amp;nbsp;example above is &amp;nbsp;in a separate Database in Teradata &amp;nbsp;for &amp;nbsp;eg &amp;nbsp;&lt;STRONG&gt;TEST&lt;/STRONG&gt; &amp;nbsp;in the above case . The function name &amp;nbsp;being &lt;STRONG&gt;PTY_DECRYPT&lt;/STRONG&gt;. &amp;nbsp;It &amp;nbsp;Takes &amp;nbsp;5 &amp;nbsp;arguments , &amp;nbsp;The first &amp;nbsp;2 &amp;nbsp;arguments &amp;nbsp;are of type&lt;STRONG&gt;&amp;nbsp;VARCHAR&lt;/STRONG&gt; &amp;nbsp;and &amp;nbsp;Rest of the arguments of &amp;nbsp;type &amp;nbsp;&lt;STRONG&gt;INTEGER&lt;/STRONG&gt;. The Function &amp;nbsp;also returns a &lt;STRONG&gt;VARCHAR&lt;/STRONG&gt; of length 400.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I have defined &amp;nbsp;the SAS Function &amp;nbsp;as shown below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc fcmp outlib=work.funcs.trial;
function dummysas(col1 $,Col2 $,Col3,Col4,Col5) $ 400;
return (n);
endsub;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Next &amp;nbsp;the &amp;nbsp;Function &amp;nbsp;to &amp;nbsp;be added to &amp;nbsp;the Sql Dictionary &amp;nbsp;is defined as follows :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.newfunc;
SASFUNCNAME = "dummysas";
SASFUNCNAMELEN = 8;
DBMSFUNCNAME = "TEST.PTY_DECRYPT";
DBMSFUNCNAMELEN = 16;
FUNCTION_CATEGORY = "SCALAR";
FUNC_USAGE_CONTEXT = "SELECT_LIST";
FUNCTION_RETURNTYP = "VARCHAR";
FUNCTION_NUM_ARGS = 5;
CONVERT_ARGS = 0;
ENGINEINDEX = 0;
output;
run;


&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally i try &amp;nbsp;to use &amp;nbsp;the &amp;nbsp;Function above in a &amp;nbsp;Query &amp;nbsp;using &amp;nbsp;Implicit &amp;nbsp;Connection to Teradata. &amp;nbsp;The Function is being applied to a Column called &lt;STRONG&gt;SSN_NBR&lt;/STRONG&gt; &amp;nbsp;in &amp;nbsp;the Teradata &amp;nbsp;view called &amp;nbsp;&lt;STRONG&gt;V_TEST_PERS&lt;/STRONG&gt; &amp;nbsp;present in the Database called &amp;nbsp;&lt;STRONG&gt;SAMPLE&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Libname Td Teradata User=XXXXX pwd=XXXX&amp;nbsp; server=XXXXX schema=SAMPLE 
SQL_FUNCTIONS="EXTERNAL_APPEND=work.newfunc"
SQL_FUNCTIONS_COPY= saslog;

options cmplib=work.funcs;


Proc sql;
Create table Final as
select
sub_id, 
SSN_NBR,
dummysas(SSN_NBR,'T_ssn_test',400,0,0 ) as SSN_NBR_Decrypt
from Td.V_TEST_PERS;
Quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the &amp;nbsp;Dataset &amp;nbsp;&lt;STRONG&gt;Final&lt;/STRONG&gt; i get &amp;nbsp;the &amp;nbsp;Column &amp;nbsp;values of &lt;STRONG&gt;SSN_NBR_Decrypt&lt;/STRONG&gt; &amp;nbsp;as Blank &amp;nbsp; for all observations .&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also &amp;nbsp;i observe &amp;nbsp;that this column &amp;nbsp;has the same value &amp;nbsp;as that &amp;nbsp;returned by the &amp;nbsp;function &lt;STRONG&gt;dummysas&lt;/STRONG&gt; &amp;nbsp; within the &lt;STRONG&gt;&amp;nbsp;PROC FCMP&lt;/STRONG&gt; above.&lt;/P&gt;
&lt;P&gt;For eg &amp;nbsp;if &amp;nbsp;i &amp;nbsp;make the function &amp;nbsp;return a contant &amp;nbsp;value &amp;nbsp;of &amp;nbsp;&lt;STRONG&gt;YES&lt;/STRONG&gt; &amp;nbsp;then &amp;nbsp;the column &amp;nbsp;SSN_NBR_Decrypt as this &amp;nbsp;value of &amp;nbsp;&lt;STRONG&gt;YES&lt;/STRONG&gt; &amp;nbsp;for all observervations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Am i &amp;nbsp;doing anything wrong or is this not possible to implement via &amp;nbsp;Implicit Sql ?&lt;/P&gt;</description>
      <pubDate>Wed, 27 Apr 2016 19:54:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-Teradata-UDF-in-SAS-Implicit-Sql-Pass-Thru/m-p/266581#M52569</guid>
      <dc:creator>pchegoor</dc:creator>
      <dc:date>2016-04-27T19:54:59Z</dc:date>
    </item>
    <item>
      <title>Re: Using a Teradata UDF in SAS Implicit Sql Pass Thru</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-Teradata-UDF-in-SAS-Implicit-Sql-Pass-Thru/m-p/266831#M52671</link>
      <description>&lt;P&gt;hi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did you check whether the function was passed down to the DBMS?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From your description it sounds like this did not happen.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why not, I have no idea.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I used the example I showed to implement this as you describe, so that SAS Enterprise Guide users could use the query builder with the UDF function within the database.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bruno&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Apr 2016 19:26:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-Teradata-UDF-in-SAS-Implicit-Sql-Pass-Thru/m-p/266831#M52671</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2016-04-27T19:26:35Z</dc:date>
    </item>
    <item>
      <title>Re: Using a Teradata UDF in SAS Implicit Sql Pass Thru</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-Teradata-UDF-in-SAS-Implicit-Sql-Pass-Thru/m-p/266835#M52674</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just noticed the value for &lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;SASFUNCNAMELEN &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;9&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;should by&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;SASFUNCNAMELEN &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;8&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;maybe this helps &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bruno&lt;/P&gt;</description>
      <pubDate>Wed, 27 Apr 2016 19:35:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-Teradata-UDF-in-SAS-Implicit-Sql-Pass-Thru/m-p/266835#M52674</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2016-04-27T19:35:04Z</dc:date>
    </item>
    <item>
      <title>Re: Using a Teradata UDF in SAS Implicit Sql Pass Thru</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-Teradata-UDF-in-SAS-Implicit-Sql-Pass-Thru/m-p/266850#M52685</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Find below a complete example, although using Oracle, it should work the same for other DBMS. It seems, you do need an ORDER BY to pass down the function to the DBMS, without the ORDER BY the SAS function gets called.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  connect to oracle (
    path=xe user=educ password=educ
    );
  execute (
    CREATE OR REPLACE FUNCTION FROMSAS 
      (
      PARAM1 IN VARCHAR2 
      , PARAM2 IN VARCHAR2 
      , PARAM3 IN NUMBER 
      , PARAM4 IN NUMBER 
      , PARAM5 IN NUMBER 
      ) RETURN VARCHAR2 AS 
      BEGIN
      RETURN param1 || param2 || ':' || param3 || param4 || param5;
  END FROMSAS;
  ) by oracle;
quit;

proc fcmp outlib=work.funcs.trial;
  function fromsas(col1 $,Col2 $,Col3,Col4,Col5) $ 400;
    return ( catx("_", col1, col2, col3, col4, col5) );
  endsub;
run;

options cmplib=work.funcs;

/* Test the new function in sas*/
data _null_;
  x = dummysas("a", "b", 1, 2, 3);
  put x=;
run;

proc sql;
  create table someTest as
    select
      name
      , sex
      , age
      , height
      , weight
      , fromsas(name, sex, age, height, weight) as fromsas
    from
      sashelp.class
  ;
quit;

/*add function to sql dictionnary*/
data work.newdbmsfunc;
  SASFUNCNAME = "FROMSAS";
  SASFUNCNAMELEN = length(sasfuncname);
  DBMSFUNCNAME = "FROMSAS";
  DBMSFUNCNAMELEN = length(dbmsfuncname);
  FUNCTION_CATEGORY = "SCALAR";
  FUNC_USAGE_CONTEXT = "SELECT_LIST";
  FUNCTION_RETURNTYP = "CHAR";
  FUNCTION_NUM_ARGS = 0;
  CONVERT_ARGS = 0;
  ENGINEINDEX = 0;
  output;
run;

/* Test the UDF function in Oracle */
libname xora oracle path=xe user=educ password=educ
  SQL_FUNCTIONS="EXTERNAL_APPEND=work.newdbmsfunc"
  SQL_FUNCTIONS_COPY= saslog
;
options
  sastrace =',,,d'
  sastraceloc=saslog
  nostsuffix
;

proc sql;
  drop table xora.classtest;
quit;

proc append
  base=xora.classtest
  data=sashelp.class
;
run;

proc sql;
  create table someTest_dbms as
    select
      name
      , sex
      , age
      , FROMSAS(name, sex, age, height, weight) as fromsas
    from
      xora.classtest
    order by
      name
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Good luck&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bruno&lt;/P&gt;</description>
      <pubDate>Wed, 27 Apr 2016 20:19:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-Teradata-UDF-in-SAS-Implicit-Sql-Pass-Thru/m-p/266850#M52685</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2016-04-27T20:19:49Z</dc:date>
    </item>
    <item>
      <title>Re: Using a Teradata UDF in SAS Implicit Sql Pass Thru</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-Teradata-UDF-in-SAS-Implicit-Sql-Pass-Thru/m-p/266865#M52691</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32"&gt;@BrunoMueller﻿&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Sorry&amp;nbsp; actually&amp;nbsp;&amp;nbsp; it&amp;nbsp; should have been&lt;/P&gt;
&lt;PRE class="  language-sas"&gt;&lt;CODE class="  language-sas"&gt;SASFUNCNAMELEN &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;8&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;instead&amp;nbsp; of&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class="  language-sas"&gt;&lt;CODE class="  language-sas"&gt;SASFUNCNAMELEN &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;9&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I&amp;nbsp; have corrected it above.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But&amp;nbsp; it still does not work .I get the same blank value.&amp;nbsp; Tough luck.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also&amp;nbsp; i did turn on the following&amp;nbsp; options&amp;nbsp;&amp;nbsp; to see the how query is getting processed:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Options  debug=DBMS_TIMERS sastrace=',,,d'
sastraceloc=saslog no$stsuffix fullstimer ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I&amp;nbsp; noticed that function is not getting passed to Teradata .&amp;nbsp; This&amp;nbsp; is what i see in the SAS Log :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;TERADATA_6: Prepared: on connection 2&lt;BR /&gt;SELECT * FROM SAMPLE."v_test_pers"&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;TERADATA&amp;amp;colon; trqacol- No casting. Raw row size=39, Casted size=39, CAST_OVERHEAD_MAXPERCENT=20%&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;TERADATA_7: Prepared: on connection 2&lt;BR /&gt;SELECT "SUB_ID","SSN_NBR" FROM SAMPLE."v_test_pers" &lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;TERADATA_8: Executed: on connection 2&lt;BR /&gt;SELECT "SUB_ID","SSN_NBR" FROM SAMPLE."v_test_pers" &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;TERADATA&amp;amp;colon; trget - rows to fetch: 2&lt;BR /&gt;TERADATA&amp;amp;colon; trforc: COMMIT WORK &lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;DBMS_TIMER: summary statistics&lt;BR /&gt;DBMS_TIMER: total SQL execution seconds were: 0&lt;BR /&gt;DBMS_TIMER: total SQL prepare seconds were: 0&lt;BR /&gt;DBMS_TIMER: dbiopen/dbiclose timespan was 1.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Apr 2016 21:05:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-Teradata-UDF-in-SAS-Implicit-Sql-Pass-Thru/m-p/266865#M52691</guid>
      <dc:creator>pchegoor</dc:creator>
      <dc:date>2016-04-27T21:05:33Z</dc:date>
    </item>
    <item>
      <title>Re: Using a Teradata UDF in SAS Implicit Sql Pass Thru</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-Teradata-UDF-in-SAS-Implicit-Sql-Pass-Thru/m-p/266903#M52704</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32"&gt;@BrunoMueller﻿&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;Thank&amp;nbsp; you&lt;/STRONG&gt; for not giving up on this and showing me the right direction.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp;Your&amp;nbsp; ORDER BY suggestion worked!&amp;nbsp; The function returned the correct value when &lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp; used in an&amp;nbsp;&lt;/STRONG&gt;&lt;STRONG&gt;IMPLICIT Pass Through Query.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; Infact&amp;nbsp; i had approached SAS Tech Support with same question and i was told that it is not possible to use the&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;UDF in an IMPLICIT Pass through&amp;nbsp;&amp;nbsp; Query but that it can only be used in an&amp;nbsp; EXPLICIT&amp;nbsp; Pass through Query.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;This ONLY proves the SAS Language has many hidden features which not many are aware of &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; This has been a Great discussion .&amp;nbsp; Learnt&amp;nbsp; some new features .&amp;nbsp; Thank&amp;nbsp; you once again.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; Below&amp;nbsp; is&amp;nbsp; my&amp;nbsp; SAS Code incase someone&amp;nbsp; is interested in the same .&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Typically&amp;nbsp; it has the same logic as suggested by you&amp;nbsp; above .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*****************************************************************************************
  The Purpose of this Program is to utilize a Teradata UDF (User Defined Function)
  in an Implicit PROC SQL  Pass through Query in SAS.

  Assumption :  A  Teradata UDF already has been created with the name PTY_DECRYPT
                inside the Database TEST. The function has 5 arguments with the 1st
                and 2nd being of type VARCHAR and the rest being INTEGER. The Function also
                returns a string of type VARCHAR  and length 400.The purpose of the Function
                is to decrypt the value of column (SSN_NBR) in a Teradata view (V_TEST_PERS)
                located in a Database called SAMPLE

                Eg. Function Usage is as follows in an Explicit Sql  SELECT  statement:

                  TEST.PTY_DECRYPT(SSN_NBR,'T_ssn_test',400,0,0 )  as SSN_NBR_Decrypt 

********************************************************************************************/




/*This  Option  Statement  is necessary to prevent WARNING : Function &amp;lt;Function name&amp;gt; was defined in a previous package .......*/

Options cmplib=_NULL_;

/*Define a Dummy Function called dummysas using PROC FCMP having same Number and Type of Arguments as the Teradata UDF 
  The function also returns a string of length 50  similar to Teradata UDF. Note: Though the Teradata UDF returns a string 
  of length 400 characters you can use a value less than this or specify no value for this */

proc fcmp outlib=WORK.funcs.trial;
  function dummysas(col1 $,Col2 $,Col3,Col4,Col5) $ 50;
    return ('testvalue');
  endsub;
run;



/*Specify  the  SAS Dataset which contains the above compiled Function */

options cmplib=work.funcs;

/*  Test  the  Function  */

data A;
  x=dummysas('1','2',0,0,0);
  put x=;
run;

/* Create a  Dataset  with the above created Function and Teradata UDF  properties 
  to be added to the existing function list in the SQL dictionary */

/*For More Information see : http://goo.gl/OyNcyN */

data work.newfunc;
  SASFUNCNAME = "dummysas";    /*Specify correct name of the SAS  function above */
  SASFUNCNAMELEN = length(SASFUNCNAME); /*Specify correct length of the SAS function name */
  DBMSFUNCNAME = "TEST.PTY_DECRYPT"; /*Specify correct name of the Teradara UDF*/
  DBMSFUNCNAMELEN = length(DBMSFUNCNAME);/*Specify correct length of the Teradara UDF */
  FUNCTION_CATEGORY = "SCALAR";    /* Specify SCALAR  category */
  FUNC_USAGE_CONTEXT = "SELECT_LIST"; /* Specify Function Usage Context ie SELECT_LIST in this case */
  FUNCTION_RETURNTYP = "VARCHAR"; /*Specify CHAR or VARCHAR as Function Return  Type*/
  FUNCTION_NUM_ARGS = 0; /*Specify default value of 0 */
  CONVERT_ARGS = 0;  /*Specify default value of 0 */
  ENGINEINDEX = 0;  /*Specify default value of 0 */
  output;
run;

/*  Define  Teradata  Connection  using a Libname  Statement and add Options SQL_FUNCTIONS and SQL_FUNCTIONS_COPY */

Libname Td Teradata  User=test123 pwd=test123 server=TD_EDW database=SAMPLE  SQL_FUNCTIONS="EXTERNAL_APPEND=work.newfunc"
  SQL_FUNCTIONS_COPY= saslog ;


/* Display in the SAS Log information about where  the Query Processing occurs   */

  Options  debug=DBMS_TIMERS sastrace=',,,d'
sastraceloc=saslog no$stsuffix fullstimer ;


/*Use  the function dummysas  in the Implicit  Query */
/*Note :  The ORDER BY  Clause is necessary for the Function to be pushed to Database for Processing */

  Proc sql;
Create  table Temp as
select
sub_id , 
SSN_NBR,
dummysas(SSN_NBR,'T_ssn_test',50,0,0) as SSN_NBR_Decrypt 
from Td.V_TEST_PERS 
order by 1;
Quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Apr 2016 06:41:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-Teradata-UDF-in-SAS-Implicit-Sql-Pass-Thru/m-p/266903#M52704</guid>
      <dc:creator>pchegoor</dc:creator>
      <dc:date>2016-04-28T06:41:07Z</dc:date>
    </item>
    <item>
      <title>Re: Using a Teradata UDF in SAS Implicit Sql Pass Thru</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-Teradata-UDF-in-SAS-Implicit-Sql-Pass-Thru/m-p/267002#M52715</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Glad it finally worked, and thanks for sharing the code you have used.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bruno&lt;/P&gt;</description>
      <pubDate>Thu, 28 Apr 2016 15:39:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-Teradata-UDF-in-SAS-Implicit-Sql-Pass-Thru/m-p/267002#M52715</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2016-04-28T15:39:54Z</dc:date>
    </item>
  </channel>
</rss>

