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.
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;
proc datasets with kill IS the programmatic way to go.
In SAS language but it may not be the object way. For example, EG add-ins.
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;
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.
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
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.
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!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: