BookmarkSubscribeRSS Feed
JP1234
Calcite | Level 5
 

data t1;

x=1;

y=2;

z=3;

 

w

u

v



label x="this is obsolete xx " y="this obsolete is yy" z="this is zz";

run;

 

data t1 has about 500 variables. about 100have 'obsolete' in their label like x and y.

How can I drop these varibles from t1 based on labels.

Jeff

2 REPLIES 2
Reeza
Super User

SASHELP.VCOLUMNS table has information on the variables, including labels. You can compile a list of variables that have the 'obsolete' in the label and use it to drop them. 

 

Make sure to put the name of the library and data set in upper case. 

 

proc sql noprint;
select name into :drop_list separated by " "
from sashelp.vcolumn
where upcase(libname)='WORK' and upcase(memname)='HAVE' and upcase(label) like '%OBSOLETE%';;
quit;


data want;
set have;

drop &drop_list;
run;

@JP1234 wrote:
 

data t1;

x=1;

y=2;

z=3;

 

w

u

v



label x="this is obsolete xx " y="this obsolete is yy" z="this is zz";

run;

 

data t1 has about 500 variables. about 100have 'obsolete' in their label like x and y.

How can I drop these varibles from t1 based on labels.

Jeff


 

r_behata
Barite | Level 11
data t1;
attrib x label="this is obsolete xx"
	   y label="this obsolete is yy"
	   z label="this is zz";
x=1;y=2;z=3;output;
run;

proc contents data=t1 out=tmp(keep=name label) nodetails noprint;
run;


Proc Sql noprint;
	Select name into :drp_lst separated by ','
		from tmp
	where findw(label,'obsolete');

alter table t1
drop &drp_lst;

quit;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 681 views
  • 2 likes
  • 3 in conversation