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