Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
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> macro.
5 Usage:
6
7 %mp_lib2cards(lib=sashelp
8 , outloc= C:\temp )
9
10 The output will be one cards file in the `outloc` directory per dataset in the
11 input `lib` library. If the `outloc` directory does not exist, it is created.
12
13 To create a single SAS file with the first 1000 records of each table in a
14 library you could use this syntax:
15
16 %mp_lib2cards(lib=sashelp
17 , outloc= /tmp
18 , outfile= myfile.sas
19 , maxobs= 1000
20 )
21
22 <h4> SAS Macros </h4>
23 @li mf_mkdir.sas
24 @li mf_trimstr.sas
25 @li mp_ds2cards.sas
26
27 @param [in] lib= () Library in which to convert all datasets
28 @param [out] outloc= (%sysfunc(pathname(work))) Location in which to store
29 output. No quotes.
30 @param [out] outfile= (0) Optional output file NAME - if provided, then
31 will create a single output file instead of one file per input table.
32 @param [in] maxobs= (max) limit output to the first <code>maxobs</code> rows
33
34 @version 9.2
35 @author Allan Bowe
36**/
37
38%macro mp_lib2cards(lib=
39 ,outloc=%sysfunc(pathname(work))
40 ,maxobs=max
41 ,random_sample=NO
42 ,outfile=0
43)/*/STORE SOURCE*/;
44
45/* Find the tables */
46%local x ds memlist;
47proc sql noprint;
48select distinct lowcase(memname)
49 into: memlist
50 separated by ' '
51 from dictionary.tables
52 where upcase(libname)="%upcase(&lib)";
53
54/* trim trailing slash, if provided */
55%let outloc=%mf_trimstr(&outloc,/);
56%let outloc=%mf_trimstr(&outloc,\);
57
58/* create the output directory */
59%mf_mkdir(&outloc)
60
61/* create the cards files */
62%do x=1 %to %sysfunc(countw(&memlist));
63 %let ds=%scan(&memlist,&x);
64 %mp_ds2cards(base_ds=&lib..&ds
65 ,maxobs=&maxobs
66 ,random_sample=&random_sample
67 %if "&outfile" ne "0" %then %do;
68 ,append=YES
69 ,cards_file="&outloc/&outfile"
70 %end;
71 %else %do;
72 ,append=NO
73 ,cards_file="&outloc/&ds..sas"
74 %end;
75 )
76%end;
77
78%mend mp_lib2cards;