Birthday gift code puzzle

This is a SAS code puzzle. The code works as is, but can you make it simpler? We do this while enjoying simulation and the quirkiness of the Gregorian calendar. The problem A person receives a gift on a random day. Relative to his birthday, how many days is the gift late? Negative values indicate…

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 of St. Louis: it’s easy to find, graph, download, and process data sets online. In our case, though,…

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’t randomly choose which observation to keep. To be precise, you…

Avoid truncating characters in PROC IMPORT csv

Watch out for this common pitfall when importing .CSV files into SAS using the PROC IMPORT procedure. If your .CSV files always have character strings only with consistent widths (such as ISBN book codes, ethernet MAC addresses, UPC barcodes, Social Security Numbers) or numeric values only, then you may stop reading now. However, if your…

Dump wide table to HTML report (SAS)

This SAS macro dumps a data set with many variables to an HTML report in a single line of SAS code. It’s useful on wide data sets (or in database speak, a wide table with many columns), with long character values, or where the customer needs to focus on individual observations. It’s similar to PROC…

Import DBF in SAS

There are several ways to import DBF files in SAS. First, there is PROC DBF: But in my environment (SAS 9.1.3 Windows XP; and SAS 9.2 on Windows Server 2008 with Enterprise Guide 4.2 on Windows XP) this gives the error ERROR: Procedure DBF not found. Another way is to use PROC IMPORT: But that…

Passing a range to a SAS stored process via URL

Stored processes can be called via the SAS Stored Process Web Application using a URL. Though powerful and useful, the advanced usage concerning ranges requires explanation. Background Say you have a program called /path/myprogram on server sasserver, then in your web browser the following URL executes the stored process with the default parameters. https://sasserver/SASStoredProcess/do?_program=/path/myprogram These…

Make SAS much faster with data set compression

R is fast at processing data sets, but it is limited by memory (physical RAM plus swap). SAS processes much larger data sets, but it is slow because it keeps the data sets on the hard drive. Although computer processors have become faster and memory larger, hard drive performance hasn’t changed much: disk I/O is…