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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

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