mirror of
https://github.com/sasjs/core.git
synced 2026-01-07 09:30:06 +00:00
fix: adding fileref options and an additional test for mp_binarycopy
This commit is contained in:
46
all.sas
46
all.sas
@@ -3470,8 +3470,8 @@ run;
|
|||||||
@details Reads in a file byte by byte and writes it back out. Is an
|
@details Reads in a file byte by byte and writes it back out. Is an
|
||||||
os-independent method to copy files. In case of naming collision, the
|
os-independent method to copy files. In case of naming collision, the
|
||||||
default filerefs can be modified.
|
default filerefs can be modified.
|
||||||
Based on:
|
Note that if you have a new enough version of SAS, and you don't need features
|
||||||
https://stackoverflow.com/questions/13046116/using-sas-to-copy-a-text-file
|
such as APPEND, you may be better of using the fcopy() function instead.
|
||||||
|
|
||||||
%mp_binarycopy(inloc="/home/me/blah.txt", outref=_webout)
|
%mp_binarycopy(inloc="/home/me/blah.txt", outref=_webout)
|
||||||
|
|
||||||
@@ -3511,14 +3511,9 @@ run;
|
|||||||
,outref=____out /* override default to use own filerefs */
|
,outref=____out /* override default to use own filerefs */
|
||||||
,mode=CREATE
|
,mode=CREATE
|
||||||
)/*/STORE SOURCE*/;
|
)/*/STORE SOURCE*/;
|
||||||
%local mod outmode;
|
%local mod;
|
||||||
%if &mode=APPEND %then %do;
|
%if &mode=APPEND %then %let mod=mod;
|
||||||
%let mod=mod;
|
|
||||||
%let outmode='a';
|
|
||||||
%end;
|
|
||||||
%else %do;
|
|
||||||
%let outmode='o';
|
|
||||||
%end;
|
|
||||||
/* these IN and OUT filerefs can point to anything */
|
/* these IN and OUT filerefs can point to anything */
|
||||||
%if &inref = ____in %then %do;
|
%if &inref = ____in %then %do;
|
||||||
filename &inref &inloc lrecl=1048576 ;
|
filename &inref &inloc lrecl=1048576 ;
|
||||||
@@ -3529,8 +3524,8 @@ run;
|
|||||||
|
|
||||||
/* copy the file byte-for-byte */
|
/* copy the file byte-for-byte */
|
||||||
data _null_;
|
data _null_;
|
||||||
infile &inref;
|
infile &inref lrecl=1 recfm=n;
|
||||||
file &outref;
|
file &outref &mod recfm=n;
|
||||||
input sourcechar $char1. @@;
|
input sourcechar $char1. @@;
|
||||||
format sourcechar hex2.;
|
format sourcechar hex2.;
|
||||||
put sourcechar char1. @@;
|
put sourcechar char1. @@;
|
||||||
@@ -3542,7 +3537,8 @@ run;
|
|||||||
%if &outref=____out %then %do;
|
%if &outref=____out %then %do;
|
||||||
filename &outref clear;
|
filename &outref clear;
|
||||||
%end;
|
%end;
|
||||||
%mend mp_binarycopy;/**
|
%mend mp_binarycopy;
|
||||||
|
/**
|
||||||
@file
|
@file
|
||||||
@brief Splits a file of ANY SIZE by reference to a search string.
|
@brief Splits a file of ANY SIZE by reference to a search string.
|
||||||
@details Provide a fileref and a search string to chop off part of a file.
|
@details Provide a fileref and a search string to chop off part of a file.
|
||||||
@@ -8812,10 +8808,10 @@ options
|
|||||||
"&&name&i"n /* name literal for reserved variable names */
|
"&&name&i"n /* name literal for reserved variable names */
|
||||||
%end;
|
%end;
|
||||||
%if &action=ARR %then "]" ; %else "}" ; ;
|
%if &action=ARR %then "]" ; %else "}" ; ;
|
||||||
/* now write the long strings to _webout 1 byte at a time */
|
/* now write the long strings to _webout 1 char at a time */
|
||||||
data _null_;
|
data _null_;
|
||||||
infile _sjs;
|
infile _sjs lrecl=1 recfm=n;
|
||||||
file &jref mod;
|
file &jref mod lrecl=1 recfm=n;
|
||||||
input sourcechar $char1. @@;
|
input sourcechar $char1. @@;
|
||||||
format sourcechar hex2.;
|
format sourcechar hex2.;
|
||||||
put sourcechar char1. @@;
|
put sourcechar char1. @@;
|
||||||
@@ -15189,10 +15185,10 @@ data _null_;
|
|||||||
put ' "&&name&i"n /* name literal for reserved variable names */ ';
|
put ' "&&name&i"n /* name literal for reserved variable names */ ';
|
||||||
put ' %end; ';
|
put ' %end; ';
|
||||||
put ' %if &action=ARR %then "]" ; %else "}" ; ; ';
|
put ' %if &action=ARR %then "]" ; %else "}" ; ; ';
|
||||||
put ' /* now write the long strings to _webout 1 byte at a time */ ';
|
put ' /* now write the long strings to _webout 1 char at a time */ ';
|
||||||
put ' data _null_; ';
|
put ' data _null_; ';
|
||||||
put ' infile _sjs; ';
|
put ' infile _sjs lrecl=1 recfm=n; ';
|
||||||
put ' file &jref mod; ';
|
put ' file &jref mod lrecl=1 recfm=n; ';
|
||||||
put ' input sourcechar $char1. @@; ';
|
put ' input sourcechar $char1. @@; ';
|
||||||
put ' format sourcechar hex2.; ';
|
put ' format sourcechar hex2.; ';
|
||||||
put ' put sourcechar char1. @@; ';
|
put ' put sourcechar char1. @@; ';
|
||||||
@@ -19922,10 +19918,10 @@ data _null_;
|
|||||||
put ' "&&name&i"n /* name literal for reserved variable names */ ';
|
put ' "&&name&i"n /* name literal for reserved variable names */ ';
|
||||||
put ' %end; ';
|
put ' %end; ';
|
||||||
put ' %if &action=ARR %then "]" ; %else "}" ; ; ';
|
put ' %if &action=ARR %then "]" ; %else "}" ; ; ';
|
||||||
put ' /* now write the long strings to _webout 1 byte at a time */ ';
|
put ' /* now write the long strings to _webout 1 char at a time */ ';
|
||||||
put ' data _null_; ';
|
put ' data _null_; ';
|
||||||
put ' infile _sjs; ';
|
put ' infile _sjs lrecl=1 recfm=n; ';
|
||||||
put ' file &jref mod; ';
|
put ' file &jref mod lrecl=1 recfm=n; ';
|
||||||
put ' input sourcechar $char1. @@; ';
|
put ' input sourcechar $char1. @@; ';
|
||||||
put ' format sourcechar hex2.; ';
|
put ' format sourcechar hex2.; ';
|
||||||
put ' put sourcechar char1. @@; ';
|
put ' put sourcechar char1. @@; ';
|
||||||
@@ -22263,10 +22259,10 @@ data _null_;
|
|||||||
put ' "&&name&i"n /* name literal for reserved variable names */ ';
|
put ' "&&name&i"n /* name literal for reserved variable names */ ';
|
||||||
put ' %end; ';
|
put ' %end; ';
|
||||||
put ' %if &action=ARR %then "]" ; %else "}" ; ; ';
|
put ' %if &action=ARR %then "]" ; %else "}" ; ; ';
|
||||||
put ' /* now write the long strings to _webout 1 byte at a time */ ';
|
put ' /* now write the long strings to _webout 1 char at a time */ ';
|
||||||
put ' data _null_; ';
|
put ' data _null_; ';
|
||||||
put ' infile _sjs; ';
|
put ' infile _sjs lrecl=1 recfm=n; ';
|
||||||
put ' file &jref mod; ';
|
put ' file &jref mod lrecl=1 recfm=n; ';
|
||||||
put ' input sourcechar $char1. @@; ';
|
put ' input sourcechar $char1. @@; ';
|
||||||
put ' format sourcechar hex2.; ';
|
put ' format sourcechar hex2.; ';
|
||||||
put ' put sourcechar char1. @@; ';
|
put ' put sourcechar char1. @@; ';
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
@details Reads in a file byte by byte and writes it back out. Is an
|
@details Reads in a file byte by byte and writes it back out. Is an
|
||||||
os-independent method to copy files. In case of naming collision, the
|
os-independent method to copy files. In case of naming collision, the
|
||||||
default filerefs can be modified.
|
default filerefs can be modified.
|
||||||
Based on:
|
Note that if you have a new enough version of SAS, and you don't need features
|
||||||
https://stackoverflow.com/questions/13046116/using-sas-to-copy-a-text-file
|
such as APPEND, you may be better of using the fcopy() function instead.
|
||||||
|
|
||||||
%mp_binarycopy(inloc="/home/me/blah.txt", outref=_webout)
|
%mp_binarycopy(inloc="/home/me/blah.txt", outref=_webout)
|
||||||
|
|
||||||
@@ -45,14 +45,9 @@
|
|||||||
,outref=____out /* override default to use own filerefs */
|
,outref=____out /* override default to use own filerefs */
|
||||||
,mode=CREATE
|
,mode=CREATE
|
||||||
)/*/STORE SOURCE*/;
|
)/*/STORE SOURCE*/;
|
||||||
%local mod outmode;
|
%local mod;
|
||||||
%if &mode=APPEND %then %do;
|
%if &mode=APPEND %then %let mod=mod;
|
||||||
%let mod=mod;
|
|
||||||
%let outmode='a';
|
|
||||||
%end;
|
|
||||||
%else %do;
|
|
||||||
%let outmode='o';
|
|
||||||
%end;
|
|
||||||
/* these IN and OUT filerefs can point to anything */
|
/* these IN and OUT filerefs can point to anything */
|
||||||
%if &inref = ____in %then %do;
|
%if &inref = ____in %then %do;
|
||||||
filename &inref &inloc lrecl=1048576 ;
|
filename &inref &inloc lrecl=1048576 ;
|
||||||
@@ -63,8 +58,8 @@
|
|||||||
|
|
||||||
/* copy the file byte-for-byte */
|
/* copy the file byte-for-byte */
|
||||||
data _null_;
|
data _null_;
|
||||||
infile &inref;
|
infile &inref lrecl=1 recfm=n;
|
||||||
file &outref;
|
file &outref &mod recfm=n;
|
||||||
input sourcechar $char1. @@;
|
input sourcechar $char1. @@;
|
||||||
format sourcechar hex2.;
|
format sourcechar hex2.;
|
||||||
put sourcechar char1. @@;
|
put sourcechar char1. @@;
|
||||||
|
|||||||
@@ -234,10 +234,10 @@
|
|||||||
"&&name&i"n /* name literal for reserved variable names */
|
"&&name&i"n /* name literal for reserved variable names */
|
||||||
%end;
|
%end;
|
||||||
%if &action=ARR %then "]" ; %else "}" ; ;
|
%if &action=ARR %then "]" ; %else "}" ; ;
|
||||||
/* now write the long strings to _webout 1 byte at a time */
|
/* now write the long strings to _webout 1 char at a time */
|
||||||
data _null_;
|
data _null_;
|
||||||
infile _sjs;
|
infile _sjs lrecl=1 recfm=n;
|
||||||
file &jref mod;
|
file &jref mod lrecl=1 recfm=n;
|
||||||
input sourcechar $char1. @@;
|
input sourcechar $char1. @@;
|
||||||
format sourcechar hex2.;
|
format sourcechar hex2.;
|
||||||
put sourcechar char1. @@;
|
put sourcechar char1. @@;
|
||||||
|
|||||||
@@ -268,10 +268,10 @@ data _null_;
|
|||||||
put ' "&&name&i"n /* name literal for reserved variable names */ ';
|
put ' "&&name&i"n /* name literal for reserved variable names */ ';
|
||||||
put ' %end; ';
|
put ' %end; ';
|
||||||
put ' %if &action=ARR %then "]" ; %else "}" ; ; ';
|
put ' %if &action=ARR %then "]" ; %else "}" ; ; ';
|
||||||
put ' /* now write the long strings to _webout 1 byte at a time */ ';
|
put ' /* now write the long strings to _webout 1 char at a time */ ';
|
||||||
put ' data _null_; ';
|
put ' data _null_; ';
|
||||||
put ' infile _sjs; ';
|
put ' infile _sjs lrecl=1 recfm=n; ';
|
||||||
put ' file &jref mod; ';
|
put ' file &jref mod lrecl=1 recfm=n; ';
|
||||||
put ' input sourcechar $char1. @@; ';
|
put ' input sourcechar $char1. @@; ';
|
||||||
put ' format sourcechar hex2.; ';
|
put ' format sourcechar hex2.; ';
|
||||||
put ' put sourcechar char1. @@; ';
|
put ' put sourcechar char1. @@; ';
|
||||||
|
|||||||
@@ -67,6 +67,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "server",
|
"name": "server",
|
||||||
|
"serverUrl": "",
|
||||||
"serverType": "SASJS",
|
"serverType": "SASJS",
|
||||||
"httpsAgentOptions": {
|
"httpsAgentOptions": {
|
||||||
"allowInsecureRequests": false
|
"allowInsecureRequests": false
|
||||||
|
|||||||
@@ -269,10 +269,10 @@ data _null_;
|
|||||||
put ' "&&name&i"n /* name literal for reserved variable names */ ';
|
put ' "&&name&i"n /* name literal for reserved variable names */ ';
|
||||||
put ' %end; ';
|
put ' %end; ';
|
||||||
put ' %if &action=ARR %then "]" ; %else "}" ; ; ';
|
put ' %if &action=ARR %then "]" ; %else "}" ; ; ';
|
||||||
put ' /* now write the long strings to _webout 1 byte at a time */ ';
|
put ' /* now write the long strings to _webout 1 char at a time */ ';
|
||||||
put ' data _null_; ';
|
put ' data _null_; ';
|
||||||
put ' infile _sjs; ';
|
put ' infile _sjs lrecl=1 recfm=n; ';
|
||||||
put ' file &jref mod; ';
|
put ' file &jref mod lrecl=1 recfm=n; ';
|
||||||
put ' input sourcechar $char1. @@; ';
|
put ' input sourcechar $char1. @@; ';
|
||||||
put ' format sourcechar hex2.; ';
|
put ' format sourcechar hex2.; ';
|
||||||
put ' put sourcechar char1. @@; ';
|
put ' put sourcechar char1. @@; ';
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
<h4> SAS Macros </h4>
|
<h4> SAS Macros </h4>
|
||||||
@li mp_binarycopy.sas
|
@li mp_binarycopy.sas
|
||||||
@li mp_assert.sas
|
@li mp_assert.sas
|
||||||
|
@li mp_hashdataset.sas
|
||||||
|
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@@ -97,3 +98,39 @@ run;
|
|||||||
desc=Append Check (ref to file),
|
desc=Append Check (ref to file),
|
||||||
outds=work.test_results
|
outds=work.test_results
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/* test 5 - ensure copy works for binary characters */
|
||||||
|
/* do this backwards to avoid null chars in JSON preview */
|
||||||
|
data work.test5;
|
||||||
|
do i=255 to 1 by -1;
|
||||||
|
str=byte(i);
|
||||||
|
output;
|
||||||
|
end;
|
||||||
|
run;
|
||||||
|
/* get an md5 hash of the ds */
|
||||||
|
%mp_hashdataset(work.test5,outds=myhash)
|
||||||
|
|
||||||
|
/* copy it */
|
||||||
|
%mp_binarycopy(inloc="%sysfunc(pathname(work))/test5.sas7bdat",
|
||||||
|
outloc="%sysfunc(pathname(work))/test5copy.sas7bdat"
|
||||||
|
)
|
||||||
|
|
||||||
|
/* get an md5 hash of the copied ds */
|
||||||
|
%mp_hashdataset(work.test5copy,outds=myhash2)
|
||||||
|
|
||||||
|
/* compare hashes */
|
||||||
|
%let test5a=0;
|
||||||
|
%let test5b=1;
|
||||||
|
data _null_;
|
||||||
|
set myhash;
|
||||||
|
call symputx('test5a',hashkey);
|
||||||
|
run;
|
||||||
|
data _null_;
|
||||||
|
set myhash2;
|
||||||
|
call symputx('test5b',hashkey);
|
||||||
|
run;
|
||||||
|
%mp_assert(
|
||||||
|
iftrue=("&test5a"="&test5b"),
|
||||||
|
desc=Ensuring binary copy works on binary characters,
|
||||||
|
outds=work.test_results
|
||||||
|
)
|
||||||
|
|||||||
@@ -411,10 +411,10 @@ data _null_;
|
|||||||
put ' "&&name&i"n /* name literal for reserved variable names */ ';
|
put ' "&&name&i"n /* name literal for reserved variable names */ ';
|
||||||
put ' %end; ';
|
put ' %end; ';
|
||||||
put ' %if &action=ARR %then "]" ; %else "}" ; ; ';
|
put ' %if &action=ARR %then "]" ; %else "}" ; ; ';
|
||||||
put ' /* now write the long strings to _webout 1 byte at a time */ ';
|
put ' /* now write the long strings to _webout 1 char at a time */ ';
|
||||||
put ' data _null_; ';
|
put ' data _null_; ';
|
||||||
put ' infile _sjs; ';
|
put ' infile _sjs lrecl=1 recfm=n; ';
|
||||||
put ' file &jref mod; ';
|
put ' file &jref mod lrecl=1 recfm=n; ';
|
||||||
put ' input sourcechar $char1. @@; ';
|
put ' input sourcechar $char1. @@; ';
|
||||||
put ' format sourcechar hex2.; ';
|
put ' format sourcechar hex2.; ';
|
||||||
put ' put sourcechar char1. @@; ';
|
put ' put sourcechar char1. @@; ';
|
||||||
|
|||||||
Reference in New Issue
Block a user