Production Ready Macros for SAS Application Developers
https://github.com/sasjs/core
mm_spkexport.sas
Go to the documentation of this file.
1 /**
2  @file mm_spkexport.sas
3  @brief Creates an batch spk export command
4  @details Creates a script that will export everything in a metadata folder to
5  a specified location.
6  If you have XCMD enabled, then you can use mmx_spkexport (which performs
7  the actual export)
8 
9  Note - the batch tools require a username and password. For security,
10  these are expected to have been provided in a protected directory.
11 
12  Usage:
13 
14  %* import the macros (or make them available some other way);
15  filename mc url "https://raw.githubusercontent.com/sasjs/core/main/all.sas";
16  %inc mc;
17 
18  %* create sample text file as input to the macro;
19  filename tmp temp;
20  data _null_;
21  file tmp;
22  put '%let mmxuser="sasdemo";';
23  put '%let mmxpass="Mars321";';
24  run;
25 
26  filename myref "%sysfunc(pathname(work))/mmxexport.sh";
27  %mm_spkexport(metaloc=%str(/my/meta/loc)
28  ,outref=myref
29  ,secureref=tmp
30  ,cmdoutloc=%str(/tmp)
31  )
32 
33  Alternatively, call without inputs to create a function style output
34 
35  filename myref "/tmp/mmscript.sh";
36  %mm_spkexport(metaloc=%str(/my/meta/loc)
37  outref=myref
38  ,cmdoutloc=%str(/tmp)
39  ,cmdoutname=mmx
40  )
41 
42  You can then navigate and execute as follows:
43 
44  cd /tmp
45  ./mmscript.sh "myuser" "mypass"
46 
47 
48  <h4> Dependencies </h4>
49  @li mf_loc.sas
50  @li mm_tree.sas
51  @li mf_getuniquefileref.sas
52  @li mf_isblank.sas
53  @li mp_abort.sas
54 
55  @param metaloc= the metadata folder to export
56  @param secureref= fileref containing the username / password (should point to
57  a file in a secure location). Leave blank to substitute $bash type vars.
58  @param outref= fileref to which to write the command
59  @param cmdoutloc= the directory to which the command will write the SPK
60  (default=WORK)
61  @param cmdoutname= the name of the spk / log files to create (will be
62  identical just with .spk or .log extension)
63 
64  @version 9.4
65  @author Allan Bowe
66 
67 **/
68 
69 %macro mm_spkexport(metaloc=
70  ,secureref=
71  ,outref=
72  ,cmdoutloc=%sysfunc(pathname(work))
73  ,cmdoutname=mmxport
74 );
75 
76 %if &sysscp=WIN %then %do;
77  %put %str(WARN)ING: the script has been written assuming a unix system;
78  %put %str(WARN)ING- it will run anyway as should be easy to modify;
79 %end;
80 
81 /* set creds */
82 %local mmxuser mmxpath;
83 %let mmxuser=$1;
84 %let mmxpass=$2;
85 %if %mf_isblank(&secureref)=0 %then %do;
86  %inc &secureref/nosource;
87 %end;
88 
89 /* setup metadata connection options */
90 %local host port platform_object_path connx_string;
91 %let host=%sysfunc(getoption(metaserver));
92 %let port=%sysfunc(getoption(metaport));
93 %let platform_object_path=%mf_loc(POF);
94 
95 %let connx_string=%str(-host &host -port &port -user &mmxuser -password &mmxpass);
96 
97 %mm_tree(root=%str(&metaloc) ,types=EXPORTABLE ,outds=exportable)
98 
99 %if %mf_isblank(&outref)=1 %then %let outref=%mf_getuniquefileref();
100 
101 data _null_;
102  set exportable end=last;
103  file &outref lrecl=32767;
104  length str $32767;
105  if _n_=1 then do;
106  put "cd ""&platform_object_path"" \";
107  put "; ./ExportPackage &connx_string -disableX11 \";
108  put " -package ""&cmdoutloc/&cmdoutname..spk"" \";
109  end;
110  str=' -objects '!!cats('"',path,'/',name,"(",publictype,')" \');
111  put str;
112  if last then put " -log ""&cmdoutloc/&cmdoutname..log"" 2>&1 ";
113 run;
114 
115 %mp_abort(iftrue= (&syscc ne 0)
116  ,mac=&sysmacroname
117  ,msg=%str(syscc=&syscc)
118 )
119 
120 %mend;