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 @sasjslint {"maxLineLength": 81}
37**/
38
39%macro mp_lib2cards(lib=
40 ,outloc=%sysfunc(pathname(work))
41 ,maxobs=max
42 ,random_sample=NO
43 ,outfile=0
44)/*/STORE SOURCE*/;
45
46/* Find the tables */
47%local x ds memlist;
48proc sql noprint;
49select distinct lowcase(memname)
50 into: memlist
51 separated by ' '
52 from dictionary.tables
53 where upcase(libname)="%upcase(&lib)";
54
55/* trim trailing slash, if provided */
56%let outloc=%mf_trimstr(&outloc,/);
57%let outloc=%mf_trimstr(&outloc,\);
58
59/* create the output directory */
60%mf_mkdir(&outloc)
61
62/* create the cards files */
63%do x=1 %to %sysfunc(countw(&memlist));
64 %let ds=%scan(&memlist,&x);
65 %mp_ds2cards(base_ds=&lib..&ds
66 ,maxobs=&maxobs
67 ,random_sample=&random_sample
68 %if "&outfile" ne "0" %then %do;
69 ,append=YES
70 ,cards_file="&outloc/&outfile"
71 %end;
72 %else %do;
73 ,append=NO
74 ,cards_file="&outloc/&ds..sas"
75 %end;
76 )
77%end;
78
79%mend mp_lib2cards;