On Mon, Nov 17, 2008 at 1:30 PM, email@example.com <firstname.lastname@example.org> wrote:
> When should I use %if? When should I use if?
%if should be generally be used when you are trying to control the
generated data step (or for that matter, any code) which should be
submitted to the SAS compiler. The IF statement should be used for
conditional processing or subsetting in a data step. Look at the
examples below -
Example of %if
%if &channelName ^= %then %do;
where channel = "&channelName";
%restrictdata(channelName=) would generate the data step
%restrictdata(channelName=INTERNET) would generate the data step
where channel = "INTERNET";
Example of conditional IF -
/* The variable grade takes a value depending on the value of the
variable science. A very simplistic example I know :) . */
if science > 90 then grade = "A";
else if science > 90 then grade = "B";
else grade = "C";
Example of subsetting IF -
if science > 90; /* The dataset marks will only contain those
records where the value of the variable science was greater than 90.
Hope this helps.