Hello,
I have a data set to clean up.
I need to delete rows with dates that end with 00-10
the date column looks like this:
Date
1999010100
1999010101
1999010102
.
. .
.
2012010100
2012010101
2012010102
.
.
.
thank you
assuming you want to delete date end with '00' and '10':
data have;
input date;
cards;
1999010120
1999020510
1999080800
;
data want;
set have;
if substr(date,length(date)-1) in ('00','10') then delete;
proc print;run;
Hi Karun,
-1 means taking the last two characters of a string.
Linlin
Please take a look at the example below:
data have;
input var $;
cards;
adb
bbcd
bdscv
1234567
;
data want;
set have;
n=length(var);
from=n-1;
to=2;
new1=substr(var,from,to);
/* we could combine the above four lines as:*/
new2=substr(var,length(var)-1);
proc print;run;
Obs var n from to new1 new2
1 adb 3 2 2 db db
2 bbcd 4 3 2 cd cd
3 bdscv 5 4 2 cv cv
4 1234567 7 6 2 67 67
last_four= substr(your_var,length(your_var)-3);
I want to put as Helpful answer even though the question was asked by someone else...Would it not allow me to do that???
Regards
The data you have listed do not look like dates. They look like they might be dates in YYYYMMDD format but with an additional two digits appended.
If you did have dates like 19990101 and wanted to delete dates with the day value between 1 and 10 then you could use the DAY() function.
if 1 <= day(DATEVAR) <= 10 then delete.
If you have read this value as a number (that is 1999010101 has been read as the number 1,999,010,101) then look at using the MOD() function to find the two least significant digits.
if 1 <= mod(DATELIKEVAR,100) <= 10 then delete;
proc sql noprint;
delete from have where prxmatch('/0[01]$/', Date);
quit;
or
data want;
set have;
if prxmatch('/0[01]$/', Date) > 0 then delete;
run;
proc sql; create table res as ( select dt from hello where input(substr(dt,length(dt)-1),2.) >10 ); run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: