Hello,
I am using SAS VIYA 3.5.
Has anybody tried to define an in-memory table in the "definition" parameter of "builtins.defineActionSet"?
(I am aware that the table can be created when we call the new custom CAS action using "savereresult" statement)
For example in the following code I have tried to save the details of the table TBL in table CASUSER.TBL_RES directly from the definition of the new action set. I think that "send_response" highlighted in orange is not right. The error code I receive is below the code.
Thank you for your suggestions.
Regards,
smm662002
proc cas;
builtins.defineActionSet / name ="myActSet2"
actions=
{
{
name="lsttblDet"
desc="Display Table Details"
parms={
{name="caslib" type="string" required=TRUE isCaslib=TRUE}
{name="table" type="string" required=TRUE}
{name="caslib2" type="string" required=TRUE isCaslib=TRUE}
{name="table2" type="CASOUTTABLE" required=TRUE}
}
definition="
table.tableDetails result=a /caslib=caslib table=table;
temp=findtable(a);
saveresult temp caslib=caslib2 casout=table2;
send_response(caslib2.table2);
"
}
};
quit;
proc cas;
myActSet2.lsttblDet /
caslib=casuser table=TBL
caslib2=casuser table2=TBL_a;
quit;
there are some errors like the type statement for the table2 parameter.
caslibs need to be assigned properly, no need for send_response construct.
proc cas;
builtins.defineActionSet / name ="myActSet2"
actions=
{
{
name="lsttblDet"
desc="Display Table Details"
parms={
{name="caslib" type="string" required=TRUE isCaslib=TRUE}
{name="table" type="string" required=TRUE}
{name="caslib2" type="string" required=TRUE isCaslib=TRUE}
{name="table2" type="string" required=TRUE}
}
definition="
table.tableDetails result=a /caslib=caslib table=table;
saveresult a caslib=caslib2 casout=table2;
"
}
};
quit;
cas mySession sessopts=(caslib=casuser timeout=1800 locale="en_US");
caslib _all_ assign;
data casuser.cars;
set sashelp.cars;
run;
proc cas;
myActSet2.lsttblDet /
caslib='casuser' table='cars'
caslib2='casuser' table2='mytab';
quit;
there are some errors like the type statement for the table2 parameter.
caslibs need to be assigned properly, no need for send_response construct.
proc cas;
builtins.defineActionSet / name ="myActSet2"
actions=
{
{
name="lsttblDet"
desc="Display Table Details"
parms={
{name="caslib" type="string" required=TRUE isCaslib=TRUE}
{name="table" type="string" required=TRUE}
{name="caslib2" type="string" required=TRUE isCaslib=TRUE}
{name="table2" type="string" required=TRUE}
}
definition="
table.tableDetails result=a /caslib=caslib table=table;
saveresult a caslib=caslib2 casout=table2;
"
}
};
quit;
cas mySession sessopts=(caslib=casuser timeout=1800 locale="en_US");
caslib _all_ assign;
data casuser.cars;
set sashelp.cars;
run;
proc cas;
myActSet2.lsttblDet /
caslib='casuser' table='cars'
caslib2='casuser' table2='mytab';
quit;
Hi, I share with you another more sophisticated example of defineactionset usage.
give it a try, I get it working by trial and error, I do not have a documentation at hand.
proc cas;
builtins.defineActionSet / name="myActionSet"
actions={
{
name="listTableInfo"
desc="Return Information about a CAS Table"
parms={
{name="caslib" type="string" required=TRUE}
{name="table" type="string" required=TRUE}
}
definition="
table.tableInfo result= a / caslib=caslib table=table;
send_response(a);
"
}
{
name="detailfreq"
desc="Return Detailed Frequency and Tabulate Information"
parms={
{name="caslib" type="string" required=TRUE} {name="table" type="string" required=TRUE}
{name="var1" type="string" required=TRUE} {name="var2" type="string" required=TRUE}
}
definition="
freqtab.freqtab result=c/
table={caslib=caslib name=table},
tabulate={var1, var2,
{vars={var1, var2}}};
send_response(c);
"
}
{
name="corr"
desc="Generate a Matrix of Pearson Product-Moment correlation coefficients"
parms={
{name="caslib" type="string" required=TRUE} {name="table" type="string" required=TRUE}
{name="var1" type="string" required=TRUE} {name="var2" type="string" required=TRUE}
{name="var3" type="string" required=TRUE} {name="var4" type="string" required=TRUE}
}
definition="
simple.correlation result= d /
inputs={var1, var2}
pairwithinput={var3, var4}
table={caslib=caslib name=table};
send_response(d);
"
}
{
name="simplefreq"
desc="Return Simple Frequency Information"
parms={
{name="caslib" type="string" required=TRUE} {name="table" type="string" required=TRUE}
{name="var1" type="string" required=TRUE} {name="var2" type="string" required=TRUE}
}
definition="
simple.freq result=b /
inputs={var1, var2}
table={caslib=caslib name=table};
send_response(b);
"
}
};
run;
proc cas;
myActionSet.listTableInfo result=a/
caslib="akaike" table="cars";
print a;
myActionSet.simplefreq result=b/
caslib="akaike" table="cars" var1="Origin" var2="DriveTrain";
print b;
myActionSet.detailfreq result=C /
caslib="akaike" table="cars" var1="Origin" var2="type";
print c;
myActionSet.corr result=d /
caslib="akaike" table="cars" var1="MSRP" var2="Invoice"
var3="Horsepower" var4="MPG_City";
print d;
quit;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: