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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 929 views
  • 0 likes
  • 3 in conversation