I have inherited macro in which the below block does not seem to be resolved. The macro is supposed to conditionally select the logical operations based on the date values. If the %if conditions are satisfied, they should print the macro variables mentioned in the %put statement, which in-turn become part of the if condition. If the condition %if %length(&datein.)=10 OR %length(ST_&date.)=10 is satisfied, it would print the first %put statement else the second %put statement would be printed. Same logic applies to the second %if statement.
The macro is supposed to be run inside a data step. The logical operator AND is being considered as a variable and I'm getting a note NOTE: Variable AND is uninitialized.
I tried to balance the if condition by adding the open and closed parenthesis mentioned in below code. Tried to change the structure of the if condition to separate the first and the second condition, but doesn't seem to work. I assuming that the logical operator AND cannot be used as it is in the %if %then %else statement.
%macro test_date(date=, comp1=, comp2=, label=);
if &datein. ne "" and ST_&date. ne "" then do;
if (%if %length(&datein.)=10 OR %length(ST_&date.)=10 %then %put ST_&date._10 &comp1. datein_10; %else %put ST_&date._19 &comp1. datein_19;
AND %if %length(&datein.)=10 OR %length(ED_&date.)=10 %then %put datein_10 &comp2. ED_&date._10; %else %put datein_19 &comp2. ED_&date._19;)
then EPOCH=&label.;
end;
%mend test_date;
%test_date(date=SCREEN, comp1= le, comp2= le, label='SCREEN');
if
,then
,else
andepoch
(instead of%if
,%then
,%else
and%let epoch
), so i assume it is supposed to run in a data step? The stuff in the inner if writes to the log and will not resolve to true or false when the data step runs.And
can't be first in a statement.ST_&date
seems to be data step variable in the outer if and a string in the inner one. What is this supposed to do? - RuneS