Production Ready Macros for SAS Application Developers
https://github.com/sasjs/core
mp_lib2cards.sas
Go to the documentation of this file.
1 /**
2  @file
3  @brief Convert all library members to CARDS files
4  @details Gets list of members then calls the <code>%mp_ds2cards()</code>
5  macro
6  usage:
7 
8  %mp_lib2cards(lib=sashelp
9  , outloc= C:\temp )
10 
11  <h4> Dependencies </h4>
12  @li mf_mkdir.sas
13  @li mp_ds2cards.sas
14 
15  @param lib= Library in which to convert all datasets
16  @param outloc= Location in which to store output. Defaults to WORK library.
17  Do not use a trailing slash (my/path not my/path/). No quotes.
18  @param maxobs= limit output to the first <code>maxobs</code> observations
19 
20  @version 9.2
21  @author Allan Bowe
22 **/
23 
24 %macro mp_lib2cards(lib=
25  ,outloc=%sysfunc(pathname(work)) /* without trailing slash */
26  ,maxobs=max
27  ,random_sample=NO
28 )/*/STORE SOURCE*/;
29 
30 /* Find the tables */
31 %local x ds memlist;
32 proc sql noprint;
33 select distinct lowcase(memname)
34  into: memlist
35  separated by ' '
36  from dictionary.tables
37  where upcase(libname)="%upcase(&lib)";
38 
39 /* create the output directory */
40 %mf_mkdir(&outloc)
41 
42 /* create the cards files */
43 %do x=1 %to %sysfunc(countw(&memlist));
44  %let ds=%scan(&memlist,&x);
45  %mp_ds2cards(base_ds=&lib..&ds
46  ,cards_file="&outloc/&ds..sas"
47  ,maxobs=&maxobs
48  ,random_sample=&random_sample)
49 %end;
50 
51 %mend;