Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete column with too much missing?

Status
Not open for further replies.

ccccaaarro

Programmer
Aug 12, 2008
1
BE
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;

 
A tricky one.
I would suggest adding the following

put miss_&var;
put &level;
put symget('count');

before the line
if miss_&var> %sysevalf(&level*symget('count')) then do;

to see what you get.
That'll help check to see if one of those values is not coming through correctly.

Looks like it might be a good handy little macro for analysis purposes. Another suggestion I'd make is to add some comments into it at each stage giving a brief explanation of what it's doing.
For debugging purposes that helps us to see if it is actually doing what you want it to do, for you it helps when you come back to it several months later.


Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top