BookmarkSubscribeRSS Feed
Sandy10
Calcite | Level 5

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

1 REPLY 1
JohnHoughton
Quartz | Level 8

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"

 

 

 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 982 views
  • 0 likes
  • 2 in conversation