1
0
mirror of https://github.com/sasjs/core.git synced 2025-12-24 19:51:19 +00:00

Compare commits

...

3 Commits

8 changed files with 53 additions and 16 deletions

16
all.sas
View File

@@ -1806,7 +1806,7 @@ Usage:
/* send response in SASjs JSON format */
data _null_;
file _webout mod lrecl=32000 encoding='utf-8';
length msg $32767 debug $8;
length msg $32767 ;
sasdatetime=datetime();
msg=cats(symget('msg'),'\n\nLog Extract:\n',symget('logmsg'));
/* escape the quotes */
@@ -1837,13 +1837,15 @@ Usage:
_PROGRAM=quote(trim(resolve(symget('_PROGRAM'))));
put ',"_PROGRAM" : ' _PROGRAM ;
put ",""SYSCC"" : ""&syscc"" ";
put ",""SYSERRORTEXT"" : ""&syserrortext"" ";
syserrortext=quote(trim(symget('syserrortext')));
put ",""SYSERRORTEXT"" : " syserrortext;
put ",""SYSHOSTNAME"" : ""&syshostname"" ";
put ",""SYSJOBID"" : ""&sysjobid"" ";
put ",""SYSSITE"" : ""&syssite"" ";
sysvlong=quote(trim(symget('sysvlong')));
put ',"SYSVLONG" : ' sysvlong;
put ",""SYSWARNINGTEXT"" : ""&syswarningtext"" ";
syswarningtext=quote(trim(symget('syswarningtext')));
put ",""SYSWARNINGTEXT"" : " syswarningtext;
put ',"END_DTTM" : "' "%sysfunc(datetime(),datetime20.3)" '" ';
put "}" @;
if debug ge '"131"' then put '>>weboutEND<<';
@@ -5108,7 +5110,7 @@ create table &outds (rename=(
file "&file";
put "&str";
run;
%mp_gsubfile(file=&file, pattern=str, replacement=rep)
%mp_gsubfile(file=&file, patternvar=str, replacevar=rep)
data _null_;
infile "&file";
input;
@@ -18829,7 +18831,7 @@ data _null_;
put ' ';
put '-- open file and perform the substitution ';
put 'file = io.open(fpath,"r") ';
put 'fcontent = file:read() ';
put 'fcontent = file:read("*all") ';
put 'file:close() ';
put 'fcontent = string.gsub( ';
put ' fcontent, ';
@@ -18844,7 +18846,7 @@ data _null_;
put 'io.close(file) ';
run;
%inc "%sysfunc(pathname(work))/ml_gsubfile.lua";
%inc "%sysfunc(pathname(work))/ml_gsubfile.lua" /source2;
%mend ml_gsubfile;
/**
@@ -19238,7 +19240,7 @@ data _null_;
put '-- JSON.LUA ENDS HERE ';
run;
%inc "%sysfunc(pathname(work))/ml_json.lua";
%inc "%sysfunc(pathname(work))/ml_json.lua" /source2;
%mend ml_json;
/**

View File

@@ -158,7 +158,7 @@
/* send response in SASjs JSON format */
data _null_;
file _webout mod lrecl=32000 encoding='utf-8';
length msg $32767 debug $8;
length msg $32767 ;
sasdatetime=datetime();
msg=cats(symget('msg'),'\n\nLog Extract:\n',symget('logmsg'));
/* escape the quotes */
@@ -189,13 +189,15 @@
_PROGRAM=quote(trim(resolve(symget('_PROGRAM'))));
put ',"_PROGRAM" : ' _PROGRAM ;
put ",""SYSCC"" : ""&syscc"" ";
put ",""SYSERRORTEXT"" : ""&syserrortext"" ";
syserrortext=quote(trim(symget('syserrortext')));
put ",""SYSERRORTEXT"" : " syserrortext;
put ",""SYSHOSTNAME"" : ""&syshostname"" ";
put ",""SYSJOBID"" : ""&sysjobid"" ";
put ",""SYSSITE"" : ""&syssite"" ";
sysvlong=quote(trim(symget('sysvlong')));
put ',"SYSVLONG" : ' sysvlong;
put ",""SYSWARNINGTEXT"" : ""&syswarningtext"" ";
syswarningtext=quote(trim(symget('syswarningtext')));
put ",""SYSWARNINGTEXT"" : " syswarningtext;
put ',"END_DTTM" : "' "%sysfunc(datetime(),datetime20.3)" '" ';
put "}" @;
if debug ge '"131"' then put '>>weboutEND<<';

View File

@@ -15,7 +15,7 @@
file "&file";
put "&str";
run;
%mp_gsubfile(file=&file, pattern=str, replacement=rep)
%mp_gsubfile(file=&file, patternvar=str, replacevar=rep)
data _null_;
infile "&file";
input;

View File

@@ -22,7 +22,7 @@ for file in files:
for line in infile:
ml.write(" put '" + line.rstrip().replace("'","''") + " ';\n")
ml.write("run;\n\n")
ml.write("%inc \"%sysfunc(pathname(work))/" + name + ".lua\";\n\n")
ml.write("%inc \"%sysfunc(pathname(work))/" + name + ".lua\" /source2;\n\n")
ml.write("%mend " + name + ";\n")
ml.close()

View File

@@ -10,7 +10,7 @@ end
-- open file and perform the substitution
file = io.open(fpath,"r")
fcontent = file:read()
fcontent = file:read("*all")
file:close()
fcontent = string.gsub(
fcontent,

View File

@@ -24,7 +24,7 @@ data _null_;
put ' ';
put '-- open file and perform the substitution ';
put 'file = io.open(fpath,"r") ';
put 'fcontent = file:read() ';
put 'fcontent = file:read("*all") ';
put 'file:close() ';
put 'fcontent = string.gsub( ';
put ' fcontent, ';
@@ -39,6 +39,6 @@ data _null_;
put 'io.close(file) ';
run;
%inc "%sysfunc(pathname(work))/ml_gsubfile.lua";
%inc "%sysfunc(pathname(work))/ml_gsubfile.lua" /source2;
%mend ml_gsubfile;

View File

@@ -389,6 +389,6 @@ data _null_;
put '-- JSON.LUA ENDS HERE ';
run;
%inc "%sysfunc(pathname(work))/ml_json.lua";
%inc "%sysfunc(pathname(work))/ml_json.lua" /source2;
%mend ml_json;

View File

@@ -30,4 +30,37 @@ run;
iftrue=("&str1"="&str"),
desc=Check that simple replacement was successful,
outds=work.test_results
)
/**
* test 2 - replace from additional line
*/
%global str2 strcheck2 strcheck2b;
%let file2=%sysfunc(pathname(work))/file2.txt;
%let pat2=replace/me;
%let str2=with/this;
data _null_;
file "&file2";
put 'line1';output;
put "&pat2";output;
put "&pat2";output;
run;
%mp_gsubfile(file=&file2, patternvar=pat2, replacevar=str2)
data _null_;
infile "&file2";
input;
if _n_=2 then call symputx('strcheck2',_infile_);
if _n_=3 then call symputx('strcheck2b',_infile_);
putlog _infile_;
run;
%mp_assert(
iftrue=("&strcheck2"="&str2"),
desc=Check that multi line replacement was successful (line2),
outds=work.test_results
)
%mp_assert(
iftrue=("&strcheck2b"="&str2"),
desc=Check that multi line replacement was successful (line3),
outds=work.test_results
)