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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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