DATA Step, Macro, Functions and more

Query in macro and call execute

Reply
Contributor
Posts: 40

Query in macro and call execute

[ Edited ]

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

Contributor
Posts: 62

Re: Query in macro and call execute

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 @KurtBremser maxim#11 and the sas blog "CALL EXECUTE made easy for SAS data-driven programming"

 

 

 

Ask a Question
Discussion stats
  • 1 reply
  • 70 views
  • 0 likes
  • 2 in conversation