Help using Base SAS procedures

drop variable if the variable starts with 60

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 102
Accepted Solution

drop variable if the variable starts with 60

hi i have a dataset with a column ticker

ticker

941

60941

70

6070

i want to drop the rows that start with '60'

how may i apporach this? thank you.


Accepted Solutions
Solution
‎04-23-2014 05:29 PM
Super User
Super User
Posts: 7,039

Re: drop variable if the variable starts with 60

As long as TICKER is a character variable and you don't want to use SQL then it is really easy.

data have ;

input ticker $10. ;

cards;

941

60941

70

6070

run;

data want ;

set have ;

where ticker ^=: '60';

put ticker=;

run

View solution in original post


All Replies
Super Contributor
Posts: 418

Re: drop variable if the variable starts with 60

If your variable is varchar than you can use a simple "substr" function.

data want

set have;

where substr(name,1,2)~='60';

run;

If its a numeric, you will have to use a put option to convert it before using the substr (there are lots of other ways I imagine. this is more of a beginner method).

data want;

set have;

where substr(strip(put(name,32.)),1,2)~='60';

run;

Just a note, but I would actually use a where clause

Frequent Contributor
Posts: 102

Re: drop variable if the variable starts with 60

for some strange reason it is not working.

there are ticker with

60001

60002

1

2

260

2600

i just want to drop the ones that start with 60 and still keep the ones with 260 and 2600.

Super Contributor
Posts: 418

Re: drop variable if the variable starts with 60

You'd have to re-point the column to your actual column (ticker. I used a made up column called "name").  so just replace "name" with "ticker". I redid it for you below if you are wondering.

Varchar

data want

set have;

where substr(ticker,1,2)~='60';

run;

Numeric

data want;

set have;

where substr(strip(put(ticker,32.)),1,2)~='60';

run;

Solution
‎04-23-2014 05:29 PM
Super User
Super User
Posts: 7,039

Re: drop variable if the variable starts with 60

As long as TICKER is a character variable and you don't want to use SQL then it is really easy.

data have ;

input ticker $10. ;

cards;

941

60941

70

6070

run;

data want ;

set have ;

where ticker ^=: '60';

put ticker=;

run

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 229 views
  • 7 likes
  • 3 in conversation