BookmarkSubscribeRSS Feed
noobs
Calcite | Level 5


HEllo SAS EG users,

I intend to use program to delete permanent dataset once I read it into WORK library so that I can process new data and save it as the same permanent dataset at end of the session.

What is the best way to:

a) Replace existing permanent dataset using datastep?

OR

b) Delete existing permanent dataset using datastep?

Thanks,

Dhanashree

6 REPLIES 6
TomKari
Onyx | Level 15

You don't actually need to delete your permanent dataset to replace it.

Assume you have mylib.testds

The following code:

data work.testds;

set mylib.testds;

... processing ...

run;

data mylib.testds;

set work.testds;

run;

will replace your permanent dataset.

However, if you want to delete it, I like:

proc sql;

drop table mylib.testds;

quit;

Reeza
Super User

What happens if your process fails in the middle, ie power outage, coffee spills on CPU, data you expect doesn't exist Smiley Happy

TomKari
Onyx | Level 15

Party pooper! :smileysilly:

ChrisHemedinger
Community Manager

For the error situation, SAS has an option for that (of course!).  You can use the NOREPLACE option to prevent the accidental replacement of a data set when an error occurs.

And as far as deleting a data set outright, let's not forget about our recently resurrected friend, PROC DELETE.

Chris

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
TomKari
Onyx | Level 15

Oh my goodness!

I have my original SAS manual, from back when it was one book and ran on the mainframe, and I've NEVER heard of PROC DELETE!

It must work for the CIA...or the NSA...or the KGB!

I've wanted this functionality for YEARS, and it was under my nose the whole time. Gack!

Tom
Super User Tom
Super User

A.

That is how SAS already does it.

If you write:

data mylib.x ;

  set work.x;

run;

SAS will create a whole new file named x.sas7bdat in the directory that MYLIB points to.  Once it is finished it then deletes the original x.sas7bdat and renames the file that it created.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 6 replies
  • 1305 views
  • 0 likes
  • 5 in conversation