BookmarkSubscribeRSS Feed
R_A_G_
Calcite | Level 5

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

8 REPLIES 8
Linlin
Lapis Lazuli | Level 10

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;

Linlin
Lapis Lazuli | Level 10

Hi Karun,

-1 means taking the last two characters of a string.

Linlin

Linlin
Lapis Lazuli | Level 10

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

Linlin
Lapis Lazuli | Level 10

last_four= substr(your_var,length(your_var)-3);

robertrao
Quartz | Level 8

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

Tom
Super User Tom
Super User

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;

Bayes
Calcite | Level 5

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;

NagendraKumarK
Calcite | Level 5

proc sql; create table res as ( select dt from hello where input(substr(dt,length(dt)-1),2.) >10 ); 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
  • 8 replies
  • 1478 views
  • 2 likes
  • 6 in conversation