BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
8 REPLIES 8
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Use the colon character with SAS to specify a variable root / prefix.

Scott Barry
SBBWorks, Inc.
deleted_user
Not applicable
Thanks. Is there an example of this in the documentation somewhere?

P
LinusH
Tourmaline | Level 20
(drop=h1:)

/Linus
Data never sleeps
deleted_user
Not applicable
Thanks. The only things I could find about wildcards in the documentation referred to "*" and "%".

P
deleted_user
Not applicable
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
LinusH
Tourmaline | Level 20
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
Patrick
Opal | Level 21
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
darrylovia
Quartz | Level 8
In the online documentation go to SAS Variables; SAS Variable Lists

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 17678 views
  • 2 likes
  • 5 in conversation