BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
smm662002
Quartz | Level 8

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;

 

NOTE: Active Session now DEMO.
WARNING: Variable 'casuser' is uninitialized. It has been set to missing.
WARNING: Variable 'cars' is uninitialized. It has been set to missing.
WARNING: Variable 'cars_a2' is uninitialized. It has been set to missing.
ERROR: Cannot convert parameter 'caslib' from double to string.
ERROR: The action stopped due to errors.
 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
acordes
Rhodochrosite | Level 12

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;

View solution in original post

3 REPLIES 3
acordes
Rhodochrosite | Level 12

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;
smm662002
Quartz | Level 8
Hi,

Thank you so much for your answer. Spot on.
Initially I tried with "string" type for table2 but I had a similar error hence I decided to change to "CASOUTTABLE".
Would you have any additional documentation describing when to use the types "CASOUTTABLE" | "CASTABLE" | "CASVAR" | "PARAMLIST" ?
Also I had the impression that send_response is always required but your answer is proving that I misunderstood it.

Thank you,
smm662002
acordes
Rhodochrosite | Level 12

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; 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 698 views
  • 2 likes
  • 2 in conversation