DATA Step, Macro, Functions and more

How to drop variables if variables' name contain certain character

Reply
Super Contributor
Posts: 503

How to drop variables if variables' name contain certain character

Hi Everyone,

So I have a long list of variables and I only want to keep (or drop) all variables with "Jan" or "jan".

Any help is very much appreciated.

HHC

 

data have;
input Jan1 _1_jan Feb March_ ;
datalines;
1 0 0 0
2 1 1 1
;run;

Respected Advisor
Posts: 2,647

Re: How to drop variables if variables' name contain certain character

[ Edited ]

UNTESTED CODE

 

proc sql;
     select distinct name into :names separated by ' ' from dictionary.columns where upcase(memname)='HAVE' and upcase(libname)='WORK'
and upcase(name)?'JAN'; quit; data want;
set have (drop=&names); /* OR set have (keep=&names); */
run;
--
Paige Miller
Ask a Question
Discussion stats
  • 1 reply
  • 123 views
  • 0 likes
  • 2 in conversation