BookmarkSubscribeRSS Feed
MarcoRQ
Calcite | Level 5

Is there a way to retrieve the error in powershell ?

This is an example of my powershell script:

$sas = New-Object -comObject SASEGObjectModel.Application.7.1

$App=$sas.Open("C:\temp\myTestFile.egp","")

Foreach($parametre in $App.Parameters)
{
If ($parametre.Name -eq "USER")
{
$parametre.Value='MyUser'
}
If ($parametre.Name -eq "PASSWORD")
{
$parametre.Value='{sas002}MyPasswordEncrypted'
}
}

Try {
$output = $App.run() #<======= How can I get the error here ???
Write-Host "Result: " $output}
Catch{
Write-Host "An error occurred:"
Write-Host $_
}
Finally{
$App.save()
$App.close()
$sas.quit()
}

When calling Run(), the error is not reported even if I'm using %abort ABEND in the sas macro. 😞


In my sas macro, I simulate an error by inserting the same row 2 times so I want this error reported in the powershell script

proc sql;
insert into MyConnection.MyTable select * from to_insert;
%if &SQLRC > 0 %then %do;
%put ERROR: Error happened!;
%abort ABEND;
%end;
quit;


I put all the code in the autorun.
If I put a wrong password, I get an error and go in the Catch section.

Regards,

1 REPLY 1
ballardw
Super User

If you want to know why the abort occurred you may want to consider

 

%abort abend 1234;

Where 1234 would be a return code that the operating system receives. You need to check what ranges of values your OS will allow. And 1234 if just an example. You would need to "know" what 1234 means for your program.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 662 views
  • 0 likes
  • 2 in conversation