Hi,
CHECKMASTER is a work table which contains attached data. I want to execute the SH jobs one by one in a loop through a table when val = 0 and runstatus = N . Then I want to set the runstatus as 'P' using update_status macro.
But the condition is always false . Also, I am not too sure if my call execute statement to include a sas code is correct .
Kindly advise why the condition is always false and if my call execute statement to include a sas code is correct
I am using LINUX Environment . SAS Version is 4.4 .
Below is the code:
%macro update_status(status=);
proc sql;
update exeng.EngineExecution set runstatus="&status"
where JobName=compress("&&jobs&cnt_h");
quit;
%mend update_status;
%macro jobex;
%let path=/app/scripts/batch;
%let extn=sh;
%global cnt_h;
%global jobs;
proc sql;
select count(jobname) into :cnt_h separated by ' ' from CHECK_MASTER ;
select jobname into :jobs1-:jobs%left(&cnt_h) from CHECK_MASTER;
quit;
data _null_;
set work.CHECK_MASTER;
/*call symputx ("val",val);*/
/*call symputx ("runstatus",runstatus);*/
%do i=1 %to &cnt_h;
%if ((val=0) AND (Runstatus = 'F' or RUNSTATUS='N' )) %then %do;
call execute('%include "&path./&&jobs&i...&extn"');
/*x "&path/&&jobs&i...&extn";*/
status="P";
%update_status(status);
%end;x
%end;
run;
%mend jobex;
%jobex;
Log:
MPRINT(JOBEX): data _null_;
MPRINT(JOBEX): set work.CHECK_MASTER;
SYMBOLGEN: Macro variable CNT_H resolves to 9
MLOGIC(JOBEX): %DO loop beginning; index variable I; start value is 1; stop value is 9; by value is 1.
MLOGIC(JOBEX): %IF condition ((val=0) AND (Runstatus = 'F' or RUNSTATUS='N' )) is FALSE
Thanks,
Sandhya S
Hi Sandy10
"Kindly advise why the condition is always false ..."
Your condition is ...
%if ((val=0) AND (Runstatus = 'F' or RUNSTATUS='N' )) %then %do;
... and this is always false because we have to use macro variables in a %if-%else statement, and cannot use data step variables. Val and Runstatus are both data step variables.
You could avoid using macros with the call execute; see @Kurt_Bremser maxim#11 and the sas blog "CALL EXECUTE made easy for SAS data-driven programming"
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.