Tag: Snippets

Stamping the SAS Log with all Macro Variable Values

The topic of the day around the office was stamping all of the user created macro variables into the log function. I’ve got a few programs that have a lot (20+) auto-generated dates, etc and the following is just one of the the many ways to print what each macro resolves to into your log […]

How many days until?

A simple little macro I whipped up that’ll count down the number of days until an important event. %macro daysUntil(event, date); data _null_; diff = datdif(today(), input(“&date.”, anydtdte10.), ‘act/act’); call symput(‘days_until’, strip(diff)); run; %put There are &days_until days until &event; %mend; Macro call is straight forward: %daysUntil(Christmas, 12/25/2011); %daysUntil(Columbia_Marathon, 03/10/2012); I could have used various […]

Variable Names into Macro Variables

Late last month, I posted an answer to a question on StackOverflow. This morning, I had to use something similar at work and it reminded me that ability to pull variable names out of a data set is a handy trick. For the example, I’m using the yr1001 data set from sashelp to avoid sending […]

Off to Bitbucket

With Bitbucket now offering git support, it made sense to transfer over my repositories from github. I have a lot of code (macro’s and examples) that I reference currently stored dumped onto a single page google site. I haven’t scrubbed out any proprietary information / work references so those snippets have to remain private for […]

Automatically Generate Days of the Month

Run a monthly report and absolutely hate having to change the macro variables? Luckily SAS has the handy intnx function to make your life easier. The following code will automatically generate the date for the first / last day of the previous month.  Modify the -1 to however many previous months you need to adapt […]