I use the _DATA_ trick a lot, especially for temporary datasets that I create inside macros and then delete when the macro has been executed.
I have found a problem with that though: it seems to me that the number 'n' in the DATAn naming scheme rolls over at some point, and n starts over from 1.
This causes a lot of problems, and my programs stop working.
I don't see in the documentation when the rollover is, does anybody know:
Thanks
I don't have an answer for your exact question, but I do have some advice from my experience. When I'm creating a series of temp/scratch data sets that I'm going to turn around and delete at the end of a process, I like to isolate them to their own folder (outside of WORK library). That gives me more options for deleting the whole shebang without worrying about conflicts.
I documented this in How to delete SAS data sets. Specifically the trick I use is this:
/* create a subfolder in WORK for my data */
options dlcreatedir;
libname scratch "%sysfunc(getoption(WORK))/scratch";
/* just adding some data for example purpose */
data scratch.a1 scratch.a2 scratch.a3;
set sashelp.class;
run;
/* more operations with scratch data */
/* now clear it when ready */
proc datasets lib=scratch kill nolist;
quit;
If you don't like PROC DATASETS (it does have some overhead), then PROC DELETE is quick and light. You can delete a range, but not a "wildcard" list.
proc delete library=work data=DATA1-DATA5; run;
Not a solution but similar to @ChrisHemedinger I use a common prefix, typically _dataSetName for all my temp tables and then drop them at once at the end using PROC DATASETS and the shortcut colon.
proc datasets lib=work;
delete _: ;
run;quit;
Here is a reference that illustrates how to refer to variables and datasets in a short cut list:
https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html
@gabonzo wrote:
I use the _DATA_ trick a lot, especially for temporary datasets that I create inside macros and then delete when the macro has been executed.
I have found a problem with that though: it seems to me that the number 'n' in the DATAn naming scheme rolls over at some point, and n starts over from 1.
This causes a lot of problems, and my programs stop working.
I don't see in the documentation when the rollover is, does anybody know:
- What the maximum allowed number for DATAn is
- If it is possible to extend it
Thanks
Ok, it seems a consensus is forming. Perhaps I will go with this solution.
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!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.