Help using Base SAS procedures

delete observations

Reply
Regular Contributor
Posts: 161

delete observations

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

Super Contributor
Posts: 1,636

Re: delete observations

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;

Super Contributor
Posts: 1,636

Re: delete observations

Hi Karun,

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

Linlin

Super Contributor
Posts: 1,636

Re: delete observations

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

Super Contributor
Posts: 1,636

Re: delete observations

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

Super Contributor
Posts: 1,040

Re: delete observations

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

Super User
Super User
Posts: 6,495

Re: delete observations

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;

New Contributor
Posts: 2

Re: delete observations

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;

Occasional Contributor
Posts: 14

Re: delete observations

proc sql; create table res as ( select dt from hello where input(substr(dt,length(dt)-1),2.) >10 ); run;

Ask a Question
Discussion stats
  • 8 replies
  • 363 views
  • 2 likes
  • 6 in conversation