I tried to using powershell to call SAS via COM. However it doesn't work in some situation.
I have a SAS installed on a remote windows machine with no SAS Integration Technologies (e.g. no IOM access or sas EG access or metadata server or no workspace server). When I login in via windows remote desktop, I can run sas code via COM in vscode. But if I sign in by SSH, I have the same error report as you reported.
Below I tried step by step powershell script in the ssh terminal, an error throwed in `$objSAS.LanguageService.Submit`
$objFactory = New-Object -ComObject SASObjectManager.ObjectFactoryMulti2 $objServerDef = New-Object -ComObject SASObjectManager.ServerDef $objServerDef $objServerDef.MachineDNSName = "xxx.xx.x.x" # SAS Workspace node $objServerDef.Port = 0 # workspace server port $objServerDef.Protocol = 0 # 0 = COM protocol $objServerDef # Class Identifier for SAS Workspace $objServerDef.ClassIdentifier = "440196d4-90f0-11d0-9f41-00a024bb830c" # create and connect to the SAS session $objSAS = $objFactory.CreateObjectByServer( "Local", # server name $true, $objServerDef, # built server definition "", # user ID "" # password ) $program = "proc sql; create table work.test as select* from perm.data; proc print data=work.test;run;" $objSAS.LanguageService.Submit($program); $objSAS.Close()
An error raised after `$objSAS.LanguageService.Submit($program)`
You cannot call a method on a null-valued expression. + $objSAS.LanguageService.Submit($program); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [],RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull
**Environment:**
Client OS: Windows 2019
SAS version: SAS 9.4 with ITC only, but not IT (e.g. IOM not enabled)
No SAS instance. The service is empty.
LanguageService : DataService : FileService : ODS : Utilities : Name : SAS Workspace UniqueIdentifier : 866FB099-92A3-4445-9C7F-5C137534D265
Remote powershell policy
# Get-ExecutionPolicy -list Scope ExecutionPolicy ----- --------------- MachinePolicy Undefined UserPolicy Undefined Process Undefined CurrentUser RemoteSigned LocalMachine RemoteSigned
We have a 'sasusers' group on the windows 2019 server, and I'm in the group.
I can schedul task via SSH, like:
schtasks /create /tn %USERNAME%_test_sas /tr C:\Users\%USERNAME%\run_getopts.bat /sc once /sd 2023/12/13 /st 00:46 /ru %USERNAME% /rp
We use SAS OA last week and now switch to SAS foundation. The powershell code worked before, but doesn't work after we switched to SAS foundation. We should have ITC (no metadata sever) as the code works with COM when I login via Remote Desktop.
I can't find anything related in the Windows Event Viewer.
I run the same simple powershell code as below in remote ssh and remote desktop and there are some difference in $objServerDef.
Code:
$objFactory = New-Object -ComObject SASObjectManager.ObjectFactoryMulti2 $objServerDef = New-Object -ComObject SASObjectManager.ServerDef $objServerDef
SSH: (not stable, sometimes it include `ServiceName:sasobjspawn`, `port : 0`, but other times may not)
Protocol : 0 Description : DomainName : LogicalName : BridgeEncryptionLevel : 0 BridgeEncryptionAlgorithm : RecycleActivationLimit : 0 RunForever : True ShutdownAfter : 3 ClassIdentifier : 440196D4-90F0-11D0-9F41-00A024BB830C ProgID : SAS.Workspace.1.0 ID : URI : iom://localhost;COM;CLSID=440196D4-90F0-11D0-9F41-00A024BB830C,ENCRLVL=None/ ExtraNameValuePairs : BridgeSecurityPackage : BridgeServicePrincipalName : BridgeSecurityPackageList : Kerberos,NTLM AuthenticationService :
Remote Desk:
Port : 0 ServiceName : sasobjspawn Name : MachineDNSName : Protocol : 0 Description : DomainName : LogicalName : BridgeEncryptionLevel : 0 BridgeEncryptionAlgorithm : DCOMSecurityService : 0 DCOMAuthenticationLevel : 0 MaxPerObjectPool : 10 RecycleActivationLimit : 0 RunForever : True ShutdownAfter : 3 ClassIdentifier : 440196D4-90F0-11D0-9F41-00A024BB830C ProgID : SAS.Workspace.1.0 ID : URI : iom://localhost;COM;CLSID=440196D4-90F0-11D0-9F41-00A024BB830C,ENCRLVL=None/ ExtraNameValuePairs : BridgeSecurityPackage : BridgeServicePrincipalName : BridgeSecurityPackageList : Kerberos,NTLM AuthenticationService : ProxyList : {}
Thanks. Will check with SAS admin.
The SAS Users Group for Administrators (SUGA) is open to all SAS administrators and architects who install, update, manage or maintain a SAS deployment.
SAS technical trainer Erin Winters shows you how to explore assets, create new data discovery agents, schedule data discovery agents, and much more.
Find more tutorials on the SAS Users YouTube channel.