|
> From: Rick Kim
> In SAS, we have
>
> IF expression THEN statement1 ;
> ELSE statement2 ;
>
> For instance:
> if max(a)<20 then p=0;
> else p=1;
>
> My question is what if I need to put more than one statement
> after If expression, like:
>
> if max(a)<20 then p=0 q=5;
> else p=1;
>
> Is there a way to achieve this?
you can stack as many else-if as you want:
if max(a)<20 then p=0;
else if max(a)<30 then p=0.5;
else p=1;
this eventually leads to wallpaper code;
better to use a format
proc format max 0-20 = 0
21-30 = 0.5
31-hi = 1;
Data X;
*...;
p = put(Max(A),max.);
also consider the alternate case structure;
maxA = max(a);
select(maxA);
when(<20) p=0;
when(<30) p=0.5;
otherwise p=1;end;
Ron Fehd the macro maven CDC Atlanta GA USA RJF2 at cdc dot gov
Efficiency is intelligent laziness. -David Dunham
... or use of formats
|