This tutorial explains how to run SAS procedures on multiple datasets.
Dictionary.Columns vs. Dictionary.Tables
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 :nfrom dictionary.tableswhere 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.tableswhere libname=%upcase("&lib");quit;%macro temp;%do i=1 %to &n.;proc export data = &lib..&&data&ioutfile = "C:\Users\Deepanshu\Documents\KeyBank\&&data&i...csv"DBMS = CSV;run;%end;%mend;%temp;
Awesome concepts!!! Thanks
ReplyDeleteHi Deepanshu
ReplyDeletei want to print all table names. Written below code
%let lib = sashelp;
proc sql noprint;
select memname into :data1 - :data10
from dictionary.tables
where libname=%upcase("&lib");
quit;
%macro mymacro;
%do i=1 %to 10;
%put &data&i;
%end;
%mend;
%mymacro;
getting error:
WARNING: Apparent symbolic reference DATA not resolved.
&data1
WARNING: Apparent symbolic reference DATA not resolved.
&data2
WARNING: Apparent symbolic reference DATA not resolved.... so on
Please suggest
Use &&data&i in above code then it should work
DeletePlease use "&&data&i" inside the %do loop
DeleteThen 10 dataset names will be shown in the log
related to previous above post....
ReplyDeletegot resolved by &&data&i
still have query that how n value is identified in below code
%do i=1 %to &n.;
hello,
ReplyDeletewhy we have used "..." in "&&data&i...CSV" statement?
shouldn't line 8 be %put &n.;
ReplyDelete