DATA Step, Macro, Functions and more

Learning MACROS...would like sample coding as reference

Reply
Occasional Contributor
Posts: 9

Learning MACROS...would like sample coding as reference

suppose I have 5-6 different SAS data sets stored in my C: drive (example c:/SASData)

What would be an effective macro that I could use that would display (using proc print) all of the data sets in that C: folder?


Thanks for the help!
Valued Guide
Posts: 632

Re: Learning MACROS...would like sample coding as reference

here is a possible solution:
[pre]%macro printit(dsn=);
title1 Printing &dsn;
proc print data=&dsn(obs=5);
run;
%mend printit;

%macro getdatalist(lib=);
%local count i;
proc sql noprint;
select distinct memname
into :mem1 - :mem&sysmaxlong
from dictionary.members
where libname=upcase("&lib");
quit;
%let count = &sqlobs;
%do i = 1 %to &count;
%printit(dsn=&lib..&&mem&i);
%end;
%mend getdatalist;
%getdatalist(lib=sasclass)
[/pre]
Super User
Posts: 9,687

Re: Learning MACROS...would like sample coding as reference

Just as Arthur.Carpenter 's code.But I used call execute() which is interface of macro facility with dataset.If you like.
[pre]



libname mylib 'c:\temp';
data _null_;
set sashelp.vtable(where=(libname='MYLIB'));
call execute('proc print data=mylib.'||strip(memname)||';');
call execute('run;');
run;
[/pre]


Ksharp
N/A
Posts: 1

Re: Learning MACROS...would like sample coding as reference

/* first assign your folder to a libname */
libname newLib 'c:/SASData';

/* to just show dataset names in ouput window */
proc sql;
select memname
from
dictionary.members
where libname='newLib'
;
quit;

/* or to put the dataset names into a dataset and then view with proc print */
proc sql;
create table newDataset as
select memname
from
dictionary.members
where libname='newLib'
;
quit;
proc print data=newDataset;
run;
SAS Employee RMP
SAS Employee
Posts: 52

Re: Learning MACROS...would like sample coding as reference

if you are only interested in the characteristics of the datasets and not the physical data then you can use

proc contents data=lib._all_;
run;
Ask a Question
Discussion stats
  • 4 replies
  • 143 views
  • 0 likes
  • 5 in conversation