BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
aarony
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

4 REPLIES 4
Anotherdream
Quartz | Level 8

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

aarony
Obsidian | Level 7

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.

Anotherdream
Quartz | Level 8

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;

Tom
Super User Tom
Super User

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 3730 views
  • 9 likes
  • 3 in conversation