I got following flagging issue:
%let max = 5;
%macro target_years(table);
data test ;
set work.&table;
%do i=1 %to &max;
%if i = &max %then %do;
%end;
%else %do;
"&&Zieljahre&i.._ZZ"n = 1-(1 ("&&Zieljahre&i.._BP_Garantiestand"n-"&&Zieljahre&i.._BP_Ziel_Garantiestand"n)/"&&Zieljahre&i.._BP_Ziel_Garantiestand"n);
%let x = "&&Zieljahre&i.._ZZ"n;
/*ZZ flag erstellen */
%if &x > 0 %then %do;
"&&Zieljahre&i.._ZZ_flag"n = ' ';
%end;
%else %do;
"&&Zieljahre&i.._ZZ_flag"n = '-';
%end;
%end;
%end;
run;
%mend;
%target_years(Kosten_temp)
Somehow all records are flagged with '-', the if condition with x doesn't work.
Can someone help me?
Many thanks in advance.
Kind regards, Ben
CodePudding user response:
You appear to mixing macro logic and data step logic.
You set the macro variable X to a string that starts with a "
and then test if it is larger than the string 0
. So that test is always going to be false since "
comes before 0
.
You probably want an actual IF statement there so you can test the value of the variable the previously generated SAS statement calculated.
%let max = 5;
%macro target_years(table);
%local i name ;
data test ;
set work.&table;
%do i=1 %to &max-1;
%let name = "&&Zieljahre&i.._ZZ"n;
&name = 1-(1 ("&&Zieljahre&i.._BP_Garantiestand"n-"&&Zieljahre&i.._BP_Ziel_Garantiestand"n)/"&&Zieljahre&i.._BP_Ziel_Garantiestand"n);
/*ZZ flag erstellen */
if &name > 0 then do;
"&&Zieljahre&i.._ZZ_flag"n = ' ';
end;
else do;
"&&Zieljahre&i.._ZZ_flag"n = '-';
end;
%end;
run;
%mend;