BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
4 REPLIES 4
Doc_Duke
Rhodochrosite | Level 12
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.
Patrick
Opal | Level 21
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
deleted_user
Not applicable
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;
deleted_user
Not applicable
Don't forget, for extra protection: OPTIONS NOREPLACE. However, this may have to be carefully targeted if some of your data is replaceable.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 1616 views
  • 0 likes
  • 3 in conversation