Hello there,
I'm a newbie with SAS archiving of data. I would like to know how can I delete older datas w/o affecting indexes and account/party keys.
I need to delete data w/ year 2010 and below. The account/party resets to 0,1,2,3,4 so on so forth where in it should start to different count. I hope I make sense.
Regards,
kenjots
There is no auto increment field in SAS.
So you are probably using Oracle data or similar.
If you don't want to value to change, you have to turn off in auto-increment.
You can't ask for the field to be populated automatically and for the field not to change.
That's certainly not a SAS table unless you're telling us only a very scalled down and distorted part of the story. If you're interfacing with a database then what's the database?
If it's Oracle then there would be options to implement an autoincrement field which generates a key for you which doesn't change (i.e. using a sequencer object in an insert trigger; the newer versions of Oracle also have a specific new field type for such a requirement).
...but as @ChrisNZ already hints: That's something you need to solve on the database side.
As mentioned, it is a sas dataset. I would like to know how to delete rows w/o affecting the indexes?
Looks like this but again, the party_key count will reset to 0,1,2,3 so on so forth. I want to retain the party_key index.
proc sql;
create table tmp as
select * from core.transaction_table where
month_key <= 201201
;
quit;
What are you talking about? The code you posted creates a new dataset named "tmp", there is no code creating an index.
The concept "index" is described here.
Can you explain what you are talking about? SAS will not change any data values if you delete observations.
data have ;
length ACCOUNT_PARTY 8 NAME $20 DATE 8;
input ACCOUNT_PARTY NAME DATE ;
cards;
1 ALPHA 2017
2 BETA 2016
3 CHARLIE 2018
4 DELTA 2015
5 FOXTROT 2016
;
proc sort data=have ;
by date ;
run;
proc print data=have ;
run;
proc print data=have ;
where date > 2016 ;
run;
Hi Tom,
Would it be okay if I message/email you our sample data?
Regards,
brutal3239
If there is nothing confidential in your sample data then you can also attach them here.
After deleting rows, how am i going to compress the dataset? It is still 17GB albeit more than 500k rows were deleted.
I've tried this,
proc sql;
create table tmp
(
COMPRESS=YES
) as
***then delete rows****
;
quit;
It worked. However, it is in work library. I want to do it directly to the dataset where I am going to delete rows/data.
Thanks,
brutal3239
"It worked. However, it is in work library. I want to do it directly to the dataset where I am going to delete rows/data."
If you want it in a permanent library then simply create the new table in a permanent library: create table <libref>.<table name> as ...
"I want to do it directly to the dataset "
A Proc SQL/DELETE will only logically delete the rows. If you want the data set size reduced then you need to re-create the table (i.e. using your current SQL CREATE statement).
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.