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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 338 views
  • 0 likes
  • 2 in conversation