<?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: proc cas User-defined Action definition parameters (FedSQL and quoting) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-cas-User-defined-Action-definition-parameters-FedSQL-and/m-p/920613#M362583</link>
    <description>&lt;P&gt;That is good &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That really does open it up. Now we have a choice of implementing Actions where you pass in a value and the Action takes care of the rest, and more 'open' ones where you pass in the SQL (or parts of).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Really helpfull.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks both for you input.&lt;/P&gt;</description>
    <pubDate>Sun, 17 Mar 2024 21:18:56 GMT</pubDate>
    <dc:creator>Brew</dc:creator>
    <dc:date>2024-03-17T21:18:56Z</dc:date>
    <item>
      <title>proc cas User-defined Action definition parameters (FedSQL and quoting)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-cas-User-defined-Action-definition-parameters-FedSQL-and/m-p/920414#M362504</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to create a User-Defined Action in CASL that makes use of the FEDSQL action.&lt;/P&gt;&lt;P&gt;The issue I have is with resolving the parameter passed to the action. This needs to be in single quotes within the definition - once resolved.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code below sets up a dummy data set, and then creates an action set with 2 actions. They do the same thing but the second has a parameter to allow passing of a string to the query. Its the second one that fails and I cant find the right way to code the quoting of the parameter in the SQL query. Or maybe its just not possible with the quoting within double-quotes format of defining the fedSQL.execDirect definition.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;/*start a CAS session called mySESS */
cas mySESS;
/* create a libref (MYLIB) using the CAS engine */
libname MYLIB cas;
/* create a dataset in MYLIB library (the active CASLIB being CASUSER)*/
Data MYLIB.aaa;
	length userName varchar(10);
	userName = 'aaa';TelNum = 111111;output;
	userName = 'bbb';TelNum = 222222;output;
run;

caslib _all_ assign;

/*create an action set called tblMakers*/
/* this includes 2 actions using fedSQL to create a table */
proc cas;
	builtins.defineActionSet / 
		name="tblMakers" 
 		label="make some new tables"
		actions={
			{
			name="tableCreate" 
			desc="create table in myLib" 
			definition="
				fedSQL.execDirect / query='create table casuser.bbb {options replace=true} as
					select userName
					from CASUSER.aaa
					where userName = ''bbb'' ';
			"
			}
			{
			name="tableCreateParam" 
			desc="create table in myLib with Param"
			parms={
			{name="usernameQ" type="STRING" required=True}
			} 
			definition="
				fedSQL.execDirect / query='create table casuser.ccc {options replace=true} as
					select userName
					from CASUSER.aaa
					where userName = usernameQ ';
			"
			}
		};
run;

/* run the tableCreate Action - this will work*/
proc cas;
tblMakers.tableCreate result=tbl;
run;

/* run the tableCreate Action - this will fail*/
proc cas;
tblMakers.tableCreateParam / usernameQ="bbb";
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know alternatives to fedSQL can be used ...and maybe we'll need to use them but SQL is strong here so is the preferred choice if available.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thankyou for looking.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2024 12:46:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-cas-User-defined-Action-definition-parameters-FedSQL-and/m-p/920414#M362504</guid>
      <dc:creator>Brew</dc:creator>
      <dc:date>2024-03-15T12:46:16Z</dc:date>
    </item>
    <item>
      <title>Re: proc cas User-defined Action definition parameters (FedSQL and quoting)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-cas-User-defined-Action-definition-parameters-FedSQL-and/m-p/920479#M362514</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the only way I could get it to work...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;Data casuser.aaa;
	length userName varchar(10);
	userName = 'aaa';TelNum = 111111;output;
	userName = 'bbb';TelNum = 222222;output;
    userName = 'ccc';TelNum = 222222;output;
    userName = 'ccc';TelNum = 222222;output;
run;


proc cas;
	query = "query ="||'"'||"create table casuser.ccc {options replace=true} as select userName from casuser.aaa where username ='"||'"||usernameq||"'||"'"||'"'||";  fedsql.execDirect / query = query;";
	builtins.defineActionSet / 
		name="tblMakers" 
 		label="make some new tables"
		actions={
			{
			name="tableCreateParam" 
			desc="create table in myLib with Param"
			parms={
			{name="usernameQ" type="STRING" required=True}
			} 
			definition=query
			}
		};
run;

/* run the tableCreate Action - this will fail*/
proc cas;
tblMakers.tableCreateParam / usernameQ="ccc";
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 15 Mar 2024 16:26:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-cas-User-defined-Action-definition-parameters-FedSQL-and/m-p/920479#M362514</guid>
      <dc:creator>Mazi</dc:creator>
      <dc:date>2024-03-15T16:26:00Z</dc:date>
    </item>
    <item>
      <title>Re: proc cas User-defined Action definition parameters (FedSQL and quoting)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-cas-User-defined-Action-definition-parameters-FedSQL-and/m-p/920507#M362526</link>
      <description>Thanks Mazi,&lt;BR /&gt;That does work &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; ...and I cant work out another way, let alone a more elegant one.</description>
      <pubDate>Fri, 15 Mar 2024 19:58:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-cas-User-defined-Action-definition-parameters-FedSQL-and/m-p/920507#M362526</guid>
      <dc:creator>Brew</dc:creator>
      <dc:date>2024-03-15T19:58:20Z</dc:date>
    </item>
    <item>
      <title>Re: proc cas User-defined Action definition parameters (FedSQL and quoting)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-cas-User-defined-Action-definition-parameters-FedSQL-and/m-p/920531#M362541</link>
      <description>I’ll try playing around with it more. If I can clean it up, I’ll send it through.</description>
      <pubDate>Sat, 16 Mar 2024 05:05:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-cas-User-defined-Action-definition-parameters-FedSQL-and/m-p/920531#M362541</guid>
      <dc:creator>Mazi</dc:creator>
      <dc:date>2024-03-16T05:05:29Z</dc:date>
    </item>
    <item>
      <title>Re: proc cas User-defined Action definition parameters (FedSQL and quoting)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-cas-User-defined-Action-definition-parameters-FedSQL-and/m-p/920532#M362542</link>
      <description>&lt;P&gt;I tried looking at it again but couldn't improve it further.&lt;/P&gt;&lt;P&gt;This was a good question, learnt something new about CASL myself.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Mazi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 16 Mar 2024 05:49:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-cas-User-defined-Action-definition-parameters-FedSQL-and/m-p/920532#M362542</guid>
      <dc:creator>Mazi</dc:creator>
      <dc:date>2024-03-16T05:49:58Z</dc:date>
    </item>
    <item>
      <title>Re: proc cas User-defined Action definition parameters (FedSQL and quoting)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-cas-User-defined-Action-definition-parameters-FedSQL-and/m-p/920539#M362544</link>
      <description>&lt;P&gt;After quite a bit of trial and error it appears below actually works (tested on&amp;nbsp;&lt;SPAN&gt;Stable 2024.01).&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data casuser.have;
  length userName varchar(10);
  userName = 'User 1';TelNum = 111111;output;
  userName = 'User 2';TelNum = 222222;output;
run;

/*create an action set called tblMakers*/
proc cas;
  builtins.defineActionSet / 
    name="tblMakers" 
    actions={
      {
      name="tableCreateParam" 
      parms={{name="tblName" type="STRING" required=True}{name="usernameQ" type="STRING" required=True}} 
      definition=
        "fedSQL.execDirect / query='create table casuser.'||strip(tblName)||' {options replace=true} as
            select userName, TelNum
            from CASUSER.have
            where userName='''||strip(usernameQ)||''' ';"
      }
    };
run;

/* run the tableCreateParam Action */
proc cas;
  tblMakers.tableCreateParam / tblName="want" usernameQ="User 2";
  table.fetch / table={ caslib="casuser" name="want"};
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Btw: In Viya 4 you get already as part of startup a cas session CASAUTO and a caslib and cas libname CASUSER.&lt;/P&gt;</description>
      <pubDate>Sat, 16 Mar 2024 09:12:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-cas-User-defined-Action-definition-parameters-FedSQL-and/m-p/920539#M362544</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-03-16T09:12:45Z</dc:date>
    </item>
    <item>
      <title>Re: proc cas User-defined Action definition parameters (FedSQL and quoting)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-cas-User-defined-Action-definition-parameters-FedSQL-and/m-p/920541#M362545</link>
      <description>Thanks, Patric&lt;BR /&gt;&lt;BR /&gt;I’ll have to test this in Viya 3.5 to see if it works.&lt;BR /&gt;&lt;BR /&gt;I think I tried something similar and it failed for me in 3.5.&lt;BR /&gt;&lt;BR /&gt;Also, how do you get your keywords highlighted in blue as if it were on a SAS editor?</description>
      <pubDate>Sat, 16 Mar 2024 09:00:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-cas-User-defined-Action-definition-parameters-FedSQL-and/m-p/920541#M362545</guid>
      <dc:creator>Mazi</dc:creator>
      <dc:date>2024-03-16T09:00:25Z</dc:date>
    </item>
    <item>
      <title>Re: proc cas User-defined Action definition parameters (FedSQL and quoting)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-cas-User-defined-Action-definition-parameters-FedSQL-and/m-p/920542#M362546</link>
      <description>&lt;P&gt;There have been a lot of improvements and added functionality since 3.5.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code I've posted earlier was tested on Viya 4 version Stable 2024.01&lt;/P&gt;</description>
      <pubDate>Sat, 16 Mar 2024 09:03:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-cas-User-defined-Action-definition-parameters-FedSQL-and/m-p/920542#M362546</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-03-16T09:03:07Z</dc:date>
    </item>
    <item>
      <title>Re: proc cas User-defined Action definition parameters (FedSQL and quoting)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-cas-User-defined-Action-definition-parameters-FedSQL-and/m-p/920543#M362547</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;, I can confirm that your solution works in Viya 3.5 as well!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for this.&lt;/P&gt;</description>
      <pubDate>Sat, 16 Mar 2024 09:05:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-cas-User-defined-Action-definition-parameters-FedSQL-and/m-p/920543#M362547</guid>
      <dc:creator>Mazi</dc:creator>
      <dc:date>2024-03-16T09:05:44Z</dc:date>
    </item>
    <item>
      <title>Re: proc cas User-defined Action definition parameters (FedSQL and quoting)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-cas-User-defined-Action-definition-parameters-FedSQL-and/m-p/920591#M362568</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/464333"&gt;@Mazi&lt;/a&gt;&amp;nbsp;&amp;amp;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/464511"&gt;@Brew&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now that I've made my next step in understanding how things work like that I can actually use actual program logic in the DEFINITION bit and that the scope of the parameters is local to the action, what about below version that allows for any where clause logic.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data casuser.have;
  length userName varchar(10);
  userName = 'User 1';TelNum = 111111;output;
  userName = 'User 2';TelNum = 222222;output;
  userName = 'User 3';TelNum = 333333;output;
run;

/*create an action set called tblMakers*/
%let _sv_quotelenmax=%sysfunc(getoption(quotelenmax));
options noquotelenmax;
proc cas;
  builtins.defineActionSet / 
    name="tblMakers" 
    type="CASL"
    actions={
      {
        name="tableCreateParam" 
        parms={ {name="tblName" type="STRING" required=True}
                {name="whereClause" type="STRING" required=False}
              } 
        definition=
          " if exists('whereClause') then whereClause=catx(' ','where',whereClause);
            else whereClause='';
            fedSQL.execDirect / query='create table casuser.'||tblName||' {options replace=true} as
              select userName, TelNum
              from CASUSER.have '||whereClause||' ';
          "
      }
    };
run;
options &amp;amp;_sv_quotelenmax;

/* run the tblMakers.tableCreateParam Action */
proc cas;
  tblMakers.tableCreateParam / tblName="want1" whereClause="userName='User 1' or TelNum = 333333";
  tblMakers.tableCreateParam / tblName="want2";
/*   table.fetch / table={ caslib="casuser" name="want1"}; */
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 17 Mar 2024 09:11:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-cas-User-defined-Action-definition-parameters-FedSQL-and/m-p/920591#M362568</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-03-17T09:11:32Z</dc:date>
    </item>
    <item>
      <title>Re: proc cas User-defined Action definition parameters (FedSQL and quoting)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-cas-User-defined-Action-definition-parameters-FedSQL-and/m-p/920603#M362576</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/211384"&gt;@patric&lt;/a&gt;, I actually like what you’ve done here.&lt;BR /&gt;&lt;BR /&gt;I think it can be super useful when you want to create tables consisting of various subsets.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sun, 17 Mar 2024 14:14:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-cas-User-defined-Action-definition-parameters-FedSQL-and/m-p/920603#M362576</guid>
      <dc:creator>Mazi</dc:creator>
      <dc:date>2024-03-17T14:14:01Z</dc:date>
    </item>
    <item>
      <title>Re: proc cas User-defined Action definition parameters (FedSQL and quoting)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-cas-User-defined-Action-definition-parameters-FedSQL-and/m-p/920613#M362583</link>
      <description>&lt;P&gt;That is good &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That really does open it up. Now we have a choice of implementing Actions where you pass in a value and the Action takes care of the rest, and more 'open' ones where you pass in the SQL (or parts of).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Really helpfull.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks both for you input.&lt;/P&gt;</description>
      <pubDate>Sun, 17 Mar 2024 21:18:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-cas-User-defined-Action-definition-parameters-FedSQL-and/m-p/920613#M362583</guid>
      <dc:creator>Brew</dc:creator>
      <dc:date>2024-03-17T21:18:56Z</dc:date>
    </item>
    <item>
      <title>Re: proc cas User-defined Action definition parameters (FedSQL and quoting)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-cas-User-defined-Action-definition-parameters-FedSQL-and/m-p/920862#M362689</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;SPAN&gt;....&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt; Btw: In Viya 4 you get already as part of startup a cas session CASAUTO and a caslib and cas libname CASUSER.&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please note that above statement is not correct and you can't rely on CASAUTO and CASUSER to always exist after startup.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Having said that: If you can see cas engine libraries in the Studio library pane right from beginning then there must have been a CAS session created as part of site specific config for SAS startup.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Mar 2024 01:19:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-cas-User-defined-Action-definition-parameters-FedSQL-and/m-p/920862#M362689</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-03-19T01:19:42Z</dc:date>
    </item>
  </channel>
</rss>

