I tried to add one conditional macro inside one macro code, but when I check in the log I see that the macro has not executed.
Am I missing something in the code? I confirm that the macro %get_job_details has been created before this code and it's right.
%let function_compont=LDIS; %macro IFR_TABLE2DATASET; %if &function_compont. EQ LDIS %then %do; %get_job_details(_status=STARTED, _jobName=&etls_jobName1., _intbl=&file., _outlib_path=work, _outtbl=RISK_FACTOR ); %end; %else; %do; %get_job_details(_status=STARTED, _jobName=&etls_jobName1., _intbl=&file., _outlib_path=work, _outtbl=INSURANCE ); %end; %mend IFR_TABLE2DATASET; %IFR_TABLE2DATASET;
The semicolon after the %ELSE keyword ends the "else" branch right there, the following %DO-%END will always be executed.
Start simple: have %put statements in the macro branches to verify that the condition works; next do the same within the "inner" macro.
Add
options mlogic mprint symbolgen;
, run the macro again and post the log.
@Kurt_Bremser It didn't worked either:(
I placed the 'Options' as you suggested at the begining before rerun and the SAS program which I shown you in previous post is only the small portion which I want to add inside other macro.
Log snippet of the macro program is,
8973 %if &function_compont. EQ LDIS %then 8974 8975 %put #######function_compont=&function_compont.; 8976 %do; 8977 %get_job_audit(_status=STARTED, 8978 _jobName=&etls_jobName1., 8979 _inlib_path=/var/sasdata/ifrs17/san/ifr_transfer/SERVER/Input/&source_system_cd., 8980 _intbl=&file., 8981 _outlib_path=work, 8982 _outtbl=RISK_FACTOR 8983 ); 8984 %end; 8985 %else ERROR: There is no matching %IF statement for the %ELSE. ERROR: A dummy macro will be compiled. 8986 %do; 8987 %get_job_audit(_status=STARTED, 8988 _jobName=&etls_jobName1., 8989 _inlib_path=/var/sasdata/ifrs17/san/ifr_transfer/SERVER/Input/&source_system_cd., 8990 _intbl=&file., 8991 _outlib_path=work, 8992 _outtbl=INSURANCE 8993 ); 8994 %end;
The diagnostic %PUT statements have to be inserted at syntactically and semantically correct spots; your %PUT ends the %THEN branch, and therefore the whole %IF. Move the statement into the %DO-%END block.
You need to put the %PUT in the %DO loop sections so you can test your conditional logic.
Now you can track the loop behaviour exactly by checking the log and seeing which PUT statement gets printed out.
options mprint symbolgen;
%let function_compont = LDIS;
%if %function_compont. eq LDIS %then %do;
%PUT LOOP CONDITION 1;
%end;
%else %do;
%PUT LOOP CONDITION 2;
%end;
The issue with your code was originally stated by @Kurt_Bremser - you had a semi colon after your ELSE and still remains because of where you put the %PUT statement. The error below is telling you this as well, that your IF/ELSE is not correct. This causes your IF/THEN logic to finish early and both macro calls are executed. Putting the %PUT allows you to trace your code and see that both conditions are evaluated. It's not required but it shows you how to debug your own code quickly and to trace your logic in the future.
8985 %else ERROR: There is no matching %IF statement for the %ELSE. ERROR: A dummy macro will be compiled.
This is a good example of why I do not like placing the DO used to create a block in a branch of an IF/THEN/ELSE tree on a separate line.
If you adopt a coding style where you place those DO keywords on the same line as the THEN or ELSE instead you will be less tempted to add an extra semi-colons or any misplaced statements between the THEN/ELSE and the DO.
%macro IFR_TABLE2DATASET;
%if &function_compont. EQ LDIS %then %do;
%get_job_details
(_status=STARTED
,_jobName=&etls_jobName1.
,_intbl=&file.
,_outlib_path=work
,_outtbl=RISK_FACTOR
);
%end;
%else %do;
%get_job_details
(_status=STARTED
,_jobName=&etls_jobName1.
,_intbl=&file.
,_outlib_path=work
,_outtbl=INSURANCE
);
%end;
%mend IFR_TABLE2DATASET;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Lock in the best rate now before the price increases on April 1.
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.
Ready to level-up your skills? Choose your own adventure.