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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.