Production Ready Macros for SAS Application Developers
https://github.com/sasjs/core
mmx_spkexport.sas
Go to the documentation of this file.
1/**
2 @file mmx_spkexport.sas
3 @brief Exports everything in a particular metadata folder
4 @details Will export everything in a metadata folder to a specified location.
5 Note - the batch tools require a username and password. For security,
6 these are expected to have been provided in a protected directory.
7
8Usage:
9
10 %* import the macros (or make them available some other way);
11 filename mc url "https://raw.githubusercontent.com/sasjs/core/main/all.sas";
12 %inc mc;
13
14 %* create sample text file as input to the macro;
15 filename tmp temp;
16 data _null_;
17 file tmp;
18 put '%let mmxuser=sasdemo;';
19 put '%let mmxpass=Mars321';
20 run;
21
22 filename outref "%sysfunc(pathname(work))";
23 %mmx_spkexport(
24 metaloc=%str(/30.Projects/3001.Internal/300115.DataController/dc1)
25 ,secureref=tmp
26 ,outspkpath=%str(/tmp)
27 )
28
29 <h4> SAS Macros </h4>
30 @li mf_loc.sas
31 @li mm_tree.sas
32 @li mf_getuniquefileref.sas
33 @li mp_abort.sas
34
35 @param metaloc= the metadata folder to export
36 @param secureref= fileref containing the username / password (should point to
37 a file in a secure location)
38 @param outspkname= name of the spk to be created (default is mmxport).
39 @param outspkpath= directory in which to create the SPK. Default is WORK.
40
41 @version 9.4
42 @author Allan Bowe
43
44**/
45
46%macro mmx_spkexport(metaloc=
47 ,secureref=
48 ,outspkname=mmxport
49 ,outspkpath=%sysfunc(pathname(work))
50);
51
52%local host port platform_object_path connx_string;
53%let host=%sysfunc(getoption(metaserver));
54%let port=%sysfunc(getoption(metaport));
55%let platform_object_path=%mf_loc(POF);
56
57/* get creds */
58%inc &secureref/nosource;
59
60%let connx_string=
61 %str(-host &host -port &port -user '&mmxuser' -password '&mmxpass');
62
63%mm_tree(root=%str(&metaloc) ,types=EXPORTABLE ,outds=exportable)
64
65%local fref1;
66%let fref1=%mf_getuniquefileref();
67data ;
68 set exportable end=last;
69 file &fref1 lrecl=32767;
70 length str $32767;
71 if _n_=1 then do;
72 put 'data _null_;';
73 put 'infile "cd ""&platform_object_path"" %trim(';
74 put ') cd ""&platform_object_path"" %trim(';
75 put '); ./ExportPackage &connx_string -disableX11 %trim(';
76 put ') -package ""&outspkpath/&outspkname..spk"" %trim(';
77 end;
78 str=') -objects '!!cats('""',path,'/',name,"(",publictype,')"" %trim(');
79 put str;
80 if last then do;
81 put ') -log ""&outspkpath/&outspkname..log"" 2>&1" pipe lrecl=10000;';
82 put 'input;putlog _infile_;run;';
83 end;
84run;
85
86%mp_abort(iftrue= (&syscc ne 0)
87 ,mac=&sysmacroname
88 ,msg=%str(syscc=&syscc)
89)
90
91%inc &fref1;
92
93%mend mmx_spkexport;