BookmarkSubscribeRSS Feed
Hema_12
Fluorite | Level 6

Hi All,

 

query;- i need to delete the rows which are older than 10 days and set id=1 with auto increment value.

database is teradata;

please suggest  possible solutions.

Thanks in advance.

🙂

i have written this piece of code

------------------------------------------

 

options mprint mlogic symbolgen;
%macro clean;
data one;
set work.process_cleanup;
today= today();
/*max_date=max(start_datetime);*/
max_date_1=datepart(start_datetime);
/*seven_date=intnx('day',today,-7);*/
format today date10. max_date_1 date10. /*seven_date date10.*/;

/*%if max_date_1<today %then %do;*/
/*output out_t;*/
proc sql;
delete from work.one where max_date_1< (today()-10);
/*select id from work.one where id=max(id);*/
update work.one
set id=(select max(id)-(max(id)-1) from work.process_cleanup);
quit;
/*%end;*/
/*%else;*/
/*output two;*/
run;
%mend clean;
%clean;

 

data setSmiley Tonguerocess_cleanup

========

IDPROCESS_NAMESTART_DATETIMEEND_DATETIMESTATUSMESSAGE  
137process_129/04/2019 07:5429/04/2019 07:54FLoeaded successfully
136process_229/04/2019 07:1529/04/2019 07:15FLoeaded successfully
135process_328/04/2019 07:1528/04/2019 07:15E

SASERROR: 8888

 File does not exist. Please check process log in 

134process_427/04/2019 07:1527/04/2019 07:15FLoeaded successfully
133process_526/04/2019 09:2426/04/2019 09:24FLoeaded successfully
132process_626/04/2019 09:1826/04/2019 09:18E

SASERROR: 8888

 File does not exist. Please check process log in 

131process_726/04/2019 09:0926/04/2019 09:10FLoeaded successfully
130process_826/04/2019 08:5926/04/2019 09:01FLoeaded successfully
129process_926/04/2019 08:5326/04/2019 08:54FLoeaded successfully
128process_1026/04/2019 08:3026/04/2019 08:30FLoeaded successfully
127process_1121/04/2019 07:1521/04/2019 07:15FLoeaded successfully
126process_1220/04/2019 07:1520/04/2019 07:15FLoeaded successfully
125process_1319/04/2019 07:1519/04/2019 07:15FLoeaded successfully
124process_1418/04/2019 07:1518/04/2019 07:15FLoeaded successfully
123process_1517/04/2019 07:1517/04/2019 07:15FLoeaded successfully
122process_1616/04/2019 07:1516/04/2019 07:15FLoeaded successfully
121process_1715/04/2019 07:1515/04/2019 07:16FLoeaded successfully
120process_1814/04/2019 07:1514/04/2019 07:15FLoeaded successfully
119process_1913/04/2019 07:1513/04/2019 07:15FLoeaded successfully
118process_2012/04/2019 07:1512/04/2019 07:15FLoeaded successfully
117process_2111/04/2019 07:1511/04/2019 07:15FLoeaded successfully
116process_2210/04/2019 07:1510/04/2019 07:15FLoeaded successfully
115process_2309/04/2019 07:1509/04/2019 07:15FLoeaded successfully
114process_2408/04/2019 07:1708/04/2019 07:21FLoeaded successfully
113process_2507/04/2019 07:1507/04/2019 07:15FLoeaded successfully
112process_2606/04/2019 07:1506/04/2019 07:15FLoeaded successfully
111process_2705/04/2019 18:0005/04/2019 18:07FLoeaded successfully
110process_2805/04/2019 17:3105/04/2019 17:38FLoeaded successfully
109process_2905/04/2019 16:3305/04/2019 17:31FLoeaded successfully
108process_3005/04/2019 15:5605/04/2019 16:33FLoeaded successfully
107process_3105/04/2019 15:1505/04/2019 15:56FLoeaded successfully
106process_3205/04/2019 14:0405/04/2019 15:15FLoeaded successfully

 

 

 

needed outputSmiley Surprisedne

===========

 

IDPROCESS_NAMESTART_DATETIMEEND_DATETIMESTATUSMESSAGE 
1process_129/04/2019 07:5429/04/2019 07:54FLoeaded successfully
2process_229/04/2019 07:1529/04/2019 07:15FLoeaded successfully
3process_328/04/2019 07:1528/04/2019 07:15ESASERROR: 8888 File does not exist. Please check process log in 
4process_427/04/2019 07:1527/04/2019 07:15FLoeaded successfully
5process_526/04/2019 09:2426/04/2019 09:24FLoeaded successfully
6process_626/04/2019 09:1826/04/2019 09:18E

SASERROR: 8888

 File does not exist. Please check process log 

7process_726/04/2019 09:0926/04/2019 09:10FLoeaded successfully
8process_826/04/2019 08:5926/04/2019 09:01FLoeaded successfully
9process_926/04/2019 08:5326/04/2019 08:54FLoeaded successfully
10process_1026/04/2019 08:3026/04/2019 08:30FLoeaded successfully
11process_1121/04/2019 07:1521/04/2019 07:15FLoeaded successfully
6 REPLIES 6
PaigeMiller
Diamond | Level 26

As I look at your code, I see no real benefit to doing this in a macro, and I also don't see any benefit to doing this with a DATA step followed by PROC SQL.

 

Something like this might work

 

data one;
    set work.process_cleanup;
    if datepart(start_datetime)<(today()-10) then delete;
    id+1;
run;
    
--
Paige Miller
Hema_12
Fluorite | Level 6

Hi Paige,

 

Thank you so much for your solution.But I  already achieved the deletion of rows.

it deleted the rows which are older than 10 days but not setting the id again from 1. 

i need to alter the id from 1 after deletion the rows.

 

Thanks & Regards,

Hema 

andreas_lds
Jade | Level 19

To bad that you haven't posted data in usable form, so the following code is untested:

 

data one;
    set work.process_cleanup;
    retain new_id 1;
	
	id = new_id;
	
    if datepart(start_datetime)<(today()-10) then delete;
	
	new_id = new_id + 1;
run;
Hema_12
Fluorite | Level 6

Hi ,

 

Already posted data in my main post.

i have checked your code but it not able to auto increment the id column again.

please check the needed output data here it is.

 

 

input data set --->process_cleanup

========

IDPROCESS_NAMESTART_DATETIMEEND_DATETIMESTATUSMESSAGE  
137process_129/04/2019 07:5429/04/2019 07:54FLoeaded successfully
136process_229/04/2019 07:1529/04/2019 07:15FLoeaded successfully
135process_328/04/2019 07:1528/04/2019 07:15E

SASERROR: 8888

 File does not exist. Please check process log in 

134process_427/04/2019 07:1527/04/2019 07:15FLoeaded successfully
133process_526/04/2019 09:2426/04/2019 09:24FLoeaded successfully
132process_626/04/2019 09:1826/04/2019 09:18E

SASERROR: 8888

 File does not exist. Please check process log in 

131process_726/04/2019 09:0926/04/2019 09:10FLoeaded successfully
130process_826/04/2019 08:5926/04/2019 09:01FLoeaded successfully
129process_926/04/2019 08:5326/04/2019 08:54FLoeaded successfully
128process_1026/04/2019 08:3026/04/2019 08:30FLoeaded successfully
127process_1121/04/2019 07:1521/04/2019 07:15FLoeaded successfully
126process_1220/04/2019 07:1520/04/2019 07:15FLoeaded successfully
125process_1319/04/2019 07:1519/04/2019 07:15FLoeaded successfully
124process_1418/04/2019 07:1518/04/2019 07:15FLoeaded successfully
123process_1517/04/2019 07:1517/04/2019 07:15FLoeaded successfully
122process_1616/04/2019 07:1516/04/2019 07:15FLoeaded successfully
121process_1715/04/2019 07:1515/04/2019 07:16FLoeaded successfully
120process_1814/04/2019 07:1514/04/2019 07:15FLoeaded successfully
119process_1913/04/2019 07:1513/04/2019 07:15FLoeaded successfully
118process_2012/04/2019 07:1512/04/2019 07:15FLoeaded successfully
117process_2111/04/2019 07:1511/04/2019 07:15FLoeaded successfully
116process_2210/04/2019 07:1510/04/2019 07:15FLoeaded successfully
115process_2309/04/2019 07:1509/04/2019 07:15FLoeaded successfully
114process_2408/04/2019 07:1708/04/2019 07:21FLoeaded successfully
113process_2507/04/2019 07:1507/04/2019 07:15FLoeaded successfully
112process_2606/04/2019 07:1506/04/2019 07:15FLoeaded successfully
111process_2705/04/2019 18:0005/04/2019 18:07FLoeaded successfully
110process_2805/04/2019 17:3105/04/2019 17:38FLoeaded successfully
109process_2905/04/2019 16:3305/04/2019 17:31FLoeaded successfully
108process_3005/04/2019 15:5605/04/2019 16:33FLoeaded successfully
107process_3105/04/2019 15:1505/04/2019 15:56FLoeaded successfully
106process_3205/04/2019 14:0405/04/2019 15:15FLoeaded successfully

 

 

 

output dataset

===========

 

IDPROCESS_NAMESTART_DATETIMEEND_DATETIMESTATUSMESSAGE 
1process_129/04/2019 07:5429/04/2019 07:54FLoeaded successfully
2process_229/04/2019 07:1529/04/2019 07:15FLoeaded successfully
3process_328/04/2019 07:1528/04/2019 07:15ESASERROR: 8888 File does not exist. Please check process log in 
4process_427/04/2019 07:1527/04/2019 07:15FLoeaded successfully
5process_526/04/2019 09:2426/04/2019 09:24FLoeaded successfully
6process_626/04/2019 09:1826/04/2019 09:18E

SASERROR: 8888

 File does not exist. Please check process log 

7process_726/04/2019 09:0926/04/2019 09:10FLoeaded successfully
8process_826/04/2019 08:5926/04/2019 09:01FLoeaded successfully
9process_926/04/2019 08:5326/04/2019 08:54FLoeaded successfully
10process_1026/04/2019 08:3026/04/2019 08:30FLoeaded successfully
11process_1121/04/2019 07:1521/04/2019 07:15FLoeaded successfully
andreas_lds
Jade | Level 19

You have posted tables, nice to view but useless, because they don't show any information about column types and lengths. See How to convert datasets to data steps to learn how to post data in usable form.

PaigeMiller
Diamond | Level 26

@Hema_12 wrote:

Hi Paige,

 

Thank you so much for your solution.But I  already achieved the deletion of rows.

it deleted the rows which are older than 10 days but not setting the id again from 1. 

i need to alter the id from 1 after deletion the rows.


It's not clear to me what this means. The code I provided gives ID number from 1 to 11 in the output data set, just as your example shows. If that's not what it does, then please explain further, and show us the code you used, and show us the results that are not what you want.

--
Paige Miller

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1440 views
  • 0 likes
  • 3 in conversation