BookmarkSubscribeRSS Feed
tparvaiz
Obsidian | Level 7

Hi

 

I need to delete records from table temp_weekly_data where the date is less than today and status is equal to A

 

following code is deleting records where the date is less than today(), ignoring if the staus value

 

data temp_weekly_data;
set DB.TABLE(where = (&date1 <= date_my < &date2 ) );

if status in ("A") and datepart(date_my) < today() then delete;

run;

 

staus field is of type Text, 10 character length

 

Thanks in advance

2 REPLIES 2
Shmuel
Garnet | Level 18

Your code should work fine only in case status is always in capital letter.

Are &date1 and &date2 given as datetime or date only ?

Are your where consistent with the IF statement ? (either date variable or datetime variable)

 

You may test:

data temp_weekly_data;
   set DB.TABLE(where = (&date1 <= date_my < &date2 ) );
       if upcase(status) = "A"  
         and datepart(date_my) < today() then delete;
run;
art297
Opal | Level 21

You mentioned that status is a 10 character length field. Are you possibly wanting to delete a record if its status field contains an "A"? If so, you could use:

data db.table;
  informat status $10.;
  length status $10;
  input status;
  cards;
A
BC
 A
ABC
BCD
;

data temp_weekly_data;
  set DB.TABLE (where = (&date1 <= date_my < &date2 ) );
  if find(status,"A") and datepart(date_my) < today() then delete;
run;

Art, CEO, AnalystFinder.com

 

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!

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