BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Aexor
Lapis Lazuli | Level 10

I have a sample data like this:

Here invoice_dt is in format DDMMYYS10.;

Sale   invoice_dt

A      23/07/2018

B      01/07/2018

C      22/07/2018

D      04/03/2019

E      31/03/2019

R      31/07/2018

F       01/05/2018

I        10/07/2015

J       01/02/2014

 

I want to write a where condition in datastep to delete records  where invoice_dt is in between  01/07/2018 to 31/07/2018 and 01/03/2019 to 31/03/2019, 

 

Please help.

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Just look at the position of the marker in the log.

DELETE is a data step statement, not an option used in other statements.

Since you want to filter out observations, negate the conditions

where not ("firstdate"d le date le "lastdate"d) and not ("otherfirstdate"d le date le "otherlastdate"d);

If you have further trouble, post the complete log of the step into a window opened with this button:

Bildschirmfoto 2020-04-07 um 08.32.59.jpg

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

Date literals are specified in SAS in the form "ddmonyyyy"d, like

"23nov2021"d

So you can use a condition like 

"01jul2018"d le invoice_dt le "31jul2018"d

and combine multiple such conditions with OR

Aexor
Lapis Lazuli | Level 10
Thanks.

This is giving me syntax error

data new_del;
set test1;
where "01JUL2018"d ge invoice_dt le "31JUL2018"d and "01Mar2019"d ge invoice_dt le "31Mar2019"d delete ;
Kurt_Bremser
Super User

Just look at the position of the marker in the log.

DELETE is a data step statement, not an option used in other statements.

Since you want to filter out observations, negate the conditions

where not ("firstdate"d le date le "lastdate"d) and not ("otherfirstdate"d le date le "otherlastdate"d);

If you have further trouble, post the complete log of the step into a window opened with this button:

Bildschirmfoto 2020-04-07 um 08.32.59.jpg

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 3 replies
  • 363 views
  • 0 likes
  • 2 in conversation