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 For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!

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 For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
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 For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 31138 views
  • 5 likes
  • 3 in conversation