08-05-2014 12:30 AM
Hi,
I have a requirement to generate SAS dataset names in my SAS code like the ones gets generated automatically in SAS DI - (e.g - work.W5T9JQ6B, work.W5T9J46Q, work.W5T9J46X).
Can someone suggest how to do this in SAS or any OOPS language.
Regards
Dhana
08-05-2014 04:37 AM
hi
the names used by SAS Data Integration Studio are Metadata ID's, If you simply need to create a unique name you could create a macro like below:
08-05-2014 01:28 AM
You could use proc datasets:
Proc Datasets Library=Work MemType=Data /*NoList*/;
Contents Out=Work_Cont (Keep=MemName) Data=_ALL_ /*NoPrint*/;
Run;
08-05-2014 02:06 AM
Keep a counter (in a macro variable or a utility table) and every time you create a new table, increment the counter by 1. As long as your counter stays below 36 ** 7, the following will convert an integer into a base 36 number of seven "digits" (but you might like to add a check for overflow):
CODE:
%let counter = 99999999;
data _null_;
length string $ 7 char $ 1 tablename $ 8;
num = input(symget('COUNTER'), 16.);
do i = 1 to 7;
remain = mod(num, 36);
char = substr('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ', remain+1, 1);
string = char !! left(string);
num = int(num / 36);
end;
tablename = 'W'!!string;
call symput('TABLE', tablename);
run;
%put &TABLE.;
LOG:
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
28
29 %put &TABLE.;
W01NJCHR
08-05-2014 04:37 AM
hi
the names used by SAS Data Integration Studio are Metadata ID's, If you simply need to create a unique name you could create a macro like below:
08-05-2014 05:48 AM
That's a weird requirement and I'm curious what the purpose of it is.
If this is about automatically generating SAS Work table names and make sure that the names are unique then you could also let SAS do it using below syntax:
data;
set sashelp.class;
run;
%put &syslast;
data;
set &syslast;
run;
%put &syslast;
08-05-2014 08:14 AM
UUID function :
%let dsname=w%scan(%sysfunc(uuidgen()),1); %put &dsname ;
Xia Keshan
08-06-2014 04:07 AM
Thanks Ksharp, the uuidgen function is new to me.
08-05-2014 01:04 PM
Thank you everyone...! The code provided by Bruno Muller & Ksharp soved my problem.
Regards
Dhana
Need further help from the community? Please ask a new question.