Date and datetime: accuracy vs storage and I/O costs (SAS)

How much storage space and I/O resources can be saved by using the LENGTH statement to shrink the storage of date and datetimes while maintaining sufficient precision? In my experience, saving I/O generally makes SAS run faster (such as in a DATA step) proportional to the I/O savings, so, for example, a 50% reduction in file size makes SAS run about 50% faster.

Data about each month (SAS)

A SAS code to generate information about each month such as the number of days in the month, week days, hours, work hours, etc. using intck and intnx function. It’s also a good example of using a DATA step to generate a data set without an input data set (i.e., no SET or MERGE statements).

Dummy coding in SAS

Here is a macro to generate binary features (also called dummy coding) from a nominal variable (also called a categorical variable, such as eye color). This is also called one-hot encoding and one-of-K encoding. The automation saves time and avoids mistakes when there are many possible values to a category or the values can change.

Easy sortable HTML tables in SAS ODS

Today Charlie Huang posted a SAS HTML table sorting demo, but without automation. Here is a fully automated implementation in SAS. The developer does not need to manually edit the HTML, and the user simply clicks any column and it sorts instantly client-side in the web browser. The feature is automatically applied to all SAS tables in the ODS HTML output.

Calculate Net Promoter Score in PROC TABULATE or SQL

This demonstrates an easy way to calculate the Net Promoter Score, a measure of customer loyalty, in SAS’s PROC TABULATE or PROC SQL. I prefer to use PROC TABULATE because of its power for various summaries. In the example we repeated the Net Promoter Score survey in two different months, and in one pass we…

Convert written numbers to Arabic numerals

In Natural Language Processing it can be helpful within a larger body of text to standardize written numbers to Arabic numerals. For example, we will change “I am forty-six years old” to “I am 46 years old,” so the age can be more easily extracted later with another regular expression. SAS makes this task particularly…