How do I use SAS IOM on the local machine with PowerShell?

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

How do I use SAS IOM on the local machine with PowerShell?

I am trying to adapt Chris Hemedinger's "Using PowerShell with SAS workspace" to use SAS IOM on my computer in his SAS blog for 2013-03-13.

I am getting stuck on how to determine the parameters for $objServerDef.MachineDNSName and server name.

I am connected to a local area network but I just want to use the SAS IOM that is installed on my local computer.

I tried something like "machinename.company.com" and the IP address of my computer on the network but these did not work.


Accepted Solutions
Solution
‎04-14-2015 12:08 AM
Trusted Advisor
Posts: 1,300

Re: How do I use SAS IOM on the local machine with PowerShell?

Just leave that part out... Use the default server def when using a local install:

$objFactory = New-Object -ComObject SASObjectManager.ObjectFactoryMulti2

$objServer = New-Object -ComObject SASObjectManager.ServerDef

$objSAS = $objFactory.CreateObjectByServer("mylocal", $true, $objServer, "", "")

$program = "proc setinit; run;"

$objSAS.LanguageService.Submit($program)

Write-Output $objSAS.LanguageService.FlushLog(10000)

$objSAS.close()

View solution in original post


All Replies
Respected Advisor
Posts: 3,062

Re: How do I use SAS IOM on the local machine with PowerShell?

From a Windows command line try PING machinename.company.com. Does it work? If it doesn't then check with one of your IT network specialists. If it does work then you may have some other problem - I'll let IOM experts guide you here.

Also the Windows command IPCONFIG will tell you what your actual IP address is.

Solution
‎04-14-2015 12:08 AM
Trusted Advisor
Posts: 1,300

Re: How do I use SAS IOM on the local machine with PowerShell?

Just leave that part out... Use the default server def when using a local install:

$objFactory = New-Object -ComObject SASObjectManager.ObjectFactoryMulti2

$objServer = New-Object -ComObject SASObjectManager.ServerDef

$objSAS = $objFactory.CreateObjectByServer("mylocal", $true, $objServer, "", "")

$program = "proc setinit; run;"

$objSAS.LanguageService.Submit($program)

Write-Output $objSAS.LanguageService.FlushLog(10000)

$objSAS.close()

New Contributor
Posts: 3

Re: How do I use SAS IOM on the local machine with PowerShell?

FriedEgg' program worked.

I am adding some code to help others who might try this.

Add this before the $objSAS.close() in FriedEgg's code:

$program = "data _null_ ; do i = 1 to 4 ; putlog i = ; end ; run ;"

# the next line runs $program

$objSAS.LanguageService.Submit( $program )

# look at the log

Write-Output "Log:"  # only writes "Log:" to the PowerShell log.

$log = "" # initialize $log to empty string

# do loop retrieves SAS log into $log and writes it to the PowerShell log

do

{

  $log = $objSAS.LanguageService.FlushLog( 1000 )

  Write-Output $log

} while ( $log.Length -gt 0 )

# shows the one line program followed by the four lines of i =1, i = 2, i = 3, i = 4.

# The log ends with the NOTE on time used.

# Going back to the Chris Hemedinger 2013-03-13 sasdummy  blog showing proc means:

$program = "ods listing ; proc means data = sashelp.cars ; run ;"

$objSAS.LanguageService.Submit( $program ) ;

# Note that ods listing sent the output to list, not to the log.

# The log will show the one line program, number of observations read, and time used.

# do loop retrieves the log

do

{

  $log = $objSAS.LanguageService.Flushlog( $1000 ) 

  # Note that Write-Output can be redirected or piped later.

  Write-Output $log

} while ( $log.Length -gt 0 )

# That shows the log but not the output of Proc Means.

# Another loop to get the contents of ODS listing

Write-Output "List:" # writes one line to the PowerShell log to show where list begins.

# This loop is similar to the log but I am using $list and .FlushList() method.

do

{

  $list = $objSAS.LanguageService.FlushList( 1000 )

  Write-Output $list

} while ( $list.Length -gt 0 )

# That shows a text based listing of the proc means procedure.

Community Manager
Posts: 2,692

Re: How do I use SAS IOM on the local machine with PowerShell?

For others who see this discussion, the blog articles about SAS and PowerShell are available here:

http://blogs.sas.com/content/sasdummy/tag/powershell/

Chris

Frequent Contributor
Posts: 118

Re: How do I use SAS IOM on the local machine with PowerShell?

Or for simplicity you could download and install the Cmdlets4Sas which contains special commandlets for the interaction with SAS.

In your case you could just call the Connect-SasWorkspaceLocal commandlet to get a new local SAS workspace and forget all about the SAS IOM details.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 264 views
  • 7 likes
  • 5 in conversation