i have data with columns Names (win ,unix,sas,sep..etc) and data with yes and no. i want to delete the column without giving the column name.(ex: if sas column has all 'No' data).'
Thank you
Hello,
data have;
input col1 $ col2 $ col3 $;
cards;
Yes No No
No No Yes
Yes No Yes
;
run;
data NULL_;
set have end=eof;
array cols(*) col:;
array nos(3)_TEMPORARY_;
do i=1 to dim(cols);
if strip(cols(i))="No" then nos(i)+1;
end;
if eof then do;
call execute('data want; set have;');
if max(of nos(*))=_N_ then do;
call execute('drop');
do i=1 to dim(cols);
if nos(i)=_N_ then do;
call execute(vname(cols(i)));
end;
end;
end;
call execute('; run;');
end;
run;
Hello,
data have;
input col1 $ col2 $ col3 $;
cards;
Yes No No
No No Yes
Yes No Yes
;
run;
data NULL_;
set have end=eof;
array cols(*) col:;
array nos(3)_TEMPORARY_;
do i=1 to dim(cols);
if strip(cols(i))="No" then nos(i)+1;
end;
if eof then do;
call execute('data want; set have;');
if max(of nos(*))=_N_ then do;
call execute('drop');
do i=1 to dim(cols);
if nos(i)=_N_ then do;
call execute(vname(cols(i)));
end;
end;
end;
call execute('; run;');
end;
run;
Perfect. thanks a lot.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.