Hello Everyone,
I do have a question regarding the folowing subject:
Assume you have the following datasets in your work library: "customers" , "costs" , "revenues" and "transactions".
How can I efficiently write a macro which generates one dataset called "overview" with a variable named "datasetnames" in which the corresponding name of each of the dataset in my work library is written into.
So in the described case above the "overview" dataset should look like this:
datasetnames
1 customers
2 costs
3 revenues
4 transactions
Thank you in advance for any help in this topic.
For what purpose? SAS has a set of metadata tables in SASHELP library which tell it what libraries, datasets, columns etc. are used. Just query that:
data want;
set sashelp.vtable (where=(libname="WORK") keep=memname);
run;
I think you dont have to write macro..try the below codes;
Proc contents data = work._ALL_ nods out= abc; run;
For what purpose? SAS has a set of metadata tables in SASHELP library which tell it what libraries, datasets, columns etc. are used. Just query that:
data want;
set sashelp.vtable (where=(libname="WORK") keep=memname);
run;
proc sql;
create table dataname as
select memname as datasetnames from dictionary.columns
where libname='WORK';
quit;
If you really want a macro to perform this task, you could try something like this:
%macro listds(lib=work, out=overview, namevar=datasetnames, order=memname);
proc sql;
create table &out as
select memname as &namevar
from dictionary.tables
where libname="%upcase(&lib)" & memtype='DATA'
order by ℴ
quit;
%mend listds;
Here you have the flexibility of specifying
Sample calls:
%listds; /* gives what you have described, however sorted alphabetically by dataset name */
%listds(lib=mylib, out=newlib.dslist, namevar=dsname, order=crdate) /* assuming that libraries mylib and newlib exist */
For more options regarding parameter order see the description of dictionary.tables:
proc sql;
describe table dictionary.tables;
quit;
Thank's guys for helping me out!
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.
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.