I've the ETL Jobs in DI Studio where it has precode and postcode as below. Main purpose of this code to get the Job Status and write in the SQL table.However I don't want this precode and postcode to execute when any of the ETL Job needs an update or enhancement. I don't wish to remove the precode and postcode either.
SAS program for the macro %Job_status is called in autoexec file.
I'm looking for an way to control the precode and postcode macro execution by macro variable. E.g.
%let run_macro_pre_post_code=Y; when I need to run precode and postcode and when %let run_macro_pre_post_code=N; then precode and postcode should not run.
/*Precode*/ %job_status(_status=STARTED, _jobName=&etls_jobName. ); /*Postcode*/ %job_status(_status=FINISHED, _jobName=&etls_jobName., _job_return_code=&syscc. );
I would be thankful if someone of you help me with the logic or the program to accomplish it.
You need to clearly distinguish between Macro Definition and Macro Call. The Macro Definition does NOT belong into the DI job but into a separate .sas file stored in a folder which is part of the SAS Macro Autocall Facility. The Macro Call is what belongs into the DIS job.
If you want this for every single transformation then consider to define default parameter values in the Macro Definition or use DIS generated macro variables in the macro wherever possible so you don't have to pass a lot of parameters every time you call the macro - plus you can change the defaults in a single place should there ever be the need.
Now for "disabling" the macros during development: Well, if you've got the macro calls in that many places then having such "overlay" macros as I've already proposed looks to me like a very feasible and easy to manage approach; and it doesn't require any change to the DIS job itself to switch between the productive and the "empty shell" versions.
You might also want to look into Status Handling. The Custom Action there allows to insert macro calls and if done this way then the generated code will also work in case the SAS job throws an Error.
Add a macro program:
%let run_macro_pre_post_code= Y; /* or N */
%macro chk(flag);
%if &flag = Y %then %do;
%job_status( _sattus=STARTED, _jobname= ...);
%end; %else %do;
%job_status( _sattus=FINISHED, _jobname= ...);
%end;
%mend;
%chk(&run_macro_pre_post_code);
You can submit the macro program once then run:
%macro chk(flag);
%if &flag = Y %then %do;
%job_status( _sattus=STARTED, _jobname= ...);
%end; %else %do;
%job_status( _sattus=FINISHED, _jobname= ...);
%end;
%mend;
%chk(Y);
...submit yours body job ...
%chk(N);
Sorry, it seems that I misunderstood what you are looking for.
On 2nd reading you want to control running or ignoring precode and postcode per run,
then a slight change need:
%macro chk(r_code, flag);
%if r_code ne Y %then %goto exit;
%if &flag = 1 %then %do;
%job_status( _sattus=STARTED, _jobname= ...);
%end; %else
%if &flag = 2 %then %do;
%job_status( _sattus=FINISHED, _jobname= ...);
%end;
:exit;
%mend;
%chk(&run_macro_pre_post_code , 1);
...submit yours body job ...
%chk(&run_macro_pre_post_code , 2);
Would you prefer make a slight change to your macro: %job_status:
%macro job_status(_status= , _jobname= );
%if &run_macro_pre_post_code ne Y %then %goto exit;
..... your macro code ....
%exit:
%mend job_status;
then just add per job
%let run_macro_pre_post_code= Y; /* or N */
Can you elaborate this statement ? What do you mean by executing the Job while it needs an update or enhancement ?
However I don't want this precode and postcode to execute when any of the ETL Job needs an update or enhancement
Assuming you are making changes to few jobs among the 100 jobs that you have , what is the difficulty in commenting the pre and post code for those few while testing?
Ideally, this type of features need to controlled via an external control tables where you have the full list of Jobs where you have set a Y/N flag to control a behavior for a particular Job.
@sas_savvy yes we can comment it but in the future we will be adding macros in pore/post code of each and every transformations like we did for Job pre/post code to capture the return code of the transformations in SQL table. In that case . it is not easy to comment the pre/post of every tansformation while I update and unit test any of the ETL Job.
If you can, please help me with the some example code which determine the way to accomplish it using external tables?
Changing macro job_status you need do once only.
Any time you recall the macro to run, in any job, it will use the new/updated macro.
Do you have already defined the statement
%let run_macro_pre_post_code=Y; /* or N */
in the jobs?
if positive then required work is done and no more changes need.
If negative then it depends on the tool you use to submit a set of ETL jobs.
Do you need the macro run_macro_pre_post_code assignment per job?
or per a run of all submitted jobs?
@Shmuel No, I don't have this statement defined in the job. But I can define it from Scheduler and so no changes are required in the job. As you told, I just have to change the macro definition %Job_status once.
%let run_macro_pre_post_code=Y;
Yes, I need the macro run_macro_pre_post_code assignment per Job.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.