BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
aarony
Obsidian | Level 7

     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

1 ACCEPTED SOLUTION

Accepted Solutions
8 REPLIES 8
naveen_srini
Quartz | Level 8

Try:

drop CGOV:  ;

aarony
Obsidian | Level 7

not working...get an error:

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

art297
Opal | Level 21

EC?  Naveen suggested that you use drop CGOV: ;

Show your code.

naveen_srini
Quartz | Level 8

Can you please show your code that you used?

aarony
Obsidian | Level 7

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!

aarony
Obsidian | Level 7

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!

naveen_srini
Quartz | Level 8

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

drop yourfirstvariable_C --yourlastvariable_C ;

Tom
Super User Tom
Super User

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;

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 33428 views
  • 7 likes
  • 4 in conversation