ccccaaarro
Programmer
Hello,
I'm writing a macro to delete column having too much missing. In the first, there is a count of missing for each variable. After if the count is greater than a level (x%. number of observation), the variable will be delete.
In my macro, the level condition seems to be always verified (miss_&var> %sysevalf(&level*symget('count'))). I don't understand why. Can somebody help me?
The script is following.
Regards,
Caro
%macro missing_column(dataset,varlist,varlistOUT,level=0.4);
%let i=1;
%let var=%scan(&varList, &i," ");
%do %while (&var ne %str());
%let i=%eval(&i.+1);
%let var=%scan(&varList, &i," ");
%end;
%put Nbr variables= %eval(&i-1);
data miss;
set &dataset;
call symput('count',_n_);
%do k=1 %to %eval(&i.-1);
%let var=%scan(&varList, &k," ");
%put 1: k= &k variable= &var;
retain miss_&var(0);
if missing(&var.) then miss_&var + 1;
%end;
run;
data miss2;
set miss end=fin;
if fin;
run;
data miss3;
set miss2;
%do k=1 %to %eval(&i.-1);
%let var=%scan(&varList, &k," ");
%put 2: ;
if miss_&var> %sysevalf(&level*symget('count')) then do;
%put 3: check;
drop &var;
end;
drop miss_&var;
%end;
run;
%put _user_;
%mend;
I'm writing a macro to delete column having too much missing. In the first, there is a count of missing for each variable. After if the count is greater than a level (x%. number of observation), the variable will be delete.
In my macro, the level condition seems to be always verified (miss_&var> %sysevalf(&level*symget('count'))). I don't understand why. Can somebody help me?
The script is following.
Regards,
Caro
%macro missing_column(dataset,varlist,varlistOUT,level=0.4);
%let i=1;
%let var=%scan(&varList, &i," ");
%do %while (&var ne %str());
%let i=%eval(&i.+1);
%let var=%scan(&varList, &i," ");
%end;
%put Nbr variables= %eval(&i-1);
data miss;
set &dataset;
call symput('count',_n_);
%do k=1 %to %eval(&i.-1);
%let var=%scan(&varList, &k," ");
%put 1: k= &k variable= &var;
retain miss_&var(0);
if missing(&var.) then miss_&var + 1;
%end;
run;
data miss2;
set miss end=fin;
if fin;
run;
data miss3;
set miss2;
%do k=1 %to %eval(&i.-1);
%let var=%scan(&varList, &k," ");
%put 2: ;
if miss_&var> %sysevalf(&level*symget('count')) then do;
%put 3: check;
drop &var;
end;
drop miss_&var;
%end;
run;
%put _user_;
%mend;