Wednesday 22 May 2019

Using the Lua programming language within Base SAS® by Epoch Research Institute (http://epochresearchinstitute.com)

Using the Lua programming language within Base SAS®
Did you know that you can run Lua code within Base SAS? This functionality has been available since the SAS® 9.4M3 (TS1M3) release. With the LUA procedure, you can submit Lua statements from an external Lua script or just submit the Lua statements using SAS code. In this blog, I will discuss what PROC LUA can do as well as show some examples. I will also talk about a package that provides a Lua interface to SAS® Cloud Analytic Services (CAS).

What Is Lua?
Lua is a lightweight, embeddable scripting language. You can use it in many different applications from gaming to web applications. You might already have written Lua code that you would like to run within SAS, and PROC LUA enables you to do so.
With PROC LUA, you can perform these tasks:
§  run Lua code within a SAS session
§  call most SAS functions within Lua statements
§  call functions that are created using the FCMP procedure within Lua statements
§  submit SAS code from Lua
§  Call CAS actions

PROC LUA Examples

Here is a look at the basic syntax for PROC LUA:
Ex.
proc lua <infile='file-name'> <restart> <terminate>;

Suppose you have a file called my_lua.lua or my_lua.luc that contains Lua statements, and it is in a directory called /local/lua_scripts. You would like to run those Lua statements within a SAS session. You can use PROC LUA along with the INFILE= option and specify the file name that identifies the Lua source file (in this case, it is my_lua). The Lua file name within your directory must contain the .lua or. luc extension, but do not include the extension within the file name for the INFILE= option. A FILENAME statement must be specified with a LUAPATH fileref that points to the location of the Lua file. Then include the Lua file name for the INFILE= option, as shown here:

Ex.

filename luapath '/local/lua_scripts';
proc lua infile=’my_lua’;

This example executes the Lua statements contained within the file my_lua.lua or my_lua.luc from the /local/lua_scripts directory.
If there are multiple directories that contain Lua scripts, you can list them all in one FILENAME statement:
Ex.
filename luapath ('directory1', 'directory2', 'directory3');

The RESTART option resets the state of Lua code submissions for a SAS session. The TERMINATE option stops maintaining the Lua code state in memory and terminates the Lua state when PROC LUA completes.

The syntax above discusses how to run an external Lua script, but you can also run Lua statements directly in SAS code.

Here are a couple of examples that show how to use Lua statements directly inside PROC LUA:

Example 1:
   proc lua;
   submit;
      local names= {'Mickey', 'Donald', 'Goofy', 'Minnie'}
      for i,v in ipairs(names) do
         print(v)
   end
   endsubmit;
   run;
Here is the log output from Example 1:
NOTE: Lua initialized.
Mickey
Donald
Goofy
Minnie
NOTE: PROCEDURE LUA used (Total process time):
      real time           0.38 seconds
      cpu time            0.10 seconds


Using a Lua Interface with CAS:
Available to download is a package called SWAT, which stands for SAS Scripting Wrapper for Analytics Transfer. This is a Lua interface for CAS. After you download this package, you can load data into memory and apply CAS actions to transform, summarize, model, and score your data.
The package can be downloaded from this Downloads page: SAS Lua Client Interface for Viya. After you download the SWAT package, there are some requirements for the client machine to use Lua with CAS:
1.      You must use a 64-bit version of either Lua 5.2 or Lua 5.3 on Linux.
Note: If your deployment requires newer Lua binaries, visit http://luabinaries.sourceforge.net/.
Note: Some Linux distributions do not include the required shared library libnuma.so.1. It can be installed with the numactl package supplied by your distribution's package manager.
2.      You must install the third-party package dependencies middleclass (4.0+), csv, and ee5_base64, which are all included with a SAS® Viya® installation.
For more information about configuration, see the Readme file that is included with the SWAT download.
I hope this blog post has helped you understand the possible ways of using Lua with SAS. If you have other SAS issues that you would like me to cover in future blog posts, please comment below.


SAS Courses Training
Ahmedabad |     Bengaluru         |  Chennai
+91 79 4032 7000| +91 80 9575 7700|+91 99404 52792
  Whats-app: +91 99789 95178 | +91 63608 17936

EPOCH RESEARCH INSTITUTE OFFERS:
Authorized SAS TRAINING | SAS CERTIFICATION | SOFTWARE PURCHASE | BUSINESS CONSULTING | TECHNICAL SUPPORT ON SAS || SAS STAFFING SOLUTION  

SAS Training & Placement Programs with Internship: Epoch Research Institute India Largest and Oldest #SASTraining Institute (#epochsastraining)

Epoch Research Institute Links:

#CLINICALSASPROGRAMMING,#EPOCHRESEARCHINSTITUTE,
#EPOCHSASFEEDBACK,#LEARNSASPROGRAMMINGONLINE,
#SASCLINICALONLINETRAININ,#SASELEARNING,#SASONLINETRAINING, #SASTRAINING,#CLINICALSASPROGRAMMING,#EPOCHRESEARCHINSTITUTE,
#EPOCHSASFEEDBACK,#LEARNSASPROGRAMMINGONLINE,
#SASCLINICALONLINETRAININ,#SASELEARNING,#SASONLINETRAINING, #SASTRAINING,#SASTraininginAhmedabad,#SASTraininginBangalore,
#SASTraininginChennai,#SASbusinessanalytics,#SASDatasciencetraining,
#Datamanagement,#SASDataintegrationdeveloper

No comments:

Post a Comment

How to code in Python with SAS 9.4 by Epoch Research Institute

The SAS® platform is now open to be accessed from open-source clients such as Python, Lua, Java, the R language, and REST APIs to leverage...