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;
Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.

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;
Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.
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

Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.
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

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!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 6 replies
  • 25999 views
  • 5 likes
  • 3 in conversation