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
366 stars 149 forks source link

How to set XCMD? #566

Closed kangcp closed 7 months ago

kangcp commented 8 months ago

I need to set XCMD, According to this issueSystask error command does not launch from JN, removing javaparams does solve the X command problem, but I need to specify a different sas configuration file based on different encodings, such as starting U8-encoded sas, So -config "C:\PROGRA1\SASHome\SASFOU1\9.4\nls\u8\sasv9.cfg", if I do not set javaparams, will I not be able to set sas encoding? Is there any other solution?

my sas infos: 16587 PROC OPTIONS OPTION=XCMD VALUE; 16588 RUN;

SAS (r) Proprietary Software Release 9.4 TS1M5 Option Value Information For SAS Option XCMD Value: NOXCMD Scope: SAS Session How option value set: SAS Session Startup Command Line

NOTE: PROCEDURE OPTIONS used (Total process time): real time 0.00 seconds cpu time 0.00 seconds

saspy version: 4.7.0

tomweber-sas commented 8 months ago

Thanks for opening this. When posting to an old closed issue, anyone who was on it starts getting the emails with it, which isn't what anyone wants.

So, is this a local PC SAS install you're trying to use? The proper way to configure that is w/ SAS itself, not saspy options; specifically for startup options, which can't be set at start time since the only way to use a local PC SAS deployment is via the IOM interface. It's for Workspace servers (and local pc SAS), and that doesn't allow for overriding configuration options on startup. Providing the javaparms keyword is the only way get past that restriction.

So, for instance, there should be a sasv9.cfg file in "C:\PROGRA1\SASHome\SASFOU1\9.4" which has the -config "C:\PROGRA1\SASHome\SASFOU1\9.4\nls\xx\sasv9.cfg, pointing to the specific version which has all of the actual config option for each different local/encoding.

Changing the -config value in he top sasv9.cfg (in the C:\PROGRA1\SASHome\SASFOU1\9.4 dir) to point to a different C:\PROGRA1\SASHome\SASFOU1\9.4\nls\xx value is the way to point to a specific version and will be picked up automatically when IOM starts the SAS session for saspy. In the other issue, the user couldn't change that value due to some permission setting. So using the javaparms was the work around. Once they got the config changed, they could remove the javaparms workaround and have it work as expacted.

Can you give that a try and let's see if it solves your issue?

Thanks, Tom

tomweber-sas commented 8 months ago

Oh, and of course, you can change the value of NOXCMD to XCMD in the config file you're using for the configuration!

kangcp commented 8 months ago

Thank you Tom, for some special reasons, modifying C:\PROGRA1\SASHome\SASFOU1\9.4\sasv9.cfg is not allowed, but I can modify C:\PROGRA1\SASHome\SASFOU1\9.4\nls\xx\ sasv9.cfg, but how should I set XCMD in the configuration file? I'm not very familiar with this。

tomweber-sas commented 8 months ago

Hey, the doc for XCMD is here: https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/hostwin/p0xtd57b40ehdfn1jyk8yxemfrtv.htm Which states (and is the case with my deployment) that XCMD is allowed by default. So that makes me wonder why it's disabled, and where? But it's nothing more than a line in the config file: -XCMD like you see all the other options in those config files. So I would look to see if -NOXCMD is set in the config(s) being used and either remove that or remove the NO part of it, setting -XCMD instead.

Ok, looking at the info you provided above:

Option Value Information For SAS Option XCMD
Value: NOXCMD
Scope: SAS Session
How option value set: SAS Session Startup Command Line

This says that -noxcmd is set on the command line, not from a config file. I was setting it in my ...\nls\xx\sasv9.cfg file to test out it was working:

Option Value Information For SAS Option XCMD
    Value: NOXCMD
    Scope: SAS Session
    How option value set: Config File
    Config file name:
            C:\Program Files\SASHome\SASFoundation\9.4\nls\u8\sasv9.cfg

So, how did you start that SAS session where it says it's set on the command line? Is that from SASPy with Local IOM? Is that just running SAS by clicking on a shortcut on your pc? Who installed SAS on your PC, admins, or you? Seems not to be a default configured deployment.

The 'command line' that is used from starting SAS with IOM is in the registry which is explained here in number 5. Ignore the error that's describing, as you're not getting the error, but in that registry entry descried there is the command line. So I would look there to see if that's where -NOXCMD is set. Here's mine for reference. Can you provide what you're is set to? image

It seems this was disabled on purpose since the default for a deployment is that this isn't specified anywhere thus allowing XCMD. So do you have a SAS admin that deploys these on your system? You may want to ask them why this is set.

Tom

tomweber-sas commented 8 months ago

And just for reference, here's the output from the default config without my adding the option to any config file (like I showed above).

2    proc options option=xcmd value;run;

    SAS (r) Proprietary Software Release 9.4  TS1M8

Option Value Information For SAS Option XCMD
    Value: XCMD
    Scope: SAS Session
    How option value set: Shipped Default

That would be what you would get with a default deployment.

liangfmc commented 8 months ago

TOM, I also have a similar situation, here are my configuration and python code.

winlocal = {
    'java': 'C:\\Program Files\SASHome\\SASPrivateJavaRuntimeEnvironment\\9.4\\jre\\bin\\java.exe',
    'javaparms': [f'-Dcom.sas.iom.orb.brg.zeroConfigWorkspaceServer.sascmd=C:\\Program Files\\SASHome\\SASFoundation\\9.4\\SAS.EXE'
    ],
}
import saspy
sas = saspy.SASsession(cfgname='winlocal')

ll=sas.submit('''
proc options option=xcmd value;run;
           ''')

print(ll['LOG'])
27   proc options option=xcmd value;run;

     SAS (R) PROPRIETARY SOFTWARE RELEASE 9.4  TS1M7

Option Value Information For SAS Option XCMD
    Value: NOXCMD
    Scope: SAS Session
    How option value set: SAS Session Startup Command Line
liangfmc commented 8 months ago

We need to set different sascfg files based on varying situations.

#for_utf8
winlocal = {
    'java': 'C:\\Program Files\SASHome\\SASPrivateJavaRuntimeEnvironment\\9.4\\jre\\bin\\java.exe',
    'javaparms': [f'-Dcom.sas.iom.orb.brg.zeroConfigWorkspaceServer.sascmd=C:\\Program Files\\SASHome\\SASFoundation\\9.4\\SAS.EXE' -config "C:\\Program Files\\SASHome\\SASFoundation\\9.4\\nls\\u8\\sasv9.cfg"
    ],
}
#for_en
winlocal = {
    'java': 'C:\\Program Files\SASHome\\SASPrivateJavaRuntimeEnvironment\\9.4\\jre\\bin\\java.exe',
    'javaparms': [f'-Dcom.sas.iom.orb.brg.zeroConfigWorkspaceServer.sascmd=C:\\Program Files\\SASHome\\SASFoundation\\9.4\\SAS.EXE' -config "C:\\Program Files\\SASHome\\SASFoundation\\9.4\\nls\\en\\sasv9.cfg"
    ],
}
kangcp commented 8 months ago

Hey, the doc for XCMD is here: https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/hostwin/p0xtd57b40ehdfn1jyk8yxemfrtv.htm Which states (and is the case with my deployment) that XCMD is allowed by default. So that makes me wonder why it's disabled, and where? But it's nothing more than a line in the config file: -XCMD like you see all the other options in those config files. So I would look to see if -NOXCMD is set in the config(s) being used and either remove that or remove the NO part of it, setting -XCMD instead.

Ok, looking at the info you provided above:

Option Value Information For SAS Option XCMD
Value: NOXCMD
Scope: SAS Session
How option value set: SAS Session Startup Command Line

This says that -noxcmd is set on the command line, not from a config file. I was setting it in my ...\nls\xx\sasv9.cfg file to test out it was working:

Option Value Information For SAS Option XCMD
    Value: NOXCMD
    Scope: SAS Session
    How option value set: Config File
    Config file name:
            C:\Program Files\SASHome\SASFoundation\9.4\nls\u8\sasv9.cfg

So, how did you start that SAS session where it says it's set on the command line? Is that from SASPy with Local IOM? Is that just running SAS by clicking on a shortcut on your pc? Who installed SAS on your PC, admins, or you? Seems not to be a default configured deployment.

The 'command line' that is used from starting SAS with IOM is in the registry which is explained here in number 5. Ignore the error that's describing, as you're not getting the error, but in that registry entry descried there is the command line. So I would look there to see if that's where -NOXCMD is set. Here's mine for reference. Can you provide what you're is set to? image

It seems this was disabled on purpose since the default for a deployment is that this isn't specified anywhere thus allowing XCMD. So do you have a SAS admin that deploys these on your system? You may want to ask them why this is set.

Tom

Sorry Tom, I've been a little busy recently, so I didn't reply in time。 The Settings in my registry are the same as yours。If I didn't set up javaparms, I would behave the same way as you do, but with javaparams set up I would have the situation above, and with saspy I upgraded to the latest version, but that didn't fix the problem

tomweber-sas commented 8 months ago

I've been trying to reproduce what you are seeing and i think I have, in that when I provide the sascmd in javaparms, -noxcmd is being set. However, I can't get javaparms to work for me (as it used to) and I think that because my local PC SAS is now M8. A lot changed in M8 regarding java due to endless security issues. I'm guessing that's why what used to work no longer does. So, I can't test out adding -xcmd to the javaparms command line. FWIW, the javaparms is a workaround for a different problem having to do with the registry command being invalid. The real way to configure these things w/ PC SAS is to use the config files.

Since you have it working still: 'javaparms': [f'-Dcom.sas.iom.orb.brg.zeroConfigWorkspaceServer.sascmd=C:\\Program Files\\SASHome\\SASFoundation\\9.4\\SAS.EXE' -config "C:\\Program Files\\SASHome\\SASFoundation\\9.4\\nls\\en\\sasv9.cfg"] Can you just try adding -xcmd to that command line you're using, to override? 'javaparms': [f'-Dcom.sas.iom.orb.brg.zeroConfigWorkspaceServer.sascmd=C:\\Program Files\\SASHome\\SASFoundation\\9.4\\SAS.EXE' -config "C:\\Program Files\\SASHome\\SASFoundation\\9.4\\nls\\en\\sasv9.cfg" -XCMD] Or, did you try putting it into the config file you're pointing to? Did that not get it to work?

liangfmc commented 8 months ago

TOM, I apologize for the confusion, this is the correct configuration setting. This single quote should be placed at the end. The results for both configurations are NOXCMD, value set: SAS Session Startup Command Line.

#Modify the configuration of "en\sasv9.cfg", add -XCMD
'javaparms': [f'-Dcom.sas.iom.orb.brg.zeroConfigWorkspaceServer.sascmd=C:\\Program Files\\SASHome\\SASFoundation\\9.4\\SAS.EXE -config "C:\\Program Files\\SASHome\\SASFoundation\\9.4\\nls\\en\\sasv9.cfg" ' ]

Or

'javaparms': [f'-Dcom.sas.iom.orb.brg.zeroConfigWorkspaceServer.sascmd=C:\\Program Files\\SASHome\\SASFoundation\\9.4\\SAS.EXE -config "C:\\Program Files\\SASHome\\SASFoundation\\9.4\\nls\\en\\sasv9.cfg"  -XCMD' ]

The return log is:

24         ods listing close;ods html5 (id=saspy_internal) file=_tomods1
24       ! options(bitmap_mode='inline') device=svg style=HTMLBlue; ods graphics on / outputfmt=png;
NOTE: Writing HTML5(SASPY_INTERNAL) Body file: _TOMODS1
25
26
27         proc options option=xcmd value;run;

    SAS (r) Proprietary Software Release 9.4  TS1M7

Option Value Information For SAS Option XCMD
    Value: NOXCMD
    Scope: SAS Session
    How option value set: SAS Session Startup Command Line

NOTE: PROCEDURE OPTIONS used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

However, the following configuration is normal:

'javaparms': [],

tomweber-sas commented 8 months ago

Thanks @liangfmc! That's what I was able to see also. I can get javaparms to work on my system (9.4M8), but only for the sas.exe path, with no other options; no -config or -xcmd or anything. Anything else that worked with earlier version no longer works.

So, this whole javaparms thing was a work around to a corrupt install where the command in the registry wasn't valid but the users couldn't update the registry. The eventual fix was to re-register SAS in the registry with a SAS provided tool/command: [C:\...\]sas.exe /regserver That's in the saspy doc see number 5 here.

But this isn't a documented feature or anything having to do with SASPy. It was something a user contributed to get around the bad path in the registry, till that got fixed correctly. Now were in a similar situation where using that parm causes SAS (the IOM client) sets -noxcmd,, where it wouldn't if you weren't supplying that java command override.

The right way to set the configuration for this local IOM connection is in the config files as described at the beginning of this. The problem with that is that you don't have write permission on the config file for you're local PC SAS install. That's the thing that needs to be fixed, so you can then adjust it to point to whichever .../9.4/nls/XX/sasv9,cfg and then you don't need to try to set or override NOXCMD because it won't be set, it will use the default of XCMD, though you can put -XCMD in your config file to set it, but it's already that when you aren't providing java overrides.

So, the right answer is to be allowed to edit your own local config for your own local SAS install. If this were a workspace server configuration, you shouldn't have access to it. But this is a personal PC SAS install only accessible from the local machine. There' no reason you shouldn't be able to pick you're config file and choose which one you want to use. javaparms isn't the answer for this.

Can you both change permission so you can edit your config file or have whomever admins your machines do that for you, then you can run your SAS how you wan on your machine?

Thanks, Tom

liangfmc commented 8 months ago

Thank you, Tom. I can achieve the desired effect by modifying the values in the registry and starting either en sas or utf8 sas.

tomweber-sas commented 8 months ago

Nice! Yes, that's the other way, but again, regular users can't necessarily edit registry settings, so that's a bit advanced. I really don't know why the config file is locked down from users for a local install. That's just kinda wrong since that's the way to configure SAS.

But thanks for confirming that! Tom

kangcp commented 8 months ago

@tomweber-sas Tom, you are right, normal users can't edit the registry, but the contents of the registry can be viewed through python code, so it should be readable, and now we have the awkward situation that normal users can't start sas without javaparams, and with javaparams, they can't set up XCMD

kangcp commented 8 months ago

Is there a better way to solve this problem?

tomweber-sas commented 8 months ago

Hey @kangcp, googling this I see a lot of the same issue just with SAS and users wanting to do the same thing; just edit the config file to point to a specific nls config file, or just set an option. They all come back to needing admin permission to edit the sasv9.cfg file on windows. Even though that's the defined way to do so, the permission on that file are set so only an admin can edit it. The 'solutions' vary from just opening your editor 'as administrator' so you can then save your changes, to copying the file to a location where you can edit it and then changing you're registry command to point to that file. I also had that problem and I do need to point at different nsl versions of config, so I just changed the permissions on the file to let me edit it. Done.

The javaparms was just a workaround because of a bug in a SAS deploy job that corrupted the command line in some version, I don't remember, but that real fix was to re-register the registry command with that tool I mentioned before. javaparms isn't a real, supported way to control SAS. Since IOM is the only way to be able to run a local Windows SAS session, from SASPy, and it uses the registry command to start the SAS session, the only way to configure that is either the registry command (which is more of an admin thing to do) or just edit the sasv9.cfg file, which is the defined way to change the SAS configuration. So, edit that as admin, or change the permission so you can just edit it are the only good ways to configure this. I don't know why a local PC install (Not a production workspace server deployment; that would make sense) defaults to not allowing you to edit your own config file. But it seems to be that way for everyone and everyone has this same issue. It's a SAS thing, not really a SASPy thing.

tomweber-sas commented 7 months ago

I was digging through SAS doc and found the following. https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/hostwin/p0bmj7wjme32ayn1h4wim7trkhp6.htm#p1f8pahglb6jz0n18i9bd3xxl84r It has a hundred different options and instructions for trying to deal with config files on Windows. It's ridiculous, but, it shows that there are a bunch of ways to try to do the one thing you want. And almost none of them work when using IOM, because there's a -config on the command line, (from the registry). BUT, I found one that will add a config file you point to which is added last, so what's in it overrides the others - last option wins in SAS when you specify the same option multiple times!

Sorry for the long output but easier to show. FYI. My primary sasv9.cfg points to the nls/u8, but the one I want to use is the simplified Chinese, zh. So I copied that one to a dir in my home path (I can read/write). As you see it's added after the default ones, but it overrides everything in those so it's like you only used that one. You can see it pickec it up because of the encoding and the log output, and importantly, XCMD is still enabled. Note I have no javaparms in my config (shown):

image

Can you try that and see if that solves this one for you? Maybe this is finally the answer you've been wanting!

Tom

kangcp commented 7 months ago

@tomweber-sas Thank you Tom, this method cannot solve our problem, we are ready to bypass this problem in other ways, thank you again!

tomweber-sas commented 7 months ago

Hey @kangcp , I thought that would get you what you want, but if you've got another way, that's good too. Is there anything else I can do; not that' I've done anything for this so far :) Do you want to close this, is what you're going to do instead working as you need? Thanks, Tom