The goal is to use if statement to create multiple columns in output table. I am trying to avoid using case when, because in practice 8 or 9 outputs depends on one condition, using case when will increase the complexity of my code.
I am new to SAS, following is my code, but it is not working.
%macro DPAPRDT:
proc sql;
execute(
create table test as (
%IF table2.A < table2.C and table2.A > table3.D
%then
%do
select table1.A,
table1.B,
table2.D,
table2.E,
table2.F,
%else
%do
select table1.A,
table1.B,
table3.D,
table3.E,
table3.F
%end;
from table1
join table2 on ...
join table3 on ...
WITH DATA PRIMARY INDEX (table1.A, table1.B)
%mend DPAPRDT;
So far I have 3 error code as:
ERROR: Expected semicolon not found. The macro will not be compiled.
ERROR: A dummy macro will be compiled.
ERROR: Expected %TO not found in %DO statement.
Without using Macros, the solution is:
proc sql;
execute(
create table test as (
select table1.A,
table1.B,
case when table2.A < table2.C and table2.A > table3.D
then table2.D else table3.D end as return1,
case when table2.A < table2.C and table2.A > table3.D
then table2.E else table3.E end as return2,
case when table2.A < table2.C and table2.A ..
case when table2.A < table2.C and table2.A ..
.
.
.
from table1
join table2 on ...
join table3 on ...
)WITH DATA PRIMARY INDEX (table1.A, table1.B)
end;
I have to use case when more than 10 time with the same condition
%if (&MIN <= &A) and (&A <= &MAX) %then %do; ... actual sas code to generate goes here .. %end;