DATA Step, Macro, Functions and more

macro %if condition %then action;

Reply
N/A
Posts: 0

macro %if condition %then action;

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
Super Contributor
Super Contributor
Posts: 3,174

Re: macro %if condition %then action;

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/
Respected Advisor
Posts: 3,887

Re: macro %if condition %then action;

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
Ask a Question
Discussion stats
  • 2 replies
  • 157 views
  • 0 likes
  • 3 in conversation