DATA Step, Macro, Functions and more

Dropping variables with wildcard in Data Step

Reply
N/A
Posts: 0

Dropping variables with wildcard in Data Step

In Stata, if I want to drop variables before merging that all have an "h1" root, I would type:

drop h1*

Stata drops all variables beginning with "h1", no matter what order they are in.

In SAS, I try:

data temp (drop=h1*);

SAS does not recognize the wildcard. What is the proper way to do this?

Thanks

Paul
Super Contributor
Super Contributor
Posts: 3,174

Re: Dropping variables with wildcard in Data Step

Posted in reply to deleted_user
Use the colon character with SAS to specify a variable root / prefix.

Scott Barry
SBBWorks, Inc.
N/A
Posts: 0

Re: Dropping variables with wildcard in Data Step

Posted in reply to deleted_user
Thanks. Is there an example of this in the documentation somewhere?

P
Super User
Posts: 5,424

Re: Dropping variables with wildcard in Data Step

Posted in reply to deleted_user
(drop=h1Smiley Happy

/Linus
Data never sleeps
N/A
Posts: 0

Re: Dropping variables with wildcard in Data Step

Thanks. The only things I could find about wildcards in the documentation referred to "*" and "%".

P
N/A
Posts: 0

Re: Dropping variables with wildcard in Data Step

Posted in reply to deleted_user
Hi,

it looks very easy, but...

Is there any way to drop the variables ENDING with some pattern? (Or more: variables that contain some pattern).

I've tried with

DROP=:h1

but it doesn't work. I could manage that using PROC CONTENTS and macrovariables, but I hope to find some more clear solution. Is there any?

Thanks
Jaroslav
Super User
Posts: 5,424

Re: Dropping variables with wildcard in Data Step

Posted in reply to deleted_user
There is no direct support for this in data step syntax (to my knowledge). But it doesn't have to be complicated. Try using sql with dictionary.columns to create a variable list using INTO and SEPARATED BY. See an example from this SUGI paper:

http://www2.sas.com/proceedings/sugi30/057-30.pdf

Regards,
Linus
Data never sleeps
Respected Advisor
Posts: 4,173

Re: Dropping variables with wildcard in Data Step

Have a look at this thread. It might give you an idea how to query the dictionary table and find vars with a certain pattern.
HTH
Patrick

Ooops... Somehow the link got "lost": http://support.sas.com/forums/thread.jspa?messageID=14275㟃 Message was edited by: Patrick
Frequent Contributor
Posts: 139

Re: Dropping variables with wildcard in Data Step

Posted in reply to deleted_user
In the online documentation go to SAS Variables; SAS Variable Lists
Ask a Question
Discussion stats
  • 8 replies
  • 9194 views
  • 2 likes
  • 5 in conversation