BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
AlanC
Barite | Level 11

I did not find a good place to ask this question so I figured EG would be the best location.

 

When we instantiate a new Workspace object in C#:

 

var ws = new Workspace();

var ls = ws.LanguageService

 

...and then we execute SAS code...

 

How do we then clear the work library that the ws used? I could submit a proc datasets but I figured there is probably a programmatic way to do it.

https://github.com/savian-net
1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

Hi @AlanC - actually, I think the best way is probably proc datasets lib=work kill.

 

There isn't any other method on the Workspace that abstracts this operation.

 

If you think that clearing the entire WORK library might have a side effect (removing something that you didn't explicitly create), then I recommend creating a new library that's located in a subfolder of the WORK space.

 

/* create a new lib as a subfolder of WORK */
options dlcreatedir;
libname mywork "%sysfunc(getoption(WORK))/mywork";

/* optional: one-level names will default to MYWORK lib */
options user=mywork;

/* Use and enjoy */
data one two three;
 set sashelp.class;
run;

/* cleanup MYWORK before the next task */
proc datasets nolist nodetails lib=mywork kill;
SAS Innovate 2025: Call for Content! Submit your proposals before Sept 16. Accepted presenters get amazing perks to attend the conference!

View solution in original post

6 REPLIES 6
AlanC
Barite | Level 11

In SAS language but it may not be the object way. For example, EG add-ins.

https://github.com/savian-net
ChrisHemedinger
Community Manager

Hi @AlanC - actually, I think the best way is probably proc datasets lib=work kill.

 

There isn't any other method on the Workspace that abstracts this operation.

 

If you think that clearing the entire WORK library might have a side effect (removing something that you didn't explicitly create), then I recommend creating a new library that's located in a subfolder of the WORK space.

 

/* create a new lib as a subfolder of WORK */
options dlcreatedir;
libname mywork "%sysfunc(getoption(WORK))/mywork";

/* optional: one-level names will default to MYWORK lib */
options user=mywork;

/* Use and enjoy */
data one two three;
 set sashelp.class;
run;

/* cleanup MYWORK before the next task */
proc datasets nolist nodetails lib=mywork kill;
SAS Innovate 2025: Call for Content! Submit your proposals before Sept 16. Accepted presenters get amazing perks to attend the conference!
AlanC
Barite | Level 11

Thanks Chris. I have been exploring the libref object and nothing explicitly lets me list what is there (so I can loop and delete). Getting it confirmed that it is datasets is what I needed.

 

See you at SGF.

https://github.com/savian-net
ChrisHemedinger
Community Manager

If you're working with SAS custom tasks, then the Task Toolkit has a SasData class/namespace that can help you to enumerate all of these members.  See this GitHub project for examples.  Behind the scenes, these classes are using the SAS DICTIONARY tables to discover libraries, data sets, and their properties.  The libref object in IOM is pretty limited and tricky to use.

 

These classes don't offer a delete method though.

 

Chris

SAS Innovate 2025: Call for Content! Submit your proposals before Sept 16. Accepted presenters get amazing perks to attend the conference!
AlanC
Barite | Level 11

I am instantiating n number of  workspaces and enqueuing/dequeuing them, then reusing them. This saves the reinstantiation cost so I need the workspace cleared after each language use.

https://github.com/savian-net

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 24698 views
  • 5 likes
  • 3 in conversation