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!
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.