@sasjs/core 4.66.4 → 4.67.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/xplatform/mx_append2pgm.sas +149 -0
package/package.json
CHANGED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file
|
|
3
|
+
@brief Appends a text file to a SASjs Stored Program, Viya SAS program, or
|
|
4
|
+
SAS 9 Stored Process
|
|
5
|
+
@details Extracts the source code from a SASjs Stored Program, Viya SAS
|
|
6
|
+
program (file in SAS Drive), or SAS 9 Stored Process, appends the contents
|
|
7
|
+
of a provided text file, then deletes and recreates the target item with the
|
|
8
|
+
combined content.
|
|
9
|
+
|
|
10
|
+
This is useful for dynamically modifying deployed programs, for example to
|
|
11
|
+
add test-specific configuration or runtime settings.
|
|
12
|
+
|
|
13
|
+
Usage:
|
|
14
|
+
|
|
15
|
+
%* compile macros ;
|
|
16
|
+
filename mc url
|
|
17
|
+
"https://raw.githubusercontent.com/sasjs/core/main/all.sas";
|
|
18
|
+
%inc mc;
|
|
19
|
+
|
|
20
|
+
%* write some content to append;
|
|
21
|
+
filename append temp;
|
|
22
|
+
data _null_;
|
|
23
|
+
file append;
|
|
24
|
+
put "libname mylib '/some/path';";
|
|
25
|
+
run;
|
|
26
|
+
|
|
27
|
+
%* append to existing program;
|
|
28
|
+
%mx_append2pgm(/Public/app/common/settings, inref=append)
|
|
29
|
+
|
|
30
|
+
@param [in] loc The full path to the Viya SAS program, SAS 9 Stored Process,
|
|
31
|
+
or SASjs Stored Program in Drive or Metadata, WITHOUT the .sas extension
|
|
32
|
+
(SASjs only)
|
|
33
|
+
@param [in] inref= (0) Fileref pointing to the content to be appended to the
|
|
34
|
+
target program.
|
|
35
|
+
@param [in] mdebug= (0) Set to 1 to show debug messages in the log
|
|
36
|
+
|
|
37
|
+
<h4> SAS Macros </h4>
|
|
38
|
+
@li mf_getplatform.sas
|
|
39
|
+
@li mf_getuniquefileref.sas
|
|
40
|
+
@li mm_createstp.sas
|
|
41
|
+
@li mm_deletestp.sas
|
|
42
|
+
@li mm_getstpcode.sas
|
|
43
|
+
@li ms_createfile.sas
|
|
44
|
+
@li ms_deletefile.sas
|
|
45
|
+
@li mv_createfile.sas
|
|
46
|
+
@li mv_deletefoldermember.sas
|
|
47
|
+
@li mx_getcode.sas
|
|
48
|
+
|
|
49
|
+
<h4> Related Macros </h4>
|
|
50
|
+
@li mx_append2pgm.test.sas
|
|
51
|
+
@li mx_getcode.sas
|
|
52
|
+
@li mx_createjob.sas
|
|
53
|
+
|
|
54
|
+
@author Allan Bowe
|
|
55
|
+
|
|
56
|
+
**/
|
|
57
|
+
|
|
58
|
+
%macro mx_append2pgm(loc
|
|
59
|
+
,inref=0
|
|
60
|
+
,mdebug=0
|
|
61
|
+
)/*/STORE SOURCE*/;
|
|
62
|
+
|
|
63
|
+
%local platform name shortloc coderef combref work tmpfile viyaref;
|
|
64
|
+
%let platform=%mf_getplatform();
|
|
65
|
+
|
|
66
|
+
%if &mdebug=1 %then %do;
|
|
67
|
+
%put &sysmacroname entry vars:;
|
|
68
|
+
%put _local_;
|
|
69
|
+
%end;
|
|
70
|
+
%if &syscc ne 0 %then %do;
|
|
71
|
+
%put syscc=&syscc - &sysmacroname will not execute in this state;
|
|
72
|
+
%return;
|
|
73
|
+
%end;
|
|
74
|
+
|
|
75
|
+
/* extract name & path from loc */
|
|
76
|
+
data _null_;
|
|
77
|
+
length name shortloc $500;
|
|
78
|
+
loc=symget('loc');
|
|
79
|
+
name=scan(loc,-1,'/');
|
|
80
|
+
shortloc=substr(loc,1,length(loc)-length(name)-1);
|
|
81
|
+
call symputx('name',name,'l');
|
|
82
|
+
call symputx('shortloc',shortloc,'l');
|
|
83
|
+
run;
|
|
84
|
+
|
|
85
|
+
/* create a combined fileref with original + appended content */
|
|
86
|
+
%let combref=%mf_getuniquefileref();
|
|
87
|
+
%let work=%sysfunc(pathname(work));
|
|
88
|
+
%let tmpfile=&combref..sas;
|
|
89
|
+
filename &combref "&work/&tmpfile" lrecl=32000;
|
|
90
|
+
|
|
91
|
+
%if &platform=SASVIYA %then %do;
|
|
92
|
+
/* On Viya, read the SAS program file from SAS Drive using filesrvc */
|
|
93
|
+
%let viyaref=%mf_getuniquefileref();
|
|
94
|
+
filename &viyaref filesrvc folderpath="&shortloc";
|
|
95
|
+
data _null_;
|
|
96
|
+
file &combref lrecl=32000 termstr=crlf;
|
|
97
|
+
infile &viyaref("&name..sas") lrecl=32000 end=last;
|
|
98
|
+
input;
|
|
99
|
+
put _infile_;
|
|
100
|
+
run;
|
|
101
|
+
filename &viyaref clear;
|
|
102
|
+
%symdel _FILESRVC_&viyaref._URI;
|
|
103
|
+
%end;
|
|
104
|
+
%else %do;
|
|
105
|
+
/* For SAS9 and SASJS, use mx_getcode */
|
|
106
|
+
%let coderef=%mf_getuniquefileref();
|
|
107
|
+
%mx_getcode(&loc, outref=&coderef)
|
|
108
|
+
data _null_;
|
|
109
|
+
file &combref lrecl=32000 termstr=crlf;
|
|
110
|
+
infile &coderef lrecl=32000 end=last;
|
|
111
|
+
input;
|
|
112
|
+
put _infile_;
|
|
113
|
+
run;
|
|
114
|
+
filename &coderef clear;
|
|
115
|
+
%end;
|
|
116
|
+
|
|
117
|
+
/* append the new content */
|
|
118
|
+
data _null_;
|
|
119
|
+
file &combref lrecl=32000 termstr=crlf mod;
|
|
120
|
+
infile &inref lrecl=32000;
|
|
121
|
+
input;
|
|
122
|
+
put _infile_;
|
|
123
|
+
run;
|
|
124
|
+
|
|
125
|
+
/* delete and recreate the target item */
|
|
126
|
+
%if &platform=SASJS %then %do;
|
|
127
|
+
%ms_deletefile(&loc..sas)
|
|
128
|
+
%ms_createfile(&loc..sas, inref=&combref, mdebug=&mdebug)
|
|
129
|
+
%end;
|
|
130
|
+
%else %if &platform=SASVIYA %then %do;
|
|
131
|
+
%mv_deletefoldermember(path=&shortloc, name=&name..sas, contenttype=file)
|
|
132
|
+
%mv_createfile(path=&shortloc, name=&name..sas, inref=&combref)
|
|
133
|
+
%end;
|
|
134
|
+
%else %do;
|
|
135
|
+
/* SAS 9 */
|
|
136
|
+
%mm_deletestp(target=&loc)
|
|
137
|
+
%mm_createstp(stpname=&name
|
|
138
|
+
,filename=&tmpfile
|
|
139
|
+
,directory=&work
|
|
140
|
+
,tree=&shortloc
|
|
141
|
+
,stptype=2
|
|
142
|
+
,mDebug=&mdebug
|
|
143
|
+
,minify=NO
|
|
144
|
+
)
|
|
145
|
+
%end;
|
|
146
|
+
|
|
147
|
+
filename &combref clear;
|
|
148
|
+
|
|
149
|
+
%mend mx_append2pgm;
|