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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.