DATA Step, Macro, Functions and more

Multiple Code Execution

Reply
Contributor
Posts: 63

Multiple Code Execution

Hello,

 

I have a code, that executes multiple codes based on the code frequency.

For example,

if the code "A" frequency is daily, then it will be executed Daily

If code "B" frequency is weekly then it will be executed weekly.

 

There are 12 codes, out of which

Daily    -   5

Weekly -  4

Monthly - 3

 

My current situation  is, if there is one code fails, then SAS stops executing the rest of the code.

I want to change it, so that even if one rule fails, SAS should execute the rest of the code and produce output , and a notification should be sent informing which code failed.

 

Sample Code:

 


libname test  "/data/DEV/SYS";

%let RUNDATE = &SYSDATE9;
%put &rundate.;

%put %sysfunc(weekday("&RUNDATE."d));
%put %sysfunc(day("&RUNDATE."d));

PROC PRINTTO LOG=LOG; RUN;

%macro run_code(frequency, file_name, output_file);
 %let file_path = /data/DEV/SYS/CODE;

 %if ("&frequency." = "Daily")
  or ("&frequency." = "Weekly" and %sysfunc(weekday("&RUNDATE."d))=1)
  or ("&frequency" = "Monthly" and %sysfunc(day("&RUNDATE."d))=6) %then %do;

  %include "&file_path./&file_name.";
  %put "&frequency.";
  %put "&file_path./&file_name.";

  data results;
   set results test.&output_file. (keep= Name Description Country State);
  run;
 %end;
%mend run_code;

data results;
 set _NULL_;
run;

data _NULL_;
 set test.rule_input;
 call execute ('%run_code('||TRIM(Frequency)||','||TRIM(SASFILE)||','||TRIM(output_file)||')');
run;

proc format;
picture date_b_fmt(default=45)
low-high='%Y-%0m-%0d %0H:%0M:%0S'(datatype=datetime);
run;

data test.ALLCust_&RUNDATE.;
set results;
format run_date date_b_fmt.;
format rundate1 date9.;
Run_date=datetime();
Rundate1=today();
run;

 

/*END OF CODE*/

Super User
Posts: 3,256

Re: Multiple Code Execution

Posted in reply to arunasaran

I'm guessing that your code is running with the SAS option SYNTAXCHECK. Trying NOSYNTAXCHECK may give you the behaviour you want.

 

http://documentation.sas.com/?docsetId=lesysoptsref&docsetTarget=n014qbvh3po8w5n1qlqbzr22vtg0.htm&do...

 

Rather than controlling your SAS programs using SAS, using a scheduling tool would allow you to have better control as well as automatically emailing if there is a problem.

Contributor
Posts: 63

Re: Multiple Code Execution

hi SASKIWI.

 

thank you for the reply.

 

can u guide be about the scheduling tools,

 

Regards,

Aruna B

Super User
Posts: 3,256

Re: Multiple Code Execution

Posted in reply to arunasaran

The SAS Scheduling guide is a good place to start:

 

http://documentation.sas.com/?docsetId=scheduleug&docsetTarget=n1c1fie1vigujin12wrepb4kdq87.htm&docs...

 

I would also check with your IT folks regarding any tools used currently.

Contributor
Posts: 63

Re: Multiple Code Execution

 Hi All,

 

The viable option is to schedule the code individually, so that one code failure will not affect the others.

 

Moving on to the next request, Once all the codes are executed, all their output datasets needs to get appended to one dataset.

Now, the same scenario, if any one of the output is not available the entire appending will not work, I need  a solution so that even any one or two output dataset  is not available, the other output datasets should get appended.

 

Regards,

Ar

Ask a Question
Discussion stats
  • 4 replies
  • 90 views
  • 0 likes
  • 2 in conversation