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.
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;
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
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.
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;
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;
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.
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.