drop variables with same prefix

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 102
Accepted Solution

drop variables with same prefix

     hi i have 800+variables. some of the variables have CGOV as a common prefix. i wanted to drop all of them. how may i do this?

Many thx,

aaron


Accepted Solutions
Solution
‎03-14-2015 01:59 PM
Frequent Contributor
Posts: 115

Re: drop variables with same prefix

Try:

drop CGOV:  ;

View solution in original post


All Replies
Solution
‎03-14-2015 01:59 PM
Frequent Contributor
Posts: 115

Re: drop variables with same prefix

Try:

drop CGOV:  ;

Frequent Contributor
Posts: 102

Re: drop variables with same prefix

not working...get an error:

WARNING: The variable EC in the DROP, KEEP, or RENAME list has never been referenced.

Esteemed Advisor
Posts: 7,285

Re: drop variables with same prefix

EC?  Naveen suggested that you use drop CGOV: ;

Show your code.

Frequent Contributor
Posts: 115

Re: drop variables with same prefix

Can you please show your code that you used?

Frequent Contributor
Posts: 102

Re: drop variables with same prefix

oh. sorry. it works with the colon! this is very very helpful. thank you so much.

do u by any chance have an idea, how to drop the same suffixes? ie: _C.

i have variables that ends with _C: for example, xxx_C. how may i drop them?

thankyou!

Frequent Contributor
Posts: 102

Re: drop variables with same prefix

just along the lines, how may i rename those variables that ends with _C to without them?

ideally i would like, aaa_c->aaa

many thanks in advance!

Frequent Contributor
Posts: 115

Re: drop variables with same prefix

If all variables are in an order, you can prolly use

drop yourfirstvariable_C --yourlastvariable_C ;

Super User
Super User
Posts: 6,315

Re: drop variables with same prefix

Rename is similar to suffix.  You need to query the list of names.

proc contents data=have out=contents(keep=name) noprint ; run;

proc sql noprint ;

select catx('=',name,substr(name,1,length(name)-2))

   into :renames separated by ' '

from contents

where upcase(name) like '%^_C' escape '^'

;

quit;

data want ;

  set have (rename=(&renames));

run;

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 715 views
  • 4 likes
  • 4 in conversation