Hi,
I have a dataset containing two groups of experiment data and I want to decide if the result is positive based on different criteria. Below is my data:
data mydata;
input var1 var2 var3 var4 MFI_var5 MFI_var6 MFI_var7;
datalines;
4.2 1.8 0.3 . 30 15 10
0.7 0.8 3.3 . 80 20 .
;
run;
var1 - var4 came from experiment1, MFI_var5 - MFI_var7 came from experiment2 (they have prefix of MFI). The object is if the value of experiment1 > 1.5 then it is positive, while for experiment2 it needs to be greater than 15 to be positive. And I will create indicators, whose values are 0 or 1, showing if it is positive or not. Below is my code:
%MACRO mymacro(varLIST);
%local k a b;
DATA mydataout;
SET mydata;
%LET K=1;
%LET a=%SCAN(&varLIST,&K);
%LET b=%INDEX(&a,'MFI_');
%DO %WHILE (&a NE %STR() AND &b=0);
IF &a GE 1.5 THEN expt1_&a._pos = 1;
%LET K=%EVAL(&K+1);
%LET a=%SCAN(&varLIST,&K);
%LET b=%INDEX(&a,'MFI_');
%END;
%DO %WHILE (&a NE %STR() AND &b=1);
IF &a GT 15 THEN expt2_&a._pos = 1;
%LET K=%EVAL(&K+1);
%LET a=%SCAN(&varLIST,&K);
%LET b=%INDEX(&a,'MFI_');
%END;
RUN;
%MEND;
%mymacro(var1 var2 var3 var4 MFI_var5 MFI_var6 MFI_var7);
The positive indicators are expt1_varname_pos for experiment1, and expt2_varname_pos for experiment2, here varname are: var1 - var4 and MFI_var5 - MFI_var7, I would prefer not change the varname, just dump them in the middle. Since variables from experiment2 have prefix MFI, so I used %index function to look for if 'MFI' appear in variable, it came from experiment2 and the cut off point for positive would be 15, otherwise it is 1.5. So I want to my final report would be following:
var1 var2 var3 var4 MFI_var5 MFI_var6 MFI_var7 expt1_var1_pos expt1_var2_pos expt1_var3_pos expt1_var4_pos expt1_MFI_var5_pos expt1_MFI_var6_pos expt1_MFI_var7_pos
4.2 1.8 0.3 30 15 10 1 1 1
0.7 0.8 3.3 80 20 1 1 1
However, when I ran my macro, &b always be 0 and sas still use cut off of 1.5 instead of 15 for experiment2. It gave the following incorrect result:
var1 var2 var3 var4 MFI_var5 MFI_var6 MFI_var7 expt1_var1_pos expt1_var2_pos expt1_var3_pos expt1_var4_pos expt1_MFI_var5_pos expt1_MFI_var6_pos expt1_MFI_var7_pos
4.2 1.8 0.3 30 15 10 1 1 1 1 1
0.7 0.8 3.3 80 20 1 1 1
I have tons of such data so I prefer use macro to do this. Does anybody know why %index doesn't function here?
Thanks in advance,
Lu