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 
8 Usage:
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(metaloc=%str(/30.Projects/3001.Internal/300115.DataController/dc1)
24  ,secureref=tmp
25  ,outspkpath=%str(/tmp)
26  )
27 
28  <h4> Dependencies </h4>
29  @li mf_loc.sas
30  @li mm_tree.sas
31  @li mf_getuniquefileref.sas
32  @li mp_abort.sas
33 
34  @param metaloc= the metadata folder to export
35  @param secureref= fileref containing the username / password (should point to
36  a file in a secure location)
37  @param outspkname= name of the spk to be created (default is mmxport).
38  @param outspkpath= directory in which to create the SPK. Default is WORK.
39 
40  @version 9.4
41  @author Allan Bowe
42 
43 **/
44 
45 %macro mmx_spkexport(metaloc=
46  ,secureref=
47  ,outspkname=mmxport
48  ,outspkpath=%sysfunc(pathname(work))
49 );
50 
51 %local host port platform_object_path connx_string;
52 %let host=%sysfunc(getoption(metaserver));
53 %let port=%sysfunc(getoption(metaport));
54 %let platform_object_path=%mf_loc(POF);
55 
56 /* get creds */
57 %inc &secureref/nosource;
58 
59 %let connx_string=%str(-host &host -port &port -user '&mmxuser' -password '&mmxpass');
60 
61 %mm_tree(root=%str(&metaloc) ,types=EXPORTABLE ,outds=exportable)
62 
63 %local fref1;
64 %let fref1=%mf_getuniquefileref();
65 data ;
66  set exportable end=last;
67  file &fref1 lrecl=32767;
68  length str $32767;
69  if _n_=1 then do;
70  put 'data _null_;';
71  put 'infile "cd ""&platform_object_path"" %trim(';
72  put ') cd ""&platform_object_path"" %trim(';
73  put '); ./ExportPackage &connx_string -disableX11 %trim(';
74  put ') -package ""&outspkpath/&outspkname..spk"" %trim(';
75  end;
76  str=') -objects '!!cats('""',path,'/',name,"(",publictype,')"" %trim(');
77  put str;
78  if last then do;
79  put ') -log ""&outspkpath/&outspkname..log"" 2>&1" pipe lrecl=10000;';
80  put 'input;putlog _infile_;run;';
81  end;
82 run;
83 
84 %mp_abort(iftrue= (&syscc ne 0)
85  ,mac=&sysmacroname
86  ,msg=%str(syscc=&syscc)
87 )
88 
89 %inc &fref1;
90 
91 %mend;