Monday, 12 December 2016

Look out - Locale Gotcha

As gotcha's go, this was a good one!

We had a report being generated with dates that were inconsistent with the source file (MMDDYY instead of DDMMYY), but only for certain records.  This was definitely related to the ANYDTDTE. informat, but the strange thing was - this issue only occurred when the report was generated by the Stored Process Server (it was fine in batch).

The ANYDTDTE. informat is driven by the locale setting but as per the chain of sasv9.cfg files we had -LOCALE en_GB defined for both servers.  So I checked the logs, and found something interesting..

One of our STP applications can be triggered from either Excel or a browser.  I could see that the same user had triggered two requests, less than a minute apart, one from excel and one from a browser (as evidenced by the value of the _HTUA variable)

Yet one session had _USERLOCALE=en_US and the other had _USERLOCALE=en_GB!!

As it turns out, the locale for a Stored Process session can change according to the context of the client - as described in this usage note.

So the fix is simply to add the following code (as per your desired locale):
options locale=en_gb;
But where?

I tried fixing this via the autoexec, but this had no effect (likely because the server is running before the request arrives) so instead I added it to the stp init program - which worked a treat.

I recommend adding this to your init program, unless you really do want your outputs to change according to the locale setting of the client application!


  1. Thanks for sharing Alan. I knew about the locale option required for anydtdte format but didn't know that the locale for a stored process session can be client dependent. What a gotcha! Thanks for sharing your troubleshooting and the SAS usage note too. One to remember for non-default locale environments.

  2. This information really worth saying, i think you are master of the content and thank you so much sharing that valuable information and get new skills after refer that post.
    R Language Training in Chennai