BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi Guys,

I have a question regarding SAS macro %IF %Then Syntax;

I know %If condition %then action; works

but once I have mutiple if within if/elseif,

do i have to have add %do; and %End; ?

I am converting access macro code into sas macro,
so i prefer not to add the %do & %end

Thanks,

The following is my macro,

and I have error

ERROR: There is no matching %IF statement for the %ELSE. A dummy macro will be compiled.




%Macro PoolAdj(effdate= ,State= ,Lives= );
%let PoolAdj = 1;

%IF &effdate ^= "?" %then
%IF &state ^= "FL" And &state ^= "NY" %then

%IF &effdate > '06Jun2004' %then
%IF &lives < 10 %then
&PoolAdj = &PoolAdj * 1;
%else %if &lives < 500 %then
&PoolAdj = &PoolAdj * 0.95;
%else
&PoolAdj = &PoolAdj * 0.97;
;

%else %if &effdate > '09May2002' %then
%IF &lives < 10 %then
&PoolAdj = &PoolAdj * 1;
%else %if &lives < 500 %then
&PoolAdj = &PoolAdj * 0.95;
%else
&PoolAdj = &PoolAdj * 0.97;
;
;
;


%Mend PoolAdj; Message was edited by: fortrichmond
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Yes, multiple-statement logic within a defined %IF construct requires a %DO and a %END structure.

Have a look at the SAS-hosted documentation on the MACRO language logic at the link below.

Scott Barry
SBBWorks, Inc.

http://support.sas.com/documentation/cdl/en/mcrolref/59526/HTML/default/a001037922.htm

SAS Support hosted prod documentation:

http://support.sas.com/documentation/
Patrick
Opal | Level 21
I think the only problem with this code is exactly what the error message expresses.
There is no matching '%if' case for the '%else' case.

.....
%else
&PoolAdj = &PoolAdj * 0.97;
;
%else %if &effdate > '09May2002' %then
....

Formulate it this way and it should work:
.....
%else
&PoolAdj = &PoolAdj * 0.97;
;
%if &effdate > '09May2002' %then
....

As all conditions are on the same level you will have to check that the %if statements are exclusive to each other or your logic will be flawed.

From a programming perspective I consider a %do...%end structure as easier to read and maintain.

HTH
Patrick

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 2 replies
  • 2542 views
  • 0 likes
  • 3 in conversation