DATA Step, Macro, Functions and more

temporary dataset name

Reply
N/A
Posts: 0

temporary dataset name

I want to create a temporary dataset with an arbitary name, but I don't want to overwrite any current objects in the work library. So I have a piece of code to find an available identifier for the dataset first,
/*
data _null_;
length str $ 6;
do until(not exist(str) and not exist(str, 'view'));
str = cats("_", put(floor(ranuni(0)*32768), best.));
end;
call symput("dsn", str);
run;
*/
my two questions,
(1) I know I cannot have conflict with current 'DATA' or 'VIEW' names, but are there other types of objects needs to be checked?
(2) Is there an easier way of programming?
Thanks! Message was edited by: urchin
Trusted Advisor
Posts: 2,115

Re: temporary dataset name

Posted in reply to deleted_user
If you don't care about the name, you can just use

DATA;

RUN;

And SAS will create a name for you in format DATAn, where 'n' is the next available number in the work library.
Respected Advisor
Posts: 4,173

Re: temporary dataset name

Hey yes, nice proposition Doc@Duke

And if urchin wants to use this generic dataset names later on he/she could do something like this:

data;
a=1;
run;
%let ThisIstheFirstDS=&syslast;
data;
a=2;
run;
%let ThisIstheSecondDS=&syslast;

proc print data=&ThisIstheFirstDS;
run;

Cheers, Patrick
N/A
Posts: 0

Re: temporary dataset name

Both of your minds are so sharp! I end up with something like

%macro doit(n);
%do i=1 %to &n;
data;stop;run;
%let tmp&i = %sysfunc(tranwrd(&syslast, WORK., ));
%end;
proc datasets nolist;
delete
%do i=1 %to &n;
&&tmp&i
%end;
;
run;
%mend doit;
N/A
Posts: 0

Re: temporary dataset name

Posted in reply to deleted_user
Don't forget, for extra protection: OPTIONS NOREPLACE. However, this may have to be carefully targeted if some of your data is replaceable.
Ask a Question
Discussion stats
  • 4 replies
  • 127 views
  • 0 likes
  • 3 in conversation