SAS Macro : Run SAS Procedure on Multiple Datasets

This tutorial explains how to run SAS procedures on multiple datasets.

Dictionary.Columns vs. Dictionary.Tables
Dictionary.Columns
It returns information about the columns in one or more data sets. It is similar to the results of the CONTENTS procedure.
Dictionary.Tables
It returns information about names of SAS files and type, date created and last modified, number of observations, observation length, number of variables etc.
Task : Export all SAS data sets of a library in CSV format

*Count Number of Datasets in a library;
%let lib = sashelp;
proc sql noprint;
select count(*) into :n
from dictionary.tables
where libname=%upcase("&lib");
quit;
%put &n;

*List name of all datasets in a library;
proc sql noprint;
select memname into :data1 - :data%LEFT(&n)
from dictionary.tables
where libname=%upcase("&lib");
quit; 

%macro temp;
%do i=1 %to &n.;
proc export data = &lib..&&data&i
outfile = "C:\Users\Deepanshu\Documents\KeyBank\&&data&i...csv"
DBMS = CSV;
run;
%end;
%mend;
%temp;

Get Free Email Updates :
*Please confirm your email address by clicking on the link sent to your Email*

Related Posts:

2 Responses to "SAS Macro : Run SAS Procedure on Multiple Datasets"

Next → ← Prev