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

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

Thanks. Is there an example of this in the documentation somewhere?

P
Super User
Posts: 5,260

Re: Dropping variables with wildcard in Data Step

(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

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,260

Re: Dropping variables with wildcard in Data Step

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: 3,899

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

In the online documentation go to SAS Variables; SAS Variable Lists
Ask a Question
Discussion stats
  • 8 replies
  • 8552 views
  • 0 likes
  • 5 in conversation