Tag: code

Calculate Net Promoter Score in PROC TABULATE

This demonstrates an easy way to calculate the Net Promoter Score, a measure of customer loyalty, in SAS’s PROC TABULATE. I prefer to use PROC TABULATE because of its power for various summaries. In the example we repeated the Net … Continu…

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 … C…

Checking return codes for errors in SAS

You should check for error return codes in any SAS programs that run unattended in batch jobs, so you can handle the exception properly. For example, if the data are invalid, you don’t want to generate reports or insert bad data into a database. …

Train neural network in R, predict in SAS

This R code fits an artificial neural network in R and generates Base SAS code, so new records can be scored entirely in Base SAS. This is intended to be a simple, elegant, fast solution. You don’t need SAS Enterprise Miner, IML, or any other spe…

Logistic function macro for SAS

Used in logistic regression, neural networks, and countless other applications, the logistic function is simple to understand yet can be quirky to calculate in SAS because of how SAS treats extreme values. First, let’s consider the value -1000: R…

Model decision tree in R, score in SAS

This code creates a decision tree model in R using party::ctree() and prepares the model for export it from R to SAS, so SAS can score new records without invoking R. I use this method for several reasons. First, it’s convenient for my workflow t…

Programmatically download monthly economic indicators

This SAS code programmatically downloads monthly economic indicators from FRED, and merges multiple time series into a single data set for convenient analysis. FRED (Federal Reserve Economic Data) is an excellent resource from the Federal Reserve Bank …

Delete non-exact duplicates in SAS

When deleting non-complete duplicates in SAS, in each duplicate set you may want to keep a particular record identified by a rule: it may be the oldest, newest, first, or last observation in each set. You need a identifier to be unique, but you can&#82…