BookmarkSubscribeRSS Feed
David_Billa
Rhodochrosite | Level 12

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;
7 REPLIES 7
Kurt_Bremser
Super User

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.

David_Billa
Rhodochrosite | Level 12

@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;

 

Kurt_Bremser
Super User

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.

Reeza
Super User

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;
David_Billa
Rhodochrosite | Level 12
Sure. I don't have access to SAS at the moment.

What would be the likely cause for the issue?
Reeza
Super User

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.

 

Tom
Super User Tom
Super User

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;

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 593 views
  • 3 likes
  • 4 in conversation