Previous Entry Share Next Entry
Obsessive coding
My last project for the company was to enhance the automated Unix month-end reports to include forecasting of several metrics (I wrote the original automation). I used a cool tool to determine best fit forecasting model based on the data.

I built the code to be very modular. There are three SAS scripts run in series from a simple ksh.
Script 1 collects the data from Oracle tables in multiple queries, merges the data together, and adds several calculations.
Script 2 takes the above daily data and creates monthly and weekly data from it. Based on the calculated monthly data, forecasts are made.
Script 3 generates an HTML report for each server.

Somewhere in Part 3 is the problem that was (is still) vexing me, and the reason I was still there at 5pm on my last day. I have each of the report sections as a macro (function). In 3 of the 5 reporting macros, I call a quick PROC SQL command to pull 1 value from the table (in order to create a Reference line). Each of the macros uses a different variable, which should be 'local' to that macro, based on local v. global variable rules.

For whichever of the three gets called first, it works (i tested this by changing the order of the function calls). The next two, however, get an extra "&" pre-pended to the variable (SAS uses &varname, unlike say perl, which uses $varname), which causes it to be parsed wrong. So this happens:
In macro 1, as it should be, &var1
In macro 2, it is in the logs as & &var2
In macro 3, it is in the logs as & &&var3


I did test using the same variable name in each macro, but that did not change the behavior.



Log in