|
On Mon, Nov 17, 2008 at 1:30 PM, he.terry@gmail.com <he.terry@gmail.com> 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
%macro restrictdata(channelName=);
data out;
set in;
%if &channelName ^= %then %do;
where channel = "&channelName";
%end;
run;
%mend restrictdata;
%restrictdata(channelName=) would generate the data step
data out;
set in;
run;
%restrictdata(channelName=INTERNET) would generate the data step
data out;
set in;
where channel = "INTERNET";
run;
Example of conditional IF -
data grade;
set marks;
/* 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";
run;
Example of subsetting IF -
data grade;
set marks;
if science > 90; /* The dataset marks will only contain those
records where the value of the variable science was greater than 90.
*/
run;
Hope this helps.
Regards,
Anindya
--
Anindya Mozumdar
http://www.anindyamozumdar.com
|