This task uses CAS actions that allow the user to view information about their chosen data set. A CAS Action sends a request to the server, invokes the action function, and returns the result. Viya PROCs are built from CAS Actions, but you can also code in Viya by writing the actions yourself using PROC CAS.
The task will accept a CAS table as input. The user can choose what output they are interested in from the options of table info, column info, or a simple data summary. The 3 CAS actions used are tables.tableinfo, tables.columninfo, and simple.summary.
Here's what the task looks like, with all output options selected and controls filled out:
Here is the PROC CAS code that is generated after selecting the above options:
proc cas;
table.tableinfo /name='CARS' caslib='CASUSER';
table.columninfo result=r /table={name='CARS', caslib='CASUSER'};
print r;
simple.summary / table={name='CARS', caslib='CASUSER' , groupby={'Make'} }
casOut={caslib="CASUSER", name="MYDATA", replace=true};
run;
proc print data=CASUSER.MYDATA;
run;
Finally, here are the results, that come from running the task:
One important point to note when using CAS actions in a Custom Task is that CAS Actions typically separate table name and library name, while the Custom Task controls output one long string for a two-level name (libraryname.datasetname). To use this with a CAS action, you will need to parse out the library name and the table name to fill in the CAS action. This can be done with the following VTL code:
#set($outputLibrefIndex = $outputData.toString().indexOf("."))
#set($outputLibrefIndex1 = $outputData.toString().indexOf(".")+1)
#set($outputCASLibref = $outputData.toString().substring(0, $outputLibrefIndex))
#set($outputCASName = $outputData.toString().substring($outputLibrefIndex1))
#set($inputLibrefIndex = $DATASOURCE.toString().indexOf("."))
#set($inputLibrefIndex1 = $DATASOURCE.toString().indexOf(".")+1)
#set($inputCASLibref = $DATASOURCE.toString().substring(0, $inputLibrefIndex))
#set($inputCASName = $DATASOURCE.toString().substring($inputLibrefIndex1))
Once you have pulled out the table and libref names into VTL macro variables ($outputCASName, $outputCASLibref, and $inputCASName, $inputCASLibref), you can reference them in your SAS Code.
Here is the rest of the VTL Code Template SAS code (but don't forget, you can download the task from our GitHub to try it yourself and see the entire CTM file):
proc cas ;
#if ( $chkTABLE == 1 )
table.tableinfo /name='$inputCASName' caslib='$inputCASLibref';
#end
#if ( $chkCOLUMN == 1 )
table.columninfo result=r /table={name='$inputCASName', caslib='$inputCASLibref'};
print r;
#end
#if ( $chkSUMMARY == 1 )
simple.summary / table={name='$inputCASName', caslib='$inputCASLibref' #if ($VAR.size() !=0 ), groupby={ #foreach( $item in $VAR ) '$item' #end} #end}
casOut={caslib="$outputCASLibref", name="$outputCASName", replace=true};
#end
run;
#if ( $chkSUMMARY == 1 )
proc print data=$outputData;
run;
#end
Do you have any ideas to improve this Custom Task? Let me know in the comments below!
Use the hashtag #CustomTaskTuesday and tweet @OliviaJWright with your Custom Task comments and questions!
Visit our SAS Studio GitHub to download the code for this task and follow along.
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.