Hi,
I posted it yesterday and got some valuable feedback, but it wasn’t what I want. Sorry to bother again. Below is my mini-version data:
data mydata;
input var1 var1_suffix var2 var2_suffix var3 var3_suffix var4 var4_suffix var5 var5_suffix;
datalines;
4.2 1 1.8 0 2.3 0 3.5 0 2.3 1
3 0 2.5 0 5.2 1 6.4 0 2.4 0
3.1 0 6.7 0 5.1 1 3 0 4 0
;
run;
var1 through var5 are five variables of interest. var1_suffix through var5_suffix are corresponding indicators which take values of 0 or 1. If its value=1, then I want set the corresponding variable value to missing. For example, var1=4.2 and var1_suffix=1 so I will change the value of var1 to missing, the result should be var1=. and var1_suffix=1. I wrote a macro to do this:
%MACRO mymacro(varLIST);
DATA mydataout;
SET mydata;
%LET K=1;
%LET a=%SCAN(&varLIST,&K);
%DO %WHILE("a" NE "");
%IF &a._suffix=1 %THEN &a=.;
%LET K=%EVAL(&K+1);
%LET a=%SCAN(&varLIST,&K);
%END;
RUN;
%MEND;
%mymacro(var1 var2 var3 var4 var5);
In fact I have lots of variables(could be var1 to varn), and so var_suffix, that's why I prefer using macro program, cause it is hard to calculate the total number of variables and the total varies everytime I run it. Also, var_suffix is named exactly start with var(i) and followed by _suffix.
Thanks,
Lu
... View more