DATA Step, Macro, Functions and more

delete blank columns

Reply
Super Contributor
Posts: 318

delete blank columns

hello

i have a data set containing columns x y z. data set contains 10 records. i want to check if x has a value for each observation. however if all 10 records have a value of missing or 0 in x, i want to delete the column x. how can i do that?

thanks!
N/A
Posts: 0

Re: delete blank columns

Hi,

For this we need to run PROC MEANS with (N NMISS MIN MAX) on the data first to identify those variables having missing values or zero's.
After this we can drop those variables whose N=NMISS or (MIN=0 and MAX=0) by using DROP or KEEP.

Hope this will help you
Frequent Contributor
Posts: 91

Re: delete blank columns

if you are generating this table in a data step, you could create a retained variable to count the number of time that x is missing and then on the last observation, compare that variable with _n_ and if they are equal conditionally execute a data step to drop that variable...like:
data xyz;
set abc(keep=x y z) end=lastone;
retain x_missing 0;
x_missing = x_missing + missing(x);
if lastone then do;
if x_missing = _n_ then call execute('data def;set xyz(keep=y z);run;');
end;
run;
Super Contributor
Posts: 318

Re: delete blank columns

i see. thanks a lot for the help !
N/A
Posts: 0

Re: delete blank columns

Try this


data d1;
set s1;
if x=y=z then flag='v';
run;

data d2;
set d1;
if flag ne 'v' then delete;
run;
Ask a Question
Discussion stats
  • 4 replies
  • 303 views
  • 0 likes
  • 3 in conversation