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

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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
  • 808 views
  • 0 likes
  • 1 in conversation