Hi:
Art is right -- if you want to generate a DATA step IF statement, then you do not want to replace it with a Macro %IF statement. In addition, if your original IF statement was:
[pre]
IF I le 34 and IRS_AREA = ('AS1')
[/pre]
...then this is the IF statement you need to generate. Let's say that you have a macro variable to substitute for the 34 (&NUM) and another macro variable to substitute fors the AS1 value (&IRS_AREA). Then you would have something like this:
[pre]
IF I le &NUM and IRS_AREA = ("&IRS_AREA")
[/pre]
In the above IF statement, at compile time, the value specified for &NUM will be substituted into the IF statement as a numeric constant. Then, because IRS_AREA (the dataset variable is character) in your comparison, it MUST be in quotes for the comparison to work (in DATA step syntax), so you will need to surround the macro variable reference for &IRS_AREA with double quotes so the macro variable reference will resolve.
This is a good paper with an overview of how you start with a working program and then turn it into a macro program, including macro logic:
http://www2.sas.com/proceedings/sugi28/056-28.pdf
I am, however, not quite clear on what the purpose of your macro program is.... or why simple macro variables (instead of a macro program) wouldn't work in this instance. I'm guessing you want to be able to change the value for &NUM/&I and the value for &IRS_AREA in order to have a more generic DATA step program. Also, not clear to me is why you are using %LET, which will only resolve at macro compile time.
Perhaps if you read the above paper and then Google for more papers on Macro processing (especially ones written by the most excellent macro guru, Art Carpenter), you will have a better idea of how macro variables and macro programs and macro %IF work and how they are different from a regular DATA step IF statement. For example, consider this simple macro program:
[pre]
** build IF statement that will be resolved at compile time and
** inserted into the DATA step program;
%macro wantclass(want=, get=);
** NUM and SEX are DATASET variables;
** &WANT and &GET are MACRO variables;
if sex = "&want" and num le &get then do;
%if &want = F %then %do;
newvar = 'FFFFF';
%end;
%else %if &want = M %then %do;
newvar = 'MMMMM';
%end;
output;
num = num + 1;
end;
%mend wantclass;
** Test the macro program with F and 3;
data classF;
set sashelp.class;
retain num 1;
if age le 15 then do;
%wantclass(want=F, get=3)
end;
run;
proc print data=classF;
title "1) Data in Work.ClassF";
run;
** Now run for Males and 4;
data classM;
set sashelp.class;
retain num 1;
if age le 15 then do;
%wantclass(want=M, get=4)
end;
run;
proc print data=classM;
title "2) Data in Work.ClassM";
run;
[/pre]
The purpose of the %WANTCLASS macro program is just to generate an IF statement -- in this context, a macro program for a single IF statement is sort of overkill, but consider how the IF statement will be changed by my 2 separate invocations. When I create the CLASSF dataset, I pass the macro program want=F and get=3; then when I create the CLASSM dataset, I pass the macro program want=M and get=4. Note that &WANT and &GET are macro variables that will be resolved at when the macro tokenizer scans and resolves all macro references. On the other hand, SEX and NUM are DATA step variables -- they either come from my dataset (SEX) or I am creating it in my program (NUM) for the purpose of controlling the condition and number of obs for output.
Particularly, study the difference between the "regular" IF statement -- that is responsible for the OUTPUT and the %IF statement that is being used to create a new dataset variable called NEWVAR. The way the %IF statement works is that SAS will resolve the value of &WANT and will write out either NEWVAR='FFFFF'; or NEWVAR='MMMMM'; By the time the compiler gets the code, it will only see the assignment statement because the %IF statement will no longer be in the code.
As I said, I think the design of your program needs some rethinking based on an clear understanding of how macro programs and macro variables work. I always compare the macro process to a big, but invisible, typewriter. Every time the macro processor sees a reference to &WANT, it will type the current value of &WANT into whatever code is being generated. But that's all the macro processor is -- a big, invisible typewriter.
cynthia