09-13-2017 02:49 AM
I'm quite new to SAS and really can't get my head around it's code, so asking here for help. I'm using DI studio.
I've a job that is reading an external csv file using file reader, and have a macro created by a colleague that validates the data in this external file and prints out error message to a work table.
What I'd like to do is either on precode of the file reader, or by using another user written code transformation is to read the work table and check if observations exist, and if they do, abort the job. From googling, and between here and stackoverflow, I can find how to read a dataset and count observations but I'm having real difficulty in figuring out how to implement it so any guidance would be really appreciated, or if there are better ways using SAS Di transformations like Conditional Start etc, I'm all ears for those too.
Can anyone please help me on this?
09-13-2017 06:41 AM
Yes there are.
There is a Data Validation transformation that covers some use cases.
If you have validation like if the value exists in a look up table, the Look up transformation can be used.
I think (not sitting on a DI Studio client right now) that these transformations can trigger both return code and abortion.
Abortion can also be handled by using Status Handling events.
09-14-2017 03:44 AM
We've the validation already, and have a lookup wrote written the macro. The File Reader transformation doesn't have a Status Handling tab which is what I was hoping so that doesn't work, unless there's another way I can put that in.
What I'd like to do is have my User Written Code transformation with the Validation macro run first, have the error messages (if found) output to a temporary work table and either;
by adding another transformation to abort if the dataset has records, or continue if not
or adding some code into pre-code of the file reader to check that dataset, and abort if it has records, or continue if not
or any other method I can do this
From what I can see, the Return Code transformation doesn't give me a chance to continue if failed, and not sure how I can status handling before or on the file reader step.
09-14-2017 08:15 AM
What you describe sounds to me already like a bit too much user written code (like this macro you mention). But not knowing the details below some SAS code which you could run after the error table gets created, either as post code or as a separate user written node.
If there is a macro for capturing errors but you then only keep those error in a work table and you are not really interested to look at these error records then why don't you just abort the job directly in this macro as soon as it finds the first error.
But o.k., here a code sample that aborts the job if table test got any rows.
data _null_; if nobs>0 then do; put 'Table Test has ' nobs 'rows'; put 'Aborting job'; abort abend; end; stop; set test nobs=nobs; run;
09-14-2017 11:53 AM
a month ago - last edited a month ago
With DIS you normally would use a Validation node which allows you to implement validation rules which populates Error and Exception tables. You wouldn't use a custom writte SAS macro for such a task if you can do it differently.