BookmarkSubscribeRSS Feed
czarek
Calcite | Level 5

Good afternoon everyone,

 

Because I think, that scheduling in SAS Management Console has a lot of limitations, I'm trying to schedule my deployed DI jobs using powershell, which is more flexible than old vb scripts.

What I do now:

-deploy my job as before,

-create powershell file, which runs my sas file and creates a log, for now it looks like this:

$logname="C:\SAS\Config\Lev1\SchedulingServer\batchuser\SAP_RFC\Log\mylog_"+(get-date -uformat "%Y%m%d_%H%M%S").tostring()+".log"
C:\SAS\Config\Lev1\SASApp\BatchServer\sasbatch.bat -log $logname -batch -noterminal -logparm ""rollover=session"" -sysin "C:\SAS\Config\Lev1\SchedulingServer\batchuser\SAP_RFC\myprogram.sas"

 

When I run scheduled SAS job using the old method, I can see retun code (status) in small log from vbs script, eg:

Flow STARTING...
Job BOM_tab_A5P60HQJ_CE00000O STARTING 08/03/2020 04:00:00
Job BOM_tab_A5P60HQJ_CE00000O COMPLETE 08/03/2020 04:00:43 status=0.
Job MB51_tab_A5P60HQJ_CE00000Q STARTING 08/03/2020 04:00:43
Job MB51_tab_A5P60HQJ_CE00000Q COMPLETE 08/03/2020 04:09:05 status=0.

I can see it in Windows scheduler too (Last run result column)

 

My question is, how could I retrieve this value using powershell?

 

Thanks in advance!

Best regards,

Czarek

1 REPLY 1
czarek
Calcite | Level 5

Hello,

I found an answer - there is automatic Powershell variable called $lastexitcode. So code can look like this:

 

#Execute sas code

C:\SAS\Config\Lev1\SASApp\BatchServer\sasbatch.bat -log C:\Temp\log.log -batch -noterminal -logparm ""rollover=session"" -sysin "C:\Temp\sasfile.sas"

#write information to log

(get-date -Format "yyyy.MM.dd HH:mm:ss").ToString() +   "| $lastexitcode |  My Job name" |Out-File -FilePath "C:\Temp\log_ps.log" -Append -Force

 

It works good for me 🙂

Czarek

AI Navigator GIF.gif


Navigate AI governance with SAS tools for compliance and ethical AI practices. Try SAS Ai Navigator for free for the first six months.

Check it out on Microsoft Marketplace →

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1332 views
  • 0 likes
  • 1 in conversation