BookmarkSubscribeRSS Feed
gabonzo
Quartz | Level 8

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:

 

  1. What the maximum allowed number for DATAn is
  2. If it is possible to extend it

Thanks

5 REPLIES 5
ChrisHemedinger
Community Manager

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;

 

Check out SAS Innovate on-demand content! Watch the main stage sessions, keynotes, and over 20 technical breakout sessions!
gabonzo
Quartz | Level 8
I like your idea, but it would be tricky to use it to solve my problem.

I don't create that many datasets per macro (perhaps three at most), but I have many macros, and in the current task I am doing a statistic simulation where I have to run the same set of macros over and over again for tens of thousands of times.

One way I could use your trick is to create a subfolder for each macro, but I am concerned the overhead will slow down an already slow program. Moreover, isn't PROC DATASETS supposed to be a bit of a resource hog?

Thanks anyway
ChrisHemedinger
Community Manager

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;

 

Check out SAS Innovate on-demand content! Watch the main stage sessions, keynotes, and over 20 technical breakout sessions!
Reeza
Super User

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:

 

  1. What the maximum allowed number for DATAn is
  2. If it is possible to extend it

Thanks


 

gabonzo
Quartz | Level 8

Ok, it seems a consensus is forming. Perhaps I will go with this solution.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

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
  • 5 replies
  • 494 views
  • 2 likes
  • 3 in conversation