SlideShare a Scribd company logo
1 of 30
Hey !! Do You Know Proc LUA?
ConSPIC 2018
1
By :– Dr.Sangram K. Parbhane
The opinions in this presentation are those of the presenter and
may not necessarily reflect the views of Quartesian, ConSPIC.
ConSPIC 2018
Disclaimer
2
ConSPIC 2018 3
Have you played this game?.........
ConSPIC 2018
4
Then this game ?...
Introduction to Proc Lua
Understanding Basics of Lua Programming
How Proc Lua differs over SAS Macros
Limitations and Final Thoughts
Conclusion
ConSPIC 2018
Contents
5
What is Lua ?
It's an embeddable scripting language that is often used as a way to add
user extensions to robust software applications.
Created by Roberto Lerusalimschy in Brazil
ConSPIC 2018
Pronounced LOO-ah means "Moon" in Portuguese
The Lua 5.2 run-time environment is embedded within SAS
Popular choice in game development
Open-source software
6
6
Why LUA ?..
 The need for an alternate to the SAS Macro Language was first felt
by various solutions group within SAS.
 It was therefore felt that there was a strong need for a modern
scripting language in addition to the SAS platform. Since the
purpose of Lua is to script C-based software and because SAS is
written in C, Lua was a great fit for SAS.
 Lua provides for Eclipse plug-ins and provides more detailed
debugging information.
7ConSPIC 2018
How to run Lua In SAS ?...
 PROC LUA runs the Lua virtual machine inside the SAS process to offer seamless
integration of Lua with SAS.
 Can execute Lua code by embedding it within a SUBMIT/ENDSUBMIT block in the
PROC LUA invocation
Code Output
 The preceding program, prints the 'Hello from Lua!' message to the SAS log. PROC
LUA routes output from Lua’s print function to the SAS log
8ConSPIC 2018
Value types in Lua
9ConSPIC 2018
Lua Basics
 In Lua, you usually declare a variable by using a local statement.
local pi = 3.14 -- Declare a numeric variable
local guest = "Veronica“ -- Declare a string variable
 Using the local keyword is recommended because omitting it results in the
variable being declared to be global in scope.
 The preceding program, prints the 'Hello from Lua!' message to the SAS log.
PROC LUA routes output from Lua’s print function to the SAS log
10ConSPIC 2018
Reading & Writing SAS datasets
 To read values from a SAS data set, you use the sas.open function,
which returns a handle that provides functions to read
observations, retrieve values of data set variables, and release the
handle.
If you forget to call sas.close()
after using the data set, you
will see a warning like the
following printed to SAS log
when the data set handle goes
out of scope:
11ConSPIC 2018
Defining new SAS dataset from scratch in Lua
 The sas.new_table function enables you to define a new (empty)
data set. You provide the name of the new data set, and you
provide a Lua table that is set up as an array of Lua tables, each of
which contains the attributes of one data set variable. For example,
the following code creates a new SAS data set called Work.Status
that contains three variables, node, status, and datetime:
.
12ConSPIC 2018
Calling SAS functions from Lua
 When PROC LUA initializes the Lua state, it creates a special
global Lua table called sas. This table is always available to your
Lua programs.
 To Use SAS functions just add prefix sas. to their function names
The MIN function in SAS becomes sas.min in Lua,
The TRIM function in SAS becomes sas.trim in Lua,
 Function arguments are declared within the set of parentheses that
precedes the function body, and they are positional only.
13ConSPIC 2018
Calling FCMP Functions
 We can also call functions that are created by the FCMP procedure. To use FCMP
functions from Lua, simply define them as you normally would by using PROC
FCMP, and then set the CMPLIB= system option.
14ConSPIC 2018
Difference between SAS Macros & LUA
 USE OF SEMICOLON - The Lua syntax does not mandate that
every valid statement end with a semicolon.
 In contrast, the SAS Macro Language follows the SAS
statement syntax in the sense that every valid statement must
end with a semicolon.
 A long-time Lua user might be in the habit of forgetting to do
so, which might lead to additional efforts in debugging later.
15ConSPIC 2018
Error Reporting
 Lua syntax errors are reported with the line number where error has encountered
 Errors that are reported by the SAS macro processor
 So when debug your programs for large programs that involves thousands of lines of
code..The result of macro expansion is a set of SAS statements that might not
correspond, line-by-line, to the statements in your original source file. Thus, when errors
that are reported in the SAS log refer to line numbers, those line numbers are often not
useful to you. On the other hand, Lua reports back line numbers that you can relate to the
lines in your source file—so you can quickly locate the problem area and address the
issue.
16ConSPIC 2018
Syntax Highlighting
 Text editors and IDEs such as Eclipse recognize Lua syntax and support syntax error
highlighting.
17ConSPIC 2018
Arithmetic
 In the SAS macro language, it requires to use the %EVAL macro to indicate where a text
expression should be interpreted numerically.
 In Lua numeric data types are supported directly.
 To increment a counter variable in the SAS macro language, you need to write the
following:
In SAS Macros
In Proc Lua
18ConSPIC 2018
SAS options Management
 SAS options are global. It’s designed in this way for good purpose. But
sometimes you just want to evoke a SAS option but are too lazy to close it at
the end. Proc Lua is good to have in this case.
 The trick is the options inside the SAS.SUBMIT blocks are pretty local; it will
not be inherited by the outside programs.
19ConSPIC 2018
Macro Alternatives (Wrapper programs)
 Lets take us the example of wrapper programs :to check if a dataset exists
By Data Step by using SAS external file functions like fexist:

20ConSPIC 2018
Macro Alternatives (Wrapper programs)
 Same syntax can be written in Proc Lua with more elegant way and aesthetically preferable
and also is easy to debug

21ConSPIC 2018
Which External files SAS doesn’t support?
 SAS has access to wide range of external files, but lacks support to JSON(used in
internet exchange) or HDF5 file formats but Proc Lua includes packages to read
JSON, HDF5 and other data formats.
22ConSPIC 2018
When SAS Macro Language is Better Choice?
 Case Insensitivity - Both uppercase and lowercase keywords can be used
alternatingly in Macros while uppercasing will produce an error in Proc Lua.
23ConSPIC 2018
When SAS Macro Language is Better Choice? Continued…
Lua is not integrated with the SAS tokenizer. Therefore, Lua code cannot
be used in open code and neither can it be used interchangeably with SAS
code.
24
 Integration with SAS tokenizer
 Familiarity with SAS Macros – Programmers have become
comfortable coding with the Macro Language but the same cannot
be said for Lua, which is in itself a big drawback.
ConSPIC 2018
Limitations of Proc Lua
Doesn’t port any
External libraries
can only import
external libraries
written by pure Lua
Currently only
supports Lua 5.1
Doesn’t
support Lua IO
module &
Multithreading
25ConSPIC 2018
Final Thoughts
 SAS is not “A” programming language,
It’s a collection of multiple programming languages, which includes
Data Step, DS2, Macro, SQL, IML, Groovy and such.
 Proc Lua offers a totally different programming style and flavor
like a data structure, for loop, external packages support
and other modern scripting language features.
I believe taking even a little bite of Lua can make a more versatile SAS
programmer.
26ConSPIC 2018
Conclusion
 The LUA procedure offers a new approach to writing SAS
code by enabling you to use Lua to orchestrate your PROC and
DATA steps.
 This difference is especially noticeable when you work with
larger and more complex programs that can be very difficult
to implement using only the SAS macro language for the control
logic.
 The fact that PROC LUA and the SAS macro language can work
together lets you decide how much of one approach versus the
other to adopt.
27ConSPIC 2018
References
 https://support.sas.com/resources/papers/proceedings15/SAS1
561-2015.pdf
 https://support.sas.com/resources/papers/proceedings17/SAS0
212-2017.pdf
 https://analytics.ncsu.edu/sesug/2016/AD-133_Final_PDF.pdf
 Ierusalimschy, R. (2013). Programming in Lua. 3rd ed. Rio de
Janeiro: Lua.org. Lua.org (2013). “The Programming Language
Lua.” http://www.lua.org.
28ConSPIC 2018
Reach out to me @
Dr.Sangram K. Parbhane
Statistical Programmer II
Email: inamdar.raje@gmail.com
Q & A
29ConSPIC 2018
Thank You !!
30ConSPIC 2018

More Related Content

Similar to Hey do you know Proc Lua ??

XAJA - Reverse AJAX framework
XAJA - Reverse AJAX frameworkXAJA - Reverse AJAX framework
XAJA - Reverse AJAX framework
Sri Prasanna
 

Similar to Hey do you know Proc Lua ?? (20)

Learning spark ch06 - Advanced Spark Programming
Learning spark ch06 - Advanced Spark ProgrammingLearning spark ch06 - Advanced Spark Programming
Learning spark ch06 - Advanced Spark Programming
 
Migrating to spark 2.0
Migrating to spark 2.0Migrating to spark 2.0
Migrating to spark 2.0
 
From SOA to SCA and FraSCAti
From SOA to SCA and FraSCAtiFrom SOA to SCA and FraSCAti
From SOA to SCA and FraSCAti
 
ASPgems - kappa architecture
ASPgems - kappa architectureASPgems - kappa architecture
ASPgems - kappa architecture
 
Programmability in spss 14
Programmability in spss 14Programmability in spss 14
Programmability in spss 14
 
Flink Forward Berlin 2017: Piotr Wawrzyniak - Extending Apache Flink stream p...
Flink Forward Berlin 2017: Piotr Wawrzyniak - Extending Apache Flink stream p...Flink Forward Berlin 2017: Piotr Wawrzyniak - Extending Apache Flink stream p...
Flink Forward Berlin 2017: Piotr Wawrzyniak - Extending Apache Flink stream p...
 
Preparing for Scala 3
Preparing for Scala 3Preparing for Scala 3
Preparing for Scala 3
 
Ldap sync with sap(rfc)
Ldap sync with sap(rfc)Ldap sync with sap(rfc)
Ldap sync with sap(rfc)
 
Apache Cassandra and Apche Spark
Apache Cassandra and Apche SparkApache Cassandra and Apche Spark
Apache Cassandra and Apche Spark
 
XAJA - Reverse AJAX framework
XAJA - Reverse AJAX frameworkXAJA - Reverse AJAX framework
XAJA - Reverse AJAX framework
 
C++ book
C++ bookC++ book
C++ book
 
Programmability in spss 15
Programmability in spss 15Programmability in spss 15
Programmability in spss 15
 
Why spark by Stratio - v.1.0
Why spark by Stratio - v.1.0Why spark by Stratio - v.1.0
Why spark by Stratio - v.1.0
 
Unit 4 lecture2
Unit 4 lecture2Unit 4 lecture2
Unit 4 lecture2
 
[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?
[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?
[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?
 
Trivadis TechEvent 2016 Introduction to Lagom - another microservice-based fr...
Trivadis TechEvent 2016 Introduction to Lagom - another microservice-based fr...Trivadis TechEvent 2016 Introduction to Lagom - another microservice-based fr...
Trivadis TechEvent 2016 Introduction to Lagom - another microservice-based fr...
 
What's wrong with web
What's wrong with webWhat's wrong with web
What's wrong with web
 
Present and future of unified, portable, and efficient data processing with A...
Present and future of unified, portable, and efficient data processing with A...Present and future of unified, portable, and efficient data processing with A...
Present and future of unified, portable, and efficient data processing with A...
 
Sap to php
Sap to phpSap to php
Sap to php
 
Sparkr sigmod
Sparkr sigmodSparkr sigmod
Sparkr sigmod
 

Recently uploaded

Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
gajnagarg
 
一比一原版(UCD毕业证书)加州大学戴维斯分校毕业证成绩单原件一模一样
一比一原版(UCD毕业证书)加州大学戴维斯分校毕业证成绩单原件一模一样一比一原版(UCD毕业证书)加州大学戴维斯分校毕业证成绩单原件一模一样
一比一原版(UCD毕业证书)加州大学戴维斯分校毕业证成绩单原件一模一样
wsppdmt
 
Cytotec in Jeddah+966572737505) get unwanted pregnancy kit Riyadh
Cytotec in Jeddah+966572737505) get unwanted pregnancy kit RiyadhCytotec in Jeddah+966572737505) get unwanted pregnancy kit Riyadh
Cytotec in Jeddah+966572737505) get unwanted pregnancy kit Riyadh
Abortion pills in Riyadh +966572737505 get cytotec
 
怎样办理伦敦大学城市学院毕业证(CITY毕业证书)成绩单学校原版复制
怎样办理伦敦大学城市学院毕业证(CITY毕业证书)成绩单学校原版复制怎样办理伦敦大学城市学院毕业证(CITY毕业证书)成绩单学校原版复制
怎样办理伦敦大学城市学院毕业证(CITY毕业证书)成绩单学校原版复制
vexqp
 
Gartner's Data Analytics Maturity Model.pptx
Gartner's Data Analytics Maturity Model.pptxGartner's Data Analytics Maturity Model.pptx
Gartner's Data Analytics Maturity Model.pptx
chadhar227
 
Lecture_2_Deep_Learning_Overview-newone1
Lecture_2_Deep_Learning_Overview-newone1Lecture_2_Deep_Learning_Overview-newone1
Lecture_2_Deep_Learning_Overview-newone1
ranjankumarbehera14
 
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
gajnagarg
 
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
nirzagarg
 
怎样办理旧金山城市学院毕业证(CCSF毕业证书)成绩单学校原版复制
怎样办理旧金山城市学院毕业证(CCSF毕业证书)成绩单学校原版复制怎样办理旧金山城市学院毕业证(CCSF毕业证书)成绩单学校原版复制
怎样办理旧金山城市学院毕业证(CCSF毕业证书)成绩单学校原版复制
vexqp
 
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
nirzagarg
 
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get CytotecAbortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Riyadh +966572737505 get cytotec
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Recently uploaded (20)

Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
 
SR-101-01012024-EN.docx Federal Constitution of the Swiss Confederation
SR-101-01012024-EN.docx  Federal Constitution  of the Swiss ConfederationSR-101-01012024-EN.docx  Federal Constitution  of the Swiss Confederation
SR-101-01012024-EN.docx Federal Constitution of the Swiss Confederation
 
一比一原版(UCD毕业证书)加州大学戴维斯分校毕业证成绩单原件一模一样
一比一原版(UCD毕业证书)加州大学戴维斯分校毕业证成绩单原件一模一样一比一原版(UCD毕业证书)加州大学戴维斯分校毕业证成绩单原件一模一样
一比一原版(UCD毕业证书)加州大学戴维斯分校毕业证成绩单原件一模一样
 
7. Epi of Chronic respiratory diseases.ppt
7. Epi of Chronic respiratory diseases.ppt7. Epi of Chronic respiratory diseases.ppt
7. Epi of Chronic respiratory diseases.ppt
 
Cytotec in Jeddah+966572737505) get unwanted pregnancy kit Riyadh
Cytotec in Jeddah+966572737505) get unwanted pregnancy kit RiyadhCytotec in Jeddah+966572737505) get unwanted pregnancy kit Riyadh
Cytotec in Jeddah+966572737505) get unwanted pregnancy kit Riyadh
 
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
 
Capstone in Interprofessional Informatic // IMPACT OF COVID 19 ON EDUCATION
Capstone in Interprofessional Informatic  // IMPACT OF COVID 19 ON EDUCATIONCapstone in Interprofessional Informatic  // IMPACT OF COVID 19 ON EDUCATION
Capstone in Interprofessional Informatic // IMPACT OF COVID 19 ON EDUCATION
 
Digital Transformation Playbook by Graham Ware
Digital Transformation Playbook by Graham WareDigital Transformation Playbook by Graham Ware
Digital Transformation Playbook by Graham Ware
 
怎样办理伦敦大学城市学院毕业证(CITY毕业证书)成绩单学校原版复制
怎样办理伦敦大学城市学院毕业证(CITY毕业证书)成绩单学校原版复制怎样办理伦敦大学城市学院毕业证(CITY毕业证书)成绩单学校原版复制
怎样办理伦敦大学城市学院毕业证(CITY毕业证书)成绩单学校原版复制
 
Gartner's Data Analytics Maturity Model.pptx
Gartner's Data Analytics Maturity Model.pptxGartner's Data Analytics Maturity Model.pptx
Gartner's Data Analytics Maturity Model.pptx
 
Lecture_2_Deep_Learning_Overview-newone1
Lecture_2_Deep_Learning_Overview-newone1Lecture_2_Deep_Learning_Overview-newone1
Lecture_2_Deep_Learning_Overview-newone1
 
Data Analyst Tasks to do the internship.pdf
Data Analyst Tasks to do the internship.pdfData Analyst Tasks to do the internship.pdf
Data Analyst Tasks to do the internship.pdf
 
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
 
Predicting HDB Resale Prices - Conducting Linear Regression Analysis With Orange
Predicting HDB Resale Prices - Conducting Linear Regression Analysis With OrangePredicting HDB Resale Prices - Conducting Linear Regression Analysis With Orange
Predicting HDB Resale Prices - Conducting Linear Regression Analysis With Orange
 
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
 
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book nowVadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
 
怎样办理旧金山城市学院毕业证(CCSF毕业证书)成绩单学校原版复制
怎样办理旧金山城市学院毕业证(CCSF毕业证书)成绩单学校原版复制怎样办理旧金山城市学院毕业证(CCSF毕业证书)成绩单学校原版复制
怎样办理旧金山城市学院毕业证(CCSF毕业证书)成绩单学校原版复制
 
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
 
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get CytotecAbortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get Cytotec
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 

Hey do you know Proc Lua ??

  • 1. Hey !! Do You Know Proc LUA? ConSPIC 2018 1 By :– Dr.Sangram K. Parbhane
  • 2. The opinions in this presentation are those of the presenter and may not necessarily reflect the views of Quartesian, ConSPIC. ConSPIC 2018 Disclaimer 2
  • 3. ConSPIC 2018 3 Have you played this game?.........
  • 5. Introduction to Proc Lua Understanding Basics of Lua Programming How Proc Lua differs over SAS Macros Limitations and Final Thoughts Conclusion ConSPIC 2018 Contents 5
  • 6. What is Lua ? It's an embeddable scripting language that is often used as a way to add user extensions to robust software applications. Created by Roberto Lerusalimschy in Brazil ConSPIC 2018 Pronounced LOO-ah means "Moon" in Portuguese The Lua 5.2 run-time environment is embedded within SAS Popular choice in game development Open-source software 6 6
  • 7. Why LUA ?..  The need for an alternate to the SAS Macro Language was first felt by various solutions group within SAS.  It was therefore felt that there was a strong need for a modern scripting language in addition to the SAS platform. Since the purpose of Lua is to script C-based software and because SAS is written in C, Lua was a great fit for SAS.  Lua provides for Eclipse plug-ins and provides more detailed debugging information. 7ConSPIC 2018
  • 8. How to run Lua In SAS ?...  PROC LUA runs the Lua virtual machine inside the SAS process to offer seamless integration of Lua with SAS.  Can execute Lua code by embedding it within a SUBMIT/ENDSUBMIT block in the PROC LUA invocation Code Output  The preceding program, prints the 'Hello from Lua!' message to the SAS log. PROC LUA routes output from Lua’s print function to the SAS log 8ConSPIC 2018
  • 9. Value types in Lua 9ConSPIC 2018
  • 10. Lua Basics  In Lua, you usually declare a variable by using a local statement. local pi = 3.14 -- Declare a numeric variable local guest = "Veronica“ -- Declare a string variable  Using the local keyword is recommended because omitting it results in the variable being declared to be global in scope.  The preceding program, prints the 'Hello from Lua!' message to the SAS log. PROC LUA routes output from Lua’s print function to the SAS log 10ConSPIC 2018
  • 11. Reading & Writing SAS datasets  To read values from a SAS data set, you use the sas.open function, which returns a handle that provides functions to read observations, retrieve values of data set variables, and release the handle. If you forget to call sas.close() after using the data set, you will see a warning like the following printed to SAS log when the data set handle goes out of scope: 11ConSPIC 2018
  • 12. Defining new SAS dataset from scratch in Lua  The sas.new_table function enables you to define a new (empty) data set. You provide the name of the new data set, and you provide a Lua table that is set up as an array of Lua tables, each of which contains the attributes of one data set variable. For example, the following code creates a new SAS data set called Work.Status that contains three variables, node, status, and datetime: . 12ConSPIC 2018
  • 13. Calling SAS functions from Lua  When PROC LUA initializes the Lua state, it creates a special global Lua table called sas. This table is always available to your Lua programs.  To Use SAS functions just add prefix sas. to their function names The MIN function in SAS becomes sas.min in Lua, The TRIM function in SAS becomes sas.trim in Lua,  Function arguments are declared within the set of parentheses that precedes the function body, and they are positional only. 13ConSPIC 2018
  • 14. Calling FCMP Functions  We can also call functions that are created by the FCMP procedure. To use FCMP functions from Lua, simply define them as you normally would by using PROC FCMP, and then set the CMPLIB= system option. 14ConSPIC 2018
  • 15. Difference between SAS Macros & LUA  USE OF SEMICOLON - The Lua syntax does not mandate that every valid statement end with a semicolon.  In contrast, the SAS Macro Language follows the SAS statement syntax in the sense that every valid statement must end with a semicolon.  A long-time Lua user might be in the habit of forgetting to do so, which might lead to additional efforts in debugging later. 15ConSPIC 2018
  • 16. Error Reporting  Lua syntax errors are reported with the line number where error has encountered  Errors that are reported by the SAS macro processor  So when debug your programs for large programs that involves thousands of lines of code..The result of macro expansion is a set of SAS statements that might not correspond, line-by-line, to the statements in your original source file. Thus, when errors that are reported in the SAS log refer to line numbers, those line numbers are often not useful to you. On the other hand, Lua reports back line numbers that you can relate to the lines in your source file—so you can quickly locate the problem area and address the issue. 16ConSPIC 2018
  • 17. Syntax Highlighting  Text editors and IDEs such as Eclipse recognize Lua syntax and support syntax error highlighting. 17ConSPIC 2018
  • 18. Arithmetic  In the SAS macro language, it requires to use the %EVAL macro to indicate where a text expression should be interpreted numerically.  In Lua numeric data types are supported directly.  To increment a counter variable in the SAS macro language, you need to write the following: In SAS Macros In Proc Lua 18ConSPIC 2018
  • 19. SAS options Management  SAS options are global. It’s designed in this way for good purpose. But sometimes you just want to evoke a SAS option but are too lazy to close it at the end. Proc Lua is good to have in this case.  The trick is the options inside the SAS.SUBMIT blocks are pretty local; it will not be inherited by the outside programs. 19ConSPIC 2018
  • 20. Macro Alternatives (Wrapper programs)  Lets take us the example of wrapper programs :to check if a dataset exists By Data Step by using SAS external file functions like fexist:  20ConSPIC 2018
  • 21. Macro Alternatives (Wrapper programs)  Same syntax can be written in Proc Lua with more elegant way and aesthetically preferable and also is easy to debug  21ConSPIC 2018
  • 22. Which External files SAS doesn’t support?  SAS has access to wide range of external files, but lacks support to JSON(used in internet exchange) or HDF5 file formats but Proc Lua includes packages to read JSON, HDF5 and other data formats. 22ConSPIC 2018
  • 23. When SAS Macro Language is Better Choice?  Case Insensitivity - Both uppercase and lowercase keywords can be used alternatingly in Macros while uppercasing will produce an error in Proc Lua. 23ConSPIC 2018
  • 24. When SAS Macro Language is Better Choice? Continued… Lua is not integrated with the SAS tokenizer. Therefore, Lua code cannot be used in open code and neither can it be used interchangeably with SAS code. 24  Integration with SAS tokenizer  Familiarity with SAS Macros – Programmers have become comfortable coding with the Macro Language but the same cannot be said for Lua, which is in itself a big drawback. ConSPIC 2018
  • 25. Limitations of Proc Lua Doesn’t port any External libraries can only import external libraries written by pure Lua Currently only supports Lua 5.1 Doesn’t support Lua IO module & Multithreading 25ConSPIC 2018
  • 26. Final Thoughts  SAS is not “A” programming language, It’s a collection of multiple programming languages, which includes Data Step, DS2, Macro, SQL, IML, Groovy and such.  Proc Lua offers a totally different programming style and flavor like a data structure, for loop, external packages support and other modern scripting language features. I believe taking even a little bite of Lua can make a more versatile SAS programmer. 26ConSPIC 2018
  • 27. Conclusion  The LUA procedure offers a new approach to writing SAS code by enabling you to use Lua to orchestrate your PROC and DATA steps.  This difference is especially noticeable when you work with larger and more complex programs that can be very difficult to implement using only the SAS macro language for the control logic.  The fact that PROC LUA and the SAS macro language can work together lets you decide how much of one approach versus the other to adopt. 27ConSPIC 2018
  • 28. References  https://support.sas.com/resources/papers/proceedings15/SAS1 561-2015.pdf  https://support.sas.com/resources/papers/proceedings17/SAS0 212-2017.pdf  https://analytics.ncsu.edu/sesug/2016/AD-133_Final_PDF.pdf  Ierusalimschy, R. (2013). Programming in Lua. 3rd ed. Rio de Janeiro: Lua.org. Lua.org (2013). “The Programming Language Lua.” http://www.lua.org. 28ConSPIC 2018
  • 29. Reach out to me @ Dr.Sangram K. Parbhane Statistical Programmer II Email: inamdar.raje@gmail.com Q & A 29ConSPIC 2018

Editor's Notes

  1. This is sangram