BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SAS_L
Fluorite | Level 6

Hello Community,

I am looking for some ideas here.

I have a requirement wherein I have to create a log dataset containing 2 variables Error text and Error Timestamp. I want to populate this dataset anytime I run any SAS code. For Example, I ran a code and it hits an error, I want to populate the dataset with error text and timestamp. Next time, I again run the code and this time it runs sucessfully, I want to populate the dataset with Error text as sucessfull.

I though of exporting SAS logs to text file and then importing that file to a dataset, but I want somewhat of a realtime approach where that log dataset keeps on updating with each code run. 

Let me know if any more information is needed.

I am using SAS Studio

Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Create a little macro that inserts the error message into the data set. Add triggers into your code.

 

How that %IF/%THEN is structured will vary from program to program, but hopefully gives you an idea. 

 

%macro add_error(error_code = , error_message = );

proc sql;
insert into mydb.Error_Log
values(&error_code, &error_message);
quit;

%mend;

proc sql;
create table test as
select name, weight, height, error
from sashelp.class;
quit;

%if _SYSERR_ %then %add_error("Mistake1", "Check program at Part2");

View solution in original post

3 REPLIES 3
Reeza
Super User

Create a little macro that inserts the error message into the data set. Add triggers into your code.

 

How that %IF/%THEN is structured will vary from program to program, but hopefully gives you an idea. 

 

%macro add_error(error_code = , error_message = );

proc sql;
insert into mydb.Error_Log
values(&error_code, &error_message);
quit;

%mend;

proc sql;
create table test as
select name, weight, height, error
from sashelp.class;
quit;

%if _SYSERR_ %then %add_error("Mistake1", "Check program at Part2");

SASKiwi
PROC Star

I'm not a great fan of coding for job monitoring. You can get useful, but simple results by switching to running your code in SAS batch jobs via a job scheduler. The scheduler can automatically email you to tell you if a job was successful or not. Or you can monitor with the scheduler dashboard. Scheduling is as easy as clicking on selections in SAS Management Console.

 

Also the SAS option SYNTAXCHECK is set by default in batch mode and will immediately throw a job into syntax check mode when it hits an error so you only ever need to search for the first error in the job. That is pretty easy just with a text search as each batch job produces a SAS log file.

 

Read about this option here: https://documentation.sas.com/?docsetId=lesysoptsref&docsetTarget=n014qbvh3po8w5n1qlqbzr22vtg0.htm&d...

SAS_L
Fluorite | Level 6
Thank You. I was able to use some part of this code in my solution and get it to work. Appreciate your help!

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!
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.

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
  • 3 replies
  • 408 views
  • 4 likes
  • 3 in conversation