Leonid Batkhan's SAS blog

SAS blog

Publications by Leonid Batkhan at SAS Institute's Blog

Injecting foreign code into SAS programs

Embedding any code anywhere into SAS programs

Leonid Batkhan | May 30, 2023

This article introduces SAS macro function %embed( ) allowing to inject into SAS programs native DBMS SQL queries from external files. It also demonstrates how to embed other languages' code (Python, R, Lua) from external files into SAS code. Read More▸

Assigning metadata users’ groups and roles from one user to another

Automatic cloning of SAS metadata user groups and roles

Leonid Batkhan | January 11, 2023

This article demonstrates programming technique and presents a SAS macro that replicates (clones) metadata users’ groups and roles from one user to another. Read More▸

Programmatically create SAS metadata library inventory to prevent duplicate librefs

SAS administrator tip: How to identify and prevent duplicate librefs in SAS metadata

Leonid Batkhan | November 08, 2022

This SAS administration tutorial presents various SAS programming solutions on how to identify and prevent duplicate LIBREFs in SAS 9 metadata. Read More▸

Programming technique to make SAS programs adaptable to the running environment

Adaptive SAS programming for the Software Development Life Cycle

Leonid Batkhan | October 18, 2022

This article demonstrates programming technique to build adaptive SAS programs to facilitate transition between various environments for a smoother SDLC. Read More▸

SAS jobs automation using Windows batch files

Automating SAS processes using Windows batch files

Leonid Batkhan | September 20, 2022

This article introduces Windows batch files scripting language and demonstrates how to use them for conditional execution and effective job scheduling. Read More▸

Programming technique to make SAS programs adaptable to the running environment

Splitting a data table into multiple sheets of an Excel workbook

Leonid Batkhan | July 07, 2022

This article demonstrates how to programmatically split a data table into multiple Excel spreadsheets (tabs) in a single workbook. Tabs are color-coded and properly labeled. Read More▸

Using SAS for creating Excel workbooks programmatically

Automating Excel workbooks creation using SAS

Leonid Batkhan | June 16, 2022

This article demonstrates how to automate and improve a sometimes onerous hands-on process of creating Excel workbooks. Also shows how to enhance your Excel views with font and background colors as well as frozen headers. Read More▸

Calculating circle areas and sphere volumes without pi

Calculating circle areas and sphere volumes without π

Leonid Batkhan | March 14, 2022

For Pi Day, Leonid Batkhan offers a contrarian view on areas and volumes calculations proposing their pi-less formulae. The key here is what units to use for measuring areas and volumes - square and cubic units or else...Read More▸

Calculating circle areas and sphere volumes without pi

SAS open-source treasures from around the world: SASjs

Leonid Batkhan | February 16, 2022

This is an introduction to SASjs - a collection of tools aimed at enabling and accelerating development and operations (DevOps) for a broad range of SAS applications, including SAS web development. Read More▸

How to calculate number of days overlap for date intervals

Calculating the overlap of date/time intervals

Leonid Batkhan | January 13, 2022

This article describes and discusses pros and cons of 3 different algorithms and SAS code implementations to calculate length of overlap of date/time intervals and integer intervals in general. Read More▸

Trim leading and/or trailing characters from SAS strings

Introducing TRIMS function to remove any leading and/or trailing characters from SAS strings

Leonid Batkhan | October 14, 2021

This article introduces and implements multipurpose TRIMS function that removes any leading, trailing or both leading and trailing characters from SAS strings. Read More▸

Trimming trailing characters from SAS character strings

Removing trailing characters from SAS strings

Leonid Batkhan | September 02, 2021

This article describes and discusses pros and cons of 3 different algorithms and SAS code implementations to calculate length of overlap of date/time intervals and integer intervals in general. Read More▸

Trimming leading characters from SAS strings

Removing leading characters from SAS strings

Leonid Batkhan | August 23, 2021

This article demonstrates how to remove ANY leading characters (not just blanks) from text strings to tidy up your data. Two different SAS coding solutions are provided. Read More▸

Do-loops in SAS: tips and tricks

Little known secrets of DO-loops with index variables

Leonid Batkhan | July 06, 2021

This article reveals little known tips and tricks on how to use versatile iterative DO loops with index variable pertaining to SAS DATA steps. Read More▸

How to easily handle massively parallel processing in SAS using SYSTASK

Using SYSTASK and SAS macro loops for massively parallel processing

Leonid Batkhan | June 14, 2021

This article presents and elucidate SAS macro implementation of parallel processing by spawning multiple SAS sessions using SYSTASK statements with subsequent synchronization. Read More▸

How to easily handle massively parallel processing in SAS using shell scripts

Using shell scripts for massively parallel processing

Leonid Batkhan | April 14, 2021

This article explores and presents shell scripting solution as an alternative way of implementing SAS parallel processing. For the described use case, overall processing duration was cut roughly by a factor of 25... Read More▸

Uncertainty principle in SAS - April Fools Day

To be and not to be – the uncertainty principle in SAS

Leonid Batkhan | April 01, 2021

For centuries, people around the world have been busy scratching their heads in search of a meaningful answer to Shakespeare’s profoundly elementary question: "To be or not to be?" Here is how it applies to SAS... Read More▸

Using ENDSAS statement to stop SAS session

How to conditionally stop SAS code execution and gracefully terminate SAS session

Leonid Batkhan | March 24, 2021

This article reveals a fuss-free way to conditionally halt SAS program execution and terminate SAS session in batch-processing scenarios. Read More▸

Conditional execution of SAS global statements

How to conditionally execute SAS global statements

Leonid Batkhan | March 15, 2021

This article explains SAS global statements and presents several coding techniques that give you control of when and whether SAS global statements are executed. Read More▸

Removing a substring from SAS character string

Deleting a substring from a SAS string

Leonid Batkhan | February 22, 2021

This article demonstrates SAS coding techniques of deleting a substring from a character string - one of the common character data manipulation tasks. Read More▸

Inserting a substring into SAS character string

Inserting a substring into a SAS string

Leonid Batkhan | February 15, 2021

This article demonstrates SAS coding techniques of inserting a substring into a character string - one of the common character data manipulation tasks. Read More▸

SASensei online game to learn SAS

Game on! Here's a fun way to learn SAS

Leonid Batkhan | January 27, 2021

You can learn SAS and have fun at the same time. Join me at SASensei, an independent, third-party online SAS learning resource (game). Read More▸

Cutting run time by parallel processing

Running SAS programs in parallel using SAS/CONNECT®

Leonid Batkhan | January 13, 2021

The article demonstrates a popular "divide-and-conquer" efficiency strategy using parallel computation with SAS/Connect® that allows for substantial reduction in processing time. Read More▸

Deleting repeated characters from SAS character values

Removing repeated characters in SAS strings

Leonid Batkhan | November 04, 2020

The article presents and explains the data cleansing technique of removing unwanted repeated characters in SAS character variables; not just duplicate blanks, but any duplicated characters. Read More▸

Using MS Excel functions in SAS programs

Using Microsoft Excel functions in SAS

Leonid Batkhan | October 15, 2020

This post summarizes a lesser known but useful feature in SAS that allows you to bring Microsoft Excel functions into your SAS programs. Read More▸

Unquoting SAS character values

How to unquote SAS character variable values

Leonid Batkhan | September 17, 2020

The article reviews SAS functionality related to the character strings quoting/unquoting, then dives deep into unquoting SAS character variables. Read More▸

SAS CVP engine to expand character lengths

Expanding lengths of all character variables in SAS data sets

Leonid Batkhan | August 12, 2020

This article reveals how to change lengths for all character variables in a data set and all data sets in a data library to facilitate data migration to Unicode encoding environment. Read More▸

Dividing SAS data table into smaller data tables

Splitting a data set into smaller data sets

Leonid Batkhan | July 23, 2020

This article shows you how to split a large data set into many subsetting it by a number of observations to produce smaller, better manageable data sets. Read More▸

SAS functions with modifiers

Multi-purpose macro function for getting information about data sets

Leonid Batkhan | May 27, 2020

This article describes programming technique for creating multi-purpose SAS® Macro functions. One of the arguments serves as a modifier to achieve multi functionality. Read More▸

SAS macro functions

How to create and use SAS macro functions

Leonid Batkhan | April 22, 2020

This article differentiates between SAS macro and SAS programming languages, defines two types of SAS macros and explains how to create SAS macro functions. Read More▸

Automatic labeling of SAS variables

Automating SAS variable labels creation

Leonid Batkhan | March 10, 2020

This article describes how to automate creation of SAS variable labels so tables and reports are easier to read. New labels are derived from column names ... Read More▸

Navigating workday calendar in SAS programming

Shifting a date by a given number of workdays

Leonid Batkhan | January 27, 2020

This blog post demonstrates process and SAS coding techniques to shift dates by a given number of workdays accounting for weekends and holidays. Read More▸

Using checkmarks for comparing tables for common variables

How to compare SAS data tables for common/uncommon columns

Leonid Batkhan | December 09, 2019

This blog post demonstrates how to compare SAS data sets that include common and uncommon columns. You'll learn how to check mark commonalities and color-code differences in data tables. Read More▸

Using checklist tables

How to create checklist tables in SAS®

Leonid Batkhan | October 30, 2019

This article demonstrates use cases and programming techniques for creating in SAS comparison matrixes also known as checklist tables or checklist table charts. Read More▸

Using checklist tables

How to retrieve contents of a SAS® Scalable Performance Data Server library

Leonid Batkhan | September 16, 2019

This articles covers lightning-fast SAS® Scalable Performance Data Server libraries and programming technique of capturing their contents. Read More▸

Creative problem solving

Selling sand at the beach

Leonid Batkhan | August 18, 2019

Have you ever thought of selling sand on the beach? Neither have I. To most people the mere idea is preposterous. But isn’t it how all great discoveries, inventions and breakthroughs are made? Someone comes up with an outwardly crazy idea and ... Read More▸

Handling commas within values of macro parameters

Passing comma-delimited values into SAS macros and macro functions

Leonid Batkhan | July 17, 2019

Have you ever tried to pass comma-delimited values to SAS macro or to a SAS macro function? How can SAS distinguish commas separating parameters or arguments from commas separating parts of the values? Read More▸

Search for n-th instance of a substring withing SAS character string

Finding n-th instance of a substring within a string

Leonid Batkhan | June 26, 2019

This article solves a problem of parsing a character string to find a position of n-th occurrence of a group of characters (substring) in that string. Read More▸

Dividing by zero in SAS

Dividing by zero with SAS - myths and realities

Leonid Batkhan | May 08, 2019

This article dispels all the fallacies and delusions about division by zero in a SAS DATA step. Are you familiar with the divide() function in SAS? Read More▸

Dividing by zero in SAS - April Fools Day

Dividing by zero with SAS

Leonid Batkhan | April 01, 2019

Whether you are a strong believer in the power of dividing by zero, agnostic, undecided, a supporter, denier or anything in between and beyond, this blog post will bring all to a common denominator. Read More▸

Stop Unix/Linux script processing and exit

How to conditionally terminate a SAS batch flow process in UNIX/Linux

Leonid Batkhan | March 05, 2019

This article describes how to conditionally stop and exit SAS batch script running several SAS programs in Unix/Linux environments. This is especially useful when such jobs run on schedule unattended. Read More▸

Splitting text file or data table into many text files

How to split a raw file or a data set into many external raw files

Leonid Batkhan | February 06, 2019

This article describes SAS programming technique for splitting raw text file or a data table into many raw text files. Read More▸

Using SAS data templates

Simplify data preparation using SAS data templates

Leonid Batkhan | January 09, 2019

This article describes a data preparation approach and SAS coding technique that will significantly simplify, unclutter and streamline your SAS programming life by using data templates. Read More▸

Automatically deleting older files

SAS administrators tip: Automatically deleting old SAS logs

Leonid Batkhan | July 17, 2018

This article presents a SAS program (macro %mr_clean) that cleans up old log files on your system from a specified directory. And not only log file, but any files that are no longer needed. Read More▸

Look in a rear view mirror for foolproof solutions

Are you developing foolproof solutions?

Leonid Batkhan | May 30, 2018

It is imperative for developers, whether hardware or software engineers, to foresee unintended (probable or improbable) system usages and implement features that will make their creations foolproof, that is protected from misuse. Read More▸

Suppressing small numbers for protecting personal privacy in SAS reports

SAS tools for GDPR privacy compliant reporting

Leonid Batkhan | May 07, 2018

This article features four SAS tools for GDPR compliance which allow protecting personal data in SAS reports by suppressing counts in small demographic group reports. Read More▸

Stars and planets - April Fools Day

SAS discovers a new planet in the Solar System

Leonid Batkhan | April 01, 2018

Inspired by curiosity and backed by the most powerful analytics in the world, SAS discovers a new planet in our Solar system. See how we used SAS Viya to make this historic discovery. Read More▸

Automatcally writing batch scripts using SAS

Let SAS write batch scripts for you

Leonid Batkhan | January 25, 2018

If Necessity is the mother of Invention, then, perhaps, the father of Automation is Laziness. Automation is all about convenience, comfort, and productivity. Why do it yourself if you can devise something to do it for you! Read More▸

Running SAS programs in batch mode

Running SAS programs in batch under Unix/Linux

Leonid Batkhan | December 19, 2017

While SAS program development is usually done in an interactive SAS environment, when it comes to running SAS programs in a production or operations environment it is routinely done in batch mode. Read More▸

Calculations across SAS dataset observations

Hopping for the best - calculations across SAS dataset observations

Leonid Batkhan | November 01, 2017

This blog post demonstrates a SAS coding technique that allows for calculations with multiple variables from different observations across a SAS dataset. Read More▸

Applying styles in Enterprise Guide

Creating reports in style with SAS Enterprise Guide

Leonid Batkhan | October 10, 2017

This blog post describes a wealth of styling options available in SAS Enterprise Guide. It also covers CSS styles and server-side styles as they apply to SAS EG. Read More▸

Web browser as a code editor

Using a web browser as a SAS code editor

Leonid Batkhan | September 15, 2017

This blog post describes how to use regular web browser as an editing software. That is right, you can write your code, articles, papers, etc. in a web browser. Read More▸

CALL EXECUTE in SAS

CALL EXECUTE made easy for SAS data-driven programming

Leonid Batkhan | August 02, 2017

CALL EXECUTE is a powerful tool for developing dynamic data-driven SAS applications. This blog post demonstrates its benefits and clearly explains how to avoid its pitfalls and use it efficiently to your advantage. Read More▸

Problem solving by combining rather than dividing

Combine and conquer with SAS

Leonid Batkhan | June 06, 2017

In this blog post, author reverses the ancient political maxim "divide and conquer" and demonstrates how you can utilize the backwards principle "combine and then conquer" for problem solving. Read More▸

ETL automation

Automating the loading of multiple database tables into SAS tables

Leonid Batkhan | April 27, 2017

This article presents various ETL implementations and data-driven programming techniques for automating multiple database tables load into SAS tables. Read More▸

Encoding passwords in SAS programs

One deadly sin SAS programmers should stop committing

Leonid Batkhan | April 13, 2017

This article demonstrates how you should protect passwords in SAS programs. Even if you are a traditional SAS programmer and have nothing to do with cybersecurity, you still probably have to deal with this issue in your day-to-day work. Read More▸

to Proving Fermat's Last Theorem with SAS - April Fools' Day

SAS code to prove Fermat's Last Theorem

Leonid Batkhan | April 01, 2017

In this special occasion blog post author presents a creative and powerful SAS code that effectively proves the long-standing Fermat's Last theorem. Read More▸

Modifying variable attributes in SAS datasets

Changing variable type and variable length in SAS datasets

Leonid Batkhan | March 28, 2017

This article demonstrates how you can change SAS dataset's variable type and/or variable length in place, without adding new variables. If you believe it can’t be done, read this article from very beginning. Read More▸

Truncating and rounding SAS time values

Truncating vs rounding SAS time values

Leonid Batkhan | February 10, 2017

While truncation vs rounding may seem to be insignificant in a given instance, the cumulative effect of either could be truly enormous when it comes to time values. Read More▸

Truncating decimal numbers without rounding in SAS

Truncating decimal numbers in SAS without rounding

Leonid Batkhan | December 15, 2016

This article demonstrates how to truncate displayed numeric values to a specified number of decimal places without rounding. It's a bit trickier than it seems. Read More▸

How to modify variable attributes in all datasets of a SAS library

Modifying variable attributes in all datasets of a SAS library

Leonid Batkhan | November 25, 2016

Variable attributes update process can be fully automated and consistently applied to all datasets in a SAS library using described here approach. Read More▸

Purpose-driven vs problem-driven solutions

Are you solving the wrong problem?

Leonid Batkhan | May 23, 2016

In this article author illustrates why and how you should first articulate and define purpose before jumping to formulating and solving a problem. Read More▸

Suppressing data to protect privacy in published reports

Automatic data suppression in SAS reports

Leonid Batkhan | April 13, 2016

Have you ever used SAS to produce reports for publishing? Have you ever thought of or been told about suppressing data in such reports? Why do we need to suppress (in the sense of withholding, concealing, obscuring or hiding) data in published reports? Read More▸

Data-driven SAS macro loops

Data-driven SAS macro loops

Leonid Batkhan | March 04, 2016

Contrary to the data step DO-loops which iterate during execution time, SAS macro loops are completely different creatures as they do not iterate during execution time, but rather during code compilation time. Read More▸

Data-driven programming loops

Introducing data-driven loops

Leonid Batkhan | February 04, 2016

Programming loops are a staple of any computer programming language. In all programming loops, a group of statements is executed repeatedly based on the value of an index variable that changes from one iteration to another. Read More▸

Administering SAS metadata users

SAS administrators tip: Keeping track of SAS users

Leonid Batkhan | January 13, 2016

If you are a SAS Admin who adds and removes SAS users in the SAS Management Console, assigns them to Groups and Roles, maintains their General information and user Accounts, then you know that when number of users grow, at some point things can get messy. Read More▸

Using PROC GEOCODE in SAS

SAS to the rescue: claiming your location on Google map by address only (without knowing latitude and longitude)

Leonid Batkhan | November 03, 2015

This article demonstrates SAS' PROC GEOCODE usage for getting latitudes and longitudes of a location specified only by its postal address. Then this location is easily tagged with a marker on Google maps. Read More▸

Showing SAS-generated reports on Google maps

Integrating SAS reports with Google maps: two-pane solution

Leonid Batkhan | July 16, 2015

This article demonstrates an interactive two-pane solution combining Google map and SAS-generated report (graphics, tabular, etc.) showing pertinent information based on the interaction with the Google map. Read More▸

Overlaying SAS-generated reports on Google maps

SAS ODS destination - Google maps

Leonid Batkhan | June 05, 2015

This article demonstrates SAS programming technique of building interactive Google map overlaying a pop-up window (InfoWindow) with SAS-generated ODS HTML report pertinent to the location clicked on the Google map. Read More▸

Reversing graph axes in SAS Visual Analytics

How to reverse graph axes in SAS Visual Analytics

Leonid Batkhan | March 20, 2015

There are real-life cases when reversing graph axes make sense. For example, when Y-axis represents a depth under the sea level or depth of oil well drilling, it makes perfect sense to have zero on top and positive numbers increasing from top down. Read More▸

SAS timer to measure program processing duration

SAS timer - the key to writing efficient SAS code

Leonid Batkhan | January 21, 2015

This post presents a simple programming tool that allows you to measure duration of your SAS program. It can be easily embedded in your SAS code and is very useful for programs efficiency benchmarking. Read More▸

SAS program to build drillable Google map

Drill, baby, drill—using SAS to drill down through Google maps

Leonid Batkhan | November 28, 2014

This article demonstrates a SAS program that builds drillable Google maps. When you click on a region, you will be effectively drilling down on that region and will be presented with a second level of the Google map. Read More▸

SAS code to draw draggable circles on Google maps

Circling Google maps with SAS

Leonid Batkhan | October 13, 2014

This article demonstrates a SAS program that builds interactive Google maps allowing to draw (overlay) draggable circles of adjustable sizes over it. Read More▸

SAS code to create interactive InfoWindows on Google maps

The power of SAS-generated InfoWindows in Google maps

Leonid Batkhan | September 12, 2014

This article demonstrates a SAS program that builds live Google maps allowing to overlay interactive InfoWindows capable of displaying all sorts of information, including YouTube videos, graphs, tables, etc. Read More▸

SAS program to draw polygon overlays on Google maps

Drawing overlays on SAS-generated Google maps

Leonid Batkhan | August 29, 2014

This article demonstrates a SAS programming technique to draw a closed geometric shape, in particular, a polygon, on a Google map. Overlaying polygons on a Google map is a great visualization for geographical and administrative regions ... Read More▸

SAS program to generate Google maps with multiple markers

Live Google maps in SAS — multiple markers

Leonid Batkhan | July 24, 2014

This blog post demonstrates how to use SAS programming to generate interactive Google map with multiple points (or markers, using Google terminology) and incorporate it into SAS HTML output. Read More▸

SAS BI environment setup best practices

Setting up SAS Business Intelligence environments – the right way

Leonid Batkhan | July 09, 2014

This article presents the best practices for setting up SAS Business Intelligence (SAS BI) environments. It covers folder structures for software life cycle environments; explains the difference between SAS metadata folders and OS folders, and more ... Read More▸

Embedding Google Maps into SAS-generated HTML output

Spice up SAS output with live Google maps

Leonid Batkhan | June 06, 2014

This article introduces Google Maps API and illustrates embedding them into any SAS-generated HTML output, in particular embedding Google maps into a SAS stored process and delivering it via a SAS Information Delivery Portal. Read More▸

Using autoexec files with SAS Enterprise Guide

Autoexecs — the SAS Enterprise Guide advantage

Leonid Batkhan | May 01, 2014

Autoexec files are very convenient and powerful productivity feature of SAS Enterprise Guide. This article demonstrates various usages of autoexec with EG. Read More▸