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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 15733 views
  • 2 likes
  • 5 in conversation