mirror of
https://github.com/sasjs/core.git
synced 2026-01-05 00:20:05 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d63d2a4ec1 | ||
|
|
900f694065 | ||
|
|
838324c15e | ||
|
|
e3205ec06c | ||
|
|
154a33434e | ||
|
|
bfa1bbaeb1 | ||
|
|
1f0128aec4 | ||
|
|
69f03f4e14 |
104
.all-contributorsrc
Normal file
104
.all-contributorsrc
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
{
|
||||||
|
"projectName": "core",
|
||||||
|
"projectOwner": "sasjs",
|
||||||
|
"repoType": "github",
|
||||||
|
"repoHost": "https://github.com",
|
||||||
|
"files": [
|
||||||
|
"README.md"
|
||||||
|
],
|
||||||
|
"imageSize": 100,
|
||||||
|
"commit": false,
|
||||||
|
"commitConvention": "angular",
|
||||||
|
"contributors": [
|
||||||
|
{
|
||||||
|
"login": "allanbowe",
|
||||||
|
"name": "Allan Bowe",
|
||||||
|
"avatar_url": "https://avatars.githubusercontent.com/u/4420615?v=4",
|
||||||
|
"profile": "https://github.com/allanbowe",
|
||||||
|
"contributions": [
|
||||||
|
"business",
|
||||||
|
"code",
|
||||||
|
"content",
|
||||||
|
"doc",
|
||||||
|
"infra",
|
||||||
|
"maintenance",
|
||||||
|
"mentoring",
|
||||||
|
"question",
|
||||||
|
"review",
|
||||||
|
"test"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"login": "rafgag",
|
||||||
|
"name": "rafgag",
|
||||||
|
"avatar_url": "https://avatars.githubusercontent.com/u/69139928?v=4",
|
||||||
|
"profile": "https://github.com/rafgag",
|
||||||
|
"contributions": [
|
||||||
|
"code"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"login": "tmoody",
|
||||||
|
"name": "Trevor Moody",
|
||||||
|
"avatar_url": "https://avatars.githubusercontent.com/u/79837106?v=4",
|
||||||
|
"profile": "https://github.com/tmoody",
|
||||||
|
"contributions": [
|
||||||
|
"code"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"login": "krishna-acondy",
|
||||||
|
"name": "Krishna Acondy",
|
||||||
|
"avatar_url": "https://avatars.githubusercontent.com/u/2980428?v=4",
|
||||||
|
"profile": "https://krishna-acondy.io/",
|
||||||
|
"contributions": [
|
||||||
|
"code",
|
||||||
|
"infra",
|
||||||
|
"blog",
|
||||||
|
"content",
|
||||||
|
"ideas",
|
||||||
|
"video"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"login": "saadjutt01",
|
||||||
|
"name": "Muhammad Saad ",
|
||||||
|
"avatar_url": "https://avatars.githubusercontent.com/u/8914650?v=4",
|
||||||
|
"profile": "https://github.com/saadjutt01",
|
||||||
|
"contributions": [
|
||||||
|
"code",
|
||||||
|
"ideas"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"login": "YuryShkoda",
|
||||||
|
"name": "Yury Shkoda",
|
||||||
|
"avatar_url": "https://avatars.githubusercontent.com/u/25773492?v=4",
|
||||||
|
"profile": "https://www.erudicat.com/",
|
||||||
|
"contributions": [
|
||||||
|
"code",
|
||||||
|
"infra",
|
||||||
|
"video"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"login": "medjedovicm",
|
||||||
|
"name": "Mihajlo Medjedovic",
|
||||||
|
"avatar_url": "https://avatars.githubusercontent.com/u/18329105?v=4",
|
||||||
|
"profile": "https://github.com/medjedovicm",
|
||||||
|
"contributions": [
|
||||||
|
"infra"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"login": "kkchandok",
|
||||||
|
"name": "kkchandok",
|
||||||
|
"avatar_url": "https://avatars.githubusercontent.com/u/46090627?v=4",
|
||||||
|
"profile": "https://github.com/kkchandok",
|
||||||
|
"contributions": [
|
||||||
|
"ideas"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"contributorsPerLine": 7
|
||||||
|
}
|
||||||
31
README.md
31
README.md
@@ -179,3 +179,34 @@ If you find this library useful, please leave a [star](https://github.com/sasjs/
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Contributors ✨
|
||||||
|
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
||||||
|
[](#contributors-)
|
||||||
|
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
||||||
|
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
|
||||||
|
|
||||||
|
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
||||||
|
<!-- prettier-ignore-start -->
|
||||||
|
<!-- markdownlint-disable -->
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td align="center"><a href="https://github.com/allanbowe"><img src="https://avatars.githubusercontent.com/u/4420615?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Allan Bowe</b></sub></a><br /><a href="#business-allanbowe" title="Business development">💼</a> <a href="https://github.com/sasjs/core/commits?author=allanbowe" title="Code">💻</a> <a href="#content-allanbowe" title="Content">🖋</a> <a href="https://github.com/sasjs/core/commits?author=allanbowe" title="Documentation">📖</a> <a href="#infra-allanbowe" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#maintenance-allanbowe" title="Maintenance">🚧</a> <a href="#mentoring-allanbowe" title="Mentoring">🧑🏫</a> <a href="#question-allanbowe" title="Answering Questions">💬</a> <a href="https://github.com/sasjs/core/pulls?q=is%3Apr+reviewed-by%3Aallanbowe" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/sasjs/core/commits?author=allanbowe" title="Tests">⚠️</a></td>
|
||||||
|
<td align="center"><a href="https://github.com/rafgag"><img src="https://avatars.githubusercontent.com/u/69139928?v=4?s=100" width="100px;" alt=""/><br /><sub><b>rafgag</b></sub></a><br /><a href="https://github.com/sasjs/core/commits?author=rafgag" title="Code">💻</a></td>
|
||||||
|
<td align="center"><a href="https://github.com/tmoody"><img src="https://avatars.githubusercontent.com/u/79837106?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Trevor Moody</b></sub></a><br /><a href="https://github.com/sasjs/core/commits?author=tmoody" title="Code">💻</a></td>
|
||||||
|
<td align="center"><a href="https://krishna-acondy.io/"><img src="https://avatars.githubusercontent.com/u/2980428?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Krishna Acondy</b></sub></a><br /><a href="https://github.com/sasjs/core/commits?author=krishna-acondy" title="Code">💻</a> <a href="#infra-krishna-acondy" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#blog-krishna-acondy" title="Blogposts">📝</a> <a href="#content-krishna-acondy" title="Content">🖋</a> <a href="#ideas-krishna-acondy" title="Ideas, Planning, & Feedback">🤔</a> <a href="#video-krishna-acondy" title="Videos">📹</a></td>
|
||||||
|
<td align="center"><a href="https://github.com/saadjutt01"><img src="https://avatars.githubusercontent.com/u/8914650?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Muhammad Saad </b></sub></a><br /><a href="https://github.com/sasjs/core/commits?author=saadjutt01" title="Code">💻</a> <a href="#ideas-saadjutt01" title="Ideas, Planning, & Feedback">🤔</a></td>
|
||||||
|
<td align="center"><a href="https://www.erudicat.com/"><img src="https://avatars.githubusercontent.com/u/25773492?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Yury Shkoda</b></sub></a><br /><a href="https://github.com/sasjs/core/commits?author=YuryShkoda" title="Code">💻</a> <a href="#infra-YuryShkoda" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#video-YuryShkoda" title="Videos">📹</a></td>
|
||||||
|
<td align="center"><a href="https://github.com/medjedovicm"><img src="https://avatars.githubusercontent.com/u/18329105?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Mihajlo Medjedovic</b></sub></a><br /><a href="#infra-medjedovicm" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td align="center"><a href="https://github.com/kkchandok"><img src="https://avatars.githubusercontent.com/u/46090627?v=4?s=100" width="100px;" alt=""/><br /><sub><b>kkchandok</b></sub></a><br /><a href="#ideas-kkchandok" title="Ideas, Planning, & Feedback">🤔</a></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<!-- markdownlint-restore -->
|
||||||
|
<!-- prettier-ignore-end -->
|
||||||
|
|
||||||
|
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
||||||
|
|
||||||
|
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
|
||||||
@@ -76,7 +76,7 @@ run;
|
|||||||
|
|
||||||
%if &outfound=0 %then %do;
|
%if &outfound=0 %then %do;
|
||||||
filename &outref temp lrecl=2097088;
|
filename &outref temp lrecl=2097088;
|
||||||
%%end;
|
%end;
|
||||||
|
|
||||||
%if &action=ENCODE %then %do;
|
%if &action=ENCODE %then %do;
|
||||||
data _null_;
|
data _null_;
|
||||||
@@ -84,12 +84,12 @@ run;
|
|||||||
retain line "";
|
retain line "";
|
||||||
infile &inref recfm=F lrecl= 1 end=eof;
|
infile &inref recfm=F lrecl= 1 end=eof;
|
||||||
input @1 stream $char1.;
|
input @1 stream $char1.;
|
||||||
file &outref lrecl=76;
|
file &outref recfm=N;
|
||||||
substr(line,(_N_-(CEIL(_N_/57)-1)*57),1) = byte(rank(stream));
|
substr(line,(_N_-(CEIL(_N_/57)-1)*57),1) = byte(rank(stream));
|
||||||
if mod(_N_,57)=0 or EOF then do;
|
if mod(_N_,57)=0 or EOF then do;
|
||||||
if eof then b64=put(trim(line),$base64X76.);
|
if eof then b64=put(trim(line),$base64X76.);
|
||||||
else b64=put(line, $base64X76.);
|
else b64=put(line, $base64X76.);
|
||||||
put b64;
|
put b64 + (-1) @;
|
||||||
line="";
|
line="";
|
||||||
end;
|
end;
|
||||||
run;
|
run;
|
||||||
@@ -101,19 +101,13 @@ run;
|
|||||||
fileout = fopen("&outref",'O',3,'B');
|
fileout = fopen("&outref",'O',3,'B');
|
||||||
char= '20'x;
|
char= '20'x;
|
||||||
do while(fread(filein)=0);
|
do while(fread(filein)=0);
|
||||||
raw="1234";
|
length raw $4;
|
||||||
do i=1 to 4;
|
do i=1 to 4;
|
||||||
rc=fget(filein,char,1);
|
rc=fget(filein,char,1);
|
||||||
substr(raw,i,1)=char;
|
substr(raw,i,1)=char;
|
||||||
end;
|
end;
|
||||||
val="123";
|
rc = fput(fileout,input(raw,$base64X4.));
|
||||||
val=input(raw,$base64X4.);
|
rc = fwrite(fileout);
|
||||||
do i=1 to 3;
|
|
||||||
length byte $1;
|
|
||||||
byte=byte(rank(substr(val,i,1)));
|
|
||||||
rc = fput(fileout, byte);
|
|
||||||
end;
|
|
||||||
rc =fwrite(fileout);
|
|
||||||
end;
|
end;
|
||||||
rc = fclose(filein);
|
rc = fclose(filein);
|
||||||
rc = fclose(fileout);
|
rc = fclose(fileout);
|
||||||
|
|||||||
115
base/mp_ds2inserts.sas
Normal file
115
base/mp_ds2inserts.sas
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
/**
|
||||||
|
@file
|
||||||
|
@brief Export a dataset to SQL insert statements
|
||||||
|
@details Converts dataset values to SQL insert statements for use across
|
||||||
|
multiple database types.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
%mp_ds2inserts(sashelp.class,outref=myref,outds=class)
|
||||||
|
data class;
|
||||||
|
set sashelp.class;
|
||||||
|
stop;
|
||||||
|
proc sql;
|
||||||
|
%inc myref;
|
||||||
|
|
||||||
|
@param [in] ds The dataset to be exported
|
||||||
|
@param [out] outref= (0) The output fileref. If it does not exist, it is
|
||||||
|
created. If it does exist, new records are APPENDED.
|
||||||
|
@param [out] outlib= (0) The library (or schema) in which the target table is
|
||||||
|
located. If not provided, is ignored.
|
||||||
|
@param [out] outds= (0) The output table to load. If not provided, will
|
||||||
|
default to the table in the &ds parameter.
|
||||||
|
|
||||||
|
<h4> SAS Macros </h4>
|
||||||
|
@li mf_existfileref.sas
|
||||||
|
@li mf_getvarcount.sas
|
||||||
|
@li mf_getvarlist.sas
|
||||||
|
@li mf_getvartype.sas
|
||||||
|
|
||||||
|
@version 9.2
|
||||||
|
@author Allan Bowe (credit mjsq)
|
||||||
|
**/
|
||||||
|
|
||||||
|
%macro mp_ds2inserts(ds, outref=0,outlib=0,outds=0
|
||||||
|
)/*/STORE SOURCE*/;
|
||||||
|
|
||||||
|
%if not %sysfunc(exist(&ds)) %then %do;
|
||||||
|
%put %str(WARN)ING: &ds does not exist;
|
||||||
|
%return;
|
||||||
|
%end;
|
||||||
|
|
||||||
|
%if %index(&ds,.)=0 %then %let ds=WORK.&ds;
|
||||||
|
|
||||||
|
%if &outref=0 %then %do;
|
||||||
|
%put %str(WARN)ING: Please provide a fileref;
|
||||||
|
%return;
|
||||||
|
%end;
|
||||||
|
%if %mf_existfileref(&outref)=0 %then %do;
|
||||||
|
filename &outref temp lrecl=66000;
|
||||||
|
%end;
|
||||||
|
|
||||||
|
%if &outlib=0 %then %let outlib=;
|
||||||
|
%else %let outlib=&outlib..;
|
||||||
|
|
||||||
|
%if &outds=0 %then %let outds=%scan(&ds,2,.);
|
||||||
|
|
||||||
|
%local nobs;
|
||||||
|
proc sql noprint;
|
||||||
|
select count(*) into: nobs TRIMMED from &ds;
|
||||||
|
%if &nobs=0 %then %do;
|
||||||
|
data _null_;
|
||||||
|
file &outref mod;
|
||||||
|
put "/* No rows found in &ds */";
|
||||||
|
run;
|
||||||
|
%end;
|
||||||
|
|
||||||
|
%local vars;
|
||||||
|
%let vars=%mf_getvarcount(&ds);
|
||||||
|
%if &vars=0 %then %do;
|
||||||
|
data _null_;
|
||||||
|
file &outref mod;
|
||||||
|
put "/* No columns found in &ds */";
|
||||||
|
run;
|
||||||
|
%end;
|
||||||
|
|
||||||
|
%local varlist;
|
||||||
|
%let varlist=%mf_getvarlist(&ds);
|
||||||
|
|
||||||
|
proc format; /* credit yabwon for special null removal */
|
||||||
|
value bart ._ - .z = null
|
||||||
|
other = [best.];
|
||||||
|
/* next, export data */
|
||||||
|
data _null_;
|
||||||
|
file &outref mod ;
|
||||||
|
if _n_=1 then put "/* &outlib.&outds (&nobs rows, &vars columns) */";
|
||||||
|
set &ds;
|
||||||
|
length _____str $32767;
|
||||||
|
format _numeric_ best.;
|
||||||
|
format _character_ ;
|
||||||
|
%local i comma var vtype;
|
||||||
|
%do i=1 %to %sysfunc(countw(&varlist));
|
||||||
|
%let var=%scan(&varlist,&i);
|
||||||
|
%let vtype=%mf_getvartype(&ds,&var);
|
||||||
|
%if &i=1 %then %do;
|
||||||
|
put "insert into &outlib.&outds set ";
|
||||||
|
put " &var="@;
|
||||||
|
%end;
|
||||||
|
%else %do;
|
||||||
|
put " ,&var="@;
|
||||||
|
%end;
|
||||||
|
%if &vtype=N %then %do;
|
||||||
|
/* @todo - deal with nulls in other db flavours */
|
||||||
|
/* from ._ to .z */
|
||||||
|
put &var;
|
||||||
|
%end;
|
||||||
|
%else %do;
|
||||||
|
_____str="'"!!trim(tranwrd(&var,"'","''"))!!"'";
|
||||||
|
put _____str;
|
||||||
|
%end;
|
||||||
|
%end;
|
||||||
|
put ';';
|
||||||
|
if _n_=&nobs then put /;
|
||||||
|
run;
|
||||||
|
|
||||||
|
%mend mp_ds2inserts;
|
||||||
67
tests/base/mp_base64copy.test.sas
Normal file
67
tests/base/mp_base64copy.test.sas
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
/**
|
||||||
|
@file
|
||||||
|
@brief Testing mp_base64copy.sas macro
|
||||||
|
|
||||||
|
<h4> SAS Macros </h4>
|
||||||
|
@li mp_base64copy.sas
|
||||||
|
@li mp_assert.sas
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
|
||||||
|
/* TEST 1 - regular base64 decode */
|
||||||
|
|
||||||
|
%let string1=base ik ally;
|
||||||
|
filename tmp temp;
|
||||||
|
data _null_;
|
||||||
|
file tmp;
|
||||||
|
put "&string1";
|
||||||
|
run;
|
||||||
|
%mp_base64copy(inref=tmp, outref=myref, action=ENCODE)
|
||||||
|
|
||||||
|
data _null_;
|
||||||
|
infile myref;
|
||||||
|
input;
|
||||||
|
put _infile_;
|
||||||
|
run;
|
||||||
|
%mp_base64copy(inref=myref, outref=mynewref, action=DECODE)
|
||||||
|
data _null_;
|
||||||
|
infile mynewref lrecl=5000;
|
||||||
|
input;
|
||||||
|
put _infile_;
|
||||||
|
call symputx('string1_check',_infile_);
|
||||||
|
stop;
|
||||||
|
run;
|
||||||
|
%mp_assert(
|
||||||
|
iftrue=("&string1"="&string1_check"),
|
||||||
|
desc=Basic String Compare,
|
||||||
|
outds=work.test_results
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
/* multibyte string check */
|
||||||
|
|
||||||
|
filename tmp2 temp;
|
||||||
|
data _null_;
|
||||||
|
file tmp2;
|
||||||
|
put "'╤', '╔', '╗', '═', '╧', '╚', '╝', '║', '╟', '─', '┼', '║', '╢', '│'";
|
||||||
|
run;
|
||||||
|
%mp_base64copy(inref=tmp2, outref=myref2, action=ENCODE)
|
||||||
|
|
||||||
|
%mp_base64copy(inref=myref2, outref=newref2, action=DECODE)
|
||||||
|
data _null_;
|
||||||
|
infile newref2 lrecl=5000;
|
||||||
|
input;
|
||||||
|
list;
|
||||||
|
/* do not print the string to the log else viya 3.5 throws exception */
|
||||||
|
if trim(_infile_)=
|
||||||
|
"'╤', '╔', '╗', '═', '╧', '╚', '╝', '║', '╟', '─', '┼', '║', '╢', '│'"
|
||||||
|
then call symputx('check2',1);
|
||||||
|
else call symputx('check2',0);
|
||||||
|
stop;
|
||||||
|
run;
|
||||||
|
%mp_assert(
|
||||||
|
iftrue=("&check2"="1"),
|
||||||
|
desc=Double Byte String Compare,
|
||||||
|
outds=work.test_results
|
||||||
|
)
|
||||||
31
tests/base/mp_ds2inserts.test.sas
Normal file
31
tests/base/mp_ds2inserts.test.sas
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
/**
|
||||||
|
@file
|
||||||
|
@brief Testing mp_ds2inserts.sas macro
|
||||||
|
|
||||||
|
<h4> SAS Macros </h4>
|
||||||
|
@li mp_ds2inserts.sas
|
||||||
|
@li mp_assert.sas
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test 1 - rebuild an existing dataset
|
||||||
|
* Cars is a great dataset - it contains leading spaces, and formatted numerics
|
||||||
|
*/
|
||||||
|
|
||||||
|
%mp_ds2inserts(sashelp.cars,outref=testref,outlib=work,outds=test)
|
||||||
|
|
||||||
|
data work.test;
|
||||||
|
set sashelp.cars;
|
||||||
|
stop;
|
||||||
|
proc sql;
|
||||||
|
%inc testref;
|
||||||
|
|
||||||
|
proc compare base=sashelp.cars compare=work.test;
|
||||||
|
quit;
|
||||||
|
|
||||||
|
%mp_assert(
|
||||||
|
iftrue=(&sysinfo=1),
|
||||||
|
desc=sashelp.cars is identical except for ds label,
|
||||||
|
outds=work.test_results
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user