sassoftware / saspy

A Python interface module to the SAS System. It works with Linux, Windows, and Mainframe SAS as well as with SAS in Viya.
https://sassoftware.github.io/saspy
Other
374 stars 150 forks source link

Issues Encountered When Specifying Encoding #617

Open ka2048 opened 14 hours ago

ka2048 commented 14 hours ago

Describe the bug I installed three versions of SAS 9.4 on winlocal: the Unicode version, the English version, and the Chinese version. I hope to pass the encoding parameter when initializing the SAS session to specify the encoding, such as 'utf-8', 'windows-1252', or 'euc-cn'. However, the encoding parameter I specified does not seem to work, as my SAS session hangs when executing the following code:

saspy.SASsession(..., encoding='xxx', ...)

%put &sysencoding;
data _null_;
    put 'Hello, World!';  /* utf-8, windows-1252, euc-cn */
    put '你好,世界!';     /* utf-8, euc-cn */
    put '안녕하세요, 세계!';  /* utf-8 */
run;

My sascfg_personal.py is as follows:

SAS_config_names = ['winlocal']
winlocal = {'java': 'java'}

What is confusing is that no matter how I specify the encoding, the encoding printed in the SAS log is always 'euc-cn'.

tomweber-sas commented 8 hours ago

Hey @ka2048, unfortunately the way SAS on windows is installed and configured, and how SASPy can only use IOM to interact with it, doesn't allow for changing start up options like that. The command that is used to start SAS is defined in the windows registry and can't be changed on the fly. The way for you to be able to switch which SAS version starts up (with what options/language/...) is to change the value in the sasv9.cfg file in your SAS deployment, to point at the NLS version of sasv9.cfg you want to use. Those files can also be where you change any other SAS Initialization options too (those that you can't change after SAS starts, with the options x=y; statement - like encoding).

For instance, the registry entry that has the SAS command is like the following: image

It points to the sasv9.cfg file in it's -config parameter. That file has a -config itself (this is the one you can change) which points to the NLS specific sasv9.cfg file that then controls the rest of the options (like encoding). You could change options in that NLS version too, but just switching the path to which NLS version, in the main sasv9.cfg is the easiest. image

So, to change which encoding is used, just change in the main sasv9.cfg

-config "C:\Program Files\SASHome\SASFoundation\9.4\nls\u8\sasv9.cfg" to -config "C:\Program Files\SASHome\SASFoundation\9.4\nls\en\sasv9.cfg" or -config "C:\Program Files\SASHome\SASFoundation\9.4\nls\zn\sasv9.cfg"

or whichever you have installed. Here's what that filesystem looks like; I have multiple languages installed: image

Unfortunately the way IOM works, to start the server itself and use the configuration that's defined in the registry, precludes the ability to provide start up options from the client; kinda like a Workspace server in a larger deployment. So, changing the options in the sasv9.cfg files (or pointing to the one you want with those options) is how this is done on a windows machine.

Hope this gets you what you need! Tom