mirror of
https://github.com/sasjs/core.git
synced 2025-12-21 02:01:20 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| abccafab7b | |||
| f6cec012da | |||
| d51be73017 |
92
all.sas
92
all.sas
@@ -399,7 +399,7 @@ options noquotelenmax;
|
|||||||
@version 9.2
|
@version 9.2
|
||||||
@author Allan Bowe
|
@author Allan Bowe
|
||||||
|
|
||||||
**/ /** \cond */
|
**/
|
||||||
|
|
||||||
%macro mf_getengine(libref
|
%macro mf_getengine(libref
|
||||||
)/*/STORE SOURCE*/;
|
)/*/STORE SOURCE*/;
|
||||||
@@ -419,9 +419,7 @@ options noquotelenmax;
|
|||||||
|
|
||||||
&engine
|
&engine
|
||||||
|
|
||||||
%mend;
|
%mend;/**
|
||||||
|
|
||||||
/** \endcond *//**
|
|
||||||
@file
|
@file
|
||||||
@brief Returns the size of a file in bytes.
|
@brief Returns the size of a file in bytes.
|
||||||
@details Provide full path/filename.extension to the file, eg:
|
@details Provide full path/filename.extension to the file, eg:
|
||||||
@@ -1933,29 +1931,50 @@ Usage:
|
|||||||
|
|
||||||
@version 9.2
|
@version 9.2
|
||||||
@author Allan Bowe
|
@author Allan Bowe
|
||||||
|
|
||||||
|
<h4> Dependencies </h4>
|
||||||
|
@li mp_abort.sas
|
||||||
|
@li mf_existds.sas
|
||||||
|
|
||||||
**/
|
**/
|
||||||
|
|
||||||
%macro mp_csv2ds(inref=0,outds=0,baseds=0);
|
%macro mp_csv2ds(inref=0,outds=0,baseds=0,view=NO);
|
||||||
%if &inref=0 %then %do;
|
|
||||||
%put %str(ERR)OR: the INREF variable must be provided;
|
%mp_abort(iftrue=( &inref=0 )
|
||||||
%let syscc=4;
|
,mac=&sysmacroname
|
||||||
%abort;
|
,msg=%str(the INREF variable must be provided)
|
||||||
%end;
|
)
|
||||||
%if %superq(outds)=0 %then %do;
|
%mp_abort(iftrue=( %superq(outds)=0 )
|
||||||
%put %str(ERR)OR: the OUTDS variable must be provided;
|
,mac=&sysmacroname
|
||||||
%let syscc=4;
|
,msg=%str(the OUTDS variable must be provided)
|
||||||
%return;
|
)
|
||||||
%end;
|
%mp_abort(iftrue=( &baseds=0 )
|
||||||
%if &baseds=0 %then %do;
|
,mac=&sysmacroname
|
||||||
%put %str(ERR)OR: the BASEDS variable must be provided;
|
,msg=%str(the BASEDS variable must be provided)
|
||||||
%let syscc=4;
|
)
|
||||||
%return;
|
%mp_abort(iftrue=( &baseds=0 )
|
||||||
%end;
|
,mac=&sysmacroname
|
||||||
%if %sysfunc(exist(&BASEDS)) ne 1 & %sysfunc(exist(&BASEDS,VIEW)) ne 1 %then %do;
|
,msg=%str(the BASEDS variable must be provided)
|
||||||
%put %str(ERR)OR: the BASEDS dataset needs to be assigned, and to exist;
|
)
|
||||||
%let syscc=4;
|
%mp_abort(iftrue=( %mf_existds(&baseds)=0 )
|
||||||
%return;
|
,mac=&sysmacroname
|
||||||
%end;
|
,msg=%str(the BASEDS dataset (&baseds) needs to be assigned, and to exist)
|
||||||
|
)
|
||||||
|
|
||||||
|
/* count rows */
|
||||||
|
%local hasheader; %let hasheader=0;
|
||||||
|
data _null_;
|
||||||
|
if _N_ > 1 then do;
|
||||||
|
call symputx('hasheader',1,'l');
|
||||||
|
stop;
|
||||||
|
end;
|
||||||
|
infile &inref;
|
||||||
|
input;
|
||||||
|
run;
|
||||||
|
%mp_abort(iftrue=( &hasheader=0 )
|
||||||
|
,mac=&sysmacroname
|
||||||
|
,msg=%str(No header row in &inref)
|
||||||
|
)
|
||||||
|
|
||||||
/* get the variables in the CSV */
|
/* get the variables in the CSV */
|
||||||
data _data_;
|
data _data_;
|
||||||
@@ -2020,7 +2039,9 @@ data &outds
|
|||||||
;
|
;
|
||||||
infile &inref dsd firstobs=2;
|
infile &inref dsd firstobs=2;
|
||||||
input &instat;
|
input &instat;
|
||||||
drop &dropvars;
|
%if %length(&dropvars)>0 %then %do;
|
||||||
|
drop &dropvars;
|
||||||
|
%end;
|
||||||
run;
|
run;
|
||||||
|
|
||||||
%mend;/**
|
%mend;/**
|
||||||
@@ -4090,7 +4111,7 @@ proc sql
|
|||||||
|
|
||||||
options &etls_syntaxcheck;
|
options &etls_syntaxcheck;
|
||||||
%mend;/**
|
%mend;/**
|
||||||
@file mp_streamfile.sas
|
@file
|
||||||
@brief Streams a file to _webout according to content type
|
@brief Streams a file to _webout according to content type
|
||||||
@details Will set headers using appropriate functions (SAS 9 vs Viya) and send
|
@details Will set headers using appropriate functions (SAS 9 vs Viya) and send
|
||||||
content as a binary stream.
|
content as a binary stream.
|
||||||
@@ -4108,6 +4129,7 @@ proc sql
|
|||||||
|
|
||||||
@param contenttype= Either TEXT, ZIP, CSV, EXCEL (default TEXT)
|
@param contenttype= Either TEXT, ZIP, CSV, EXCEL (default TEXT)
|
||||||
@param inloc= /path/to/file.ext to be sent
|
@param inloc= /path/to/file.ext to be sent
|
||||||
|
@param inref= fileref of file to be sent (if provided, overrides `inloc`)
|
||||||
@param outname= the name of the file, as downloaded by the browser
|
@param outname= the name of the file, as downloaded by the browser
|
||||||
|
|
||||||
@author Allan Bowe
|
@author Allan Bowe
|
||||||
@@ -4118,6 +4140,7 @@ proc sql
|
|||||||
%macro mp_streamfile(
|
%macro mp_streamfile(
|
||||||
contenttype=TEXT
|
contenttype=TEXT
|
||||||
,inloc=
|
,inloc=
|
||||||
|
,inref=0
|
||||||
,outname=
|
,outname=
|
||||||
)/*/STORE SOURCE*/;
|
)/*/STORE SOURCE*/;
|
||||||
|
|
||||||
@@ -4133,7 +4156,7 @@ proc sql
|
|||||||
%end;
|
%end;
|
||||||
%else %if &platform=SASVIYA %then %do;
|
%else %if &platform=SASVIYA %then %do;
|
||||||
filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name='_webout.zip'
|
filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name='_webout.zip'
|
||||||
contenttype='application/zip'
|
contenttype='application/zip'
|
||||||
contentdisp="attachment; filename=&outname";
|
contentdisp="attachment; filename=&outname";
|
||||||
%end;
|
%end;
|
||||||
%end;
|
%end;
|
||||||
@@ -4147,7 +4170,7 @@ proc sql
|
|||||||
%end;
|
%end;
|
||||||
%else %if &platform=SASVIYA %then %do;
|
%else %if &platform=SASVIYA %then %do;
|
||||||
filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name='_webout.xls'
|
filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name='_webout.xls'
|
||||||
contenttype='application/vnd.ms-excel'
|
contenttype='application/vnd.ms-excel'
|
||||||
contentdisp="attachment; filename=&outname";
|
contentdisp="attachment; filename=&outname";
|
||||||
%end;
|
%end;
|
||||||
%end;
|
%end;
|
||||||
@@ -4160,7 +4183,7 @@ proc sql
|
|||||||
%end;
|
%end;
|
||||||
%else %if &platform=SASVIYA %then %do;
|
%else %if &platform=SASVIYA %then %do;
|
||||||
filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name='_webout.xls'
|
filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name='_webout.xls'
|
||||||
contenttype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
contenttype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
||||||
contentdisp="attachment; filename=&outname";
|
contentdisp="attachment; filename=&outname";
|
||||||
%end;
|
%end;
|
||||||
%end;
|
%end;
|
||||||
@@ -4193,7 +4216,7 @@ proc sql
|
|||||||
%else %if &contentype=HTML %then %do;
|
%else %if &contentype=HTML %then %do;
|
||||||
%if &platform=SASVIYA %then %do;
|
%if &platform=SASVIYA %then %do;
|
||||||
filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name="_webout.json"
|
filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name="_webout.json"
|
||||||
contenttype="text/html";
|
contenttype="text/html";
|
||||||
%end;
|
%end;
|
||||||
%end;
|
%end;
|
||||||
%else %do;
|
%else %do;
|
||||||
@@ -4201,7 +4224,12 @@ proc sql
|
|||||||
%return;
|
%return;
|
||||||
%end;
|
%end;
|
||||||
|
|
||||||
%mp_binarycopy(inloc="&inloc",outref=_webout)
|
%if &inref ne 0 %then %do;
|
||||||
|
%mp_binarycopy(inref=&inref,outref=_webout)
|
||||||
|
%end;
|
||||||
|
%else %do;
|
||||||
|
%mp_binarycopy(inloc="&inloc",outref=_webout)
|
||||||
|
%end;
|
||||||
|
|
||||||
%mend;/**
|
%mend;/**
|
||||||
@file mp_unzip.sas
|
@file mp_unzip.sas
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
@version 9.2
|
@version 9.2
|
||||||
@author Allan Bowe
|
@author Allan Bowe
|
||||||
|
|
||||||
**/ /** \cond */
|
**/
|
||||||
|
|
||||||
%macro mf_getengine(libref
|
%macro mf_getengine(libref
|
||||||
)/*/STORE SOURCE*/;
|
)/*/STORE SOURCE*/;
|
||||||
@@ -42,6 +42,4 @@
|
|||||||
|
|
||||||
&engine
|
&engine
|
||||||
|
|
||||||
%mend;
|
%mend;
|
||||||
|
|
||||||
/** \endcond */
|
|
||||||
@@ -28,29 +28,50 @@
|
|||||||
|
|
||||||
@version 9.2
|
@version 9.2
|
||||||
@author Allan Bowe
|
@author Allan Bowe
|
||||||
|
|
||||||
|
<h4> Dependencies </h4>
|
||||||
|
@li mp_abort.sas
|
||||||
|
@li mf_existds.sas
|
||||||
|
|
||||||
**/
|
**/
|
||||||
|
|
||||||
%macro mp_csv2ds(inref=0,outds=0,baseds=0);
|
%macro mp_csv2ds(inref=0,outds=0,baseds=0,view=NO);
|
||||||
%if &inref=0 %then %do;
|
|
||||||
%put %str(ERR)OR: the INREF variable must be provided;
|
%mp_abort(iftrue=( &inref=0 )
|
||||||
%let syscc=4;
|
,mac=&sysmacroname
|
||||||
%abort;
|
,msg=%str(the INREF variable must be provided)
|
||||||
%end;
|
)
|
||||||
%if %superq(outds)=0 %then %do;
|
%mp_abort(iftrue=( %superq(outds)=0 )
|
||||||
%put %str(ERR)OR: the OUTDS variable must be provided;
|
,mac=&sysmacroname
|
||||||
%let syscc=4;
|
,msg=%str(the OUTDS variable must be provided)
|
||||||
%return;
|
)
|
||||||
%end;
|
%mp_abort(iftrue=( &baseds=0 )
|
||||||
%if &baseds=0 %then %do;
|
,mac=&sysmacroname
|
||||||
%put %str(ERR)OR: the BASEDS variable must be provided;
|
,msg=%str(the BASEDS variable must be provided)
|
||||||
%let syscc=4;
|
)
|
||||||
%return;
|
%mp_abort(iftrue=( &baseds=0 )
|
||||||
%end;
|
,mac=&sysmacroname
|
||||||
%if %sysfunc(exist(&BASEDS)) ne 1 & %sysfunc(exist(&BASEDS,VIEW)) ne 1 %then %do;
|
,msg=%str(the BASEDS variable must be provided)
|
||||||
%put %str(ERR)OR: the BASEDS dataset needs to be assigned, and to exist;
|
)
|
||||||
%let syscc=4;
|
%mp_abort(iftrue=( %mf_existds(&baseds)=0 )
|
||||||
%return;
|
,mac=&sysmacroname
|
||||||
%end;
|
,msg=%str(the BASEDS dataset (&baseds) needs to be assigned, and to exist)
|
||||||
|
)
|
||||||
|
|
||||||
|
/* count rows */
|
||||||
|
%local hasheader; %let hasheader=0;
|
||||||
|
data _null_;
|
||||||
|
if _N_ > 1 then do;
|
||||||
|
call symputx('hasheader',1,'l');
|
||||||
|
stop;
|
||||||
|
end;
|
||||||
|
infile &inref;
|
||||||
|
input;
|
||||||
|
run;
|
||||||
|
%mp_abort(iftrue=( &hasheader=0 )
|
||||||
|
,mac=&sysmacroname
|
||||||
|
,msg=%str(No header row in &inref)
|
||||||
|
)
|
||||||
|
|
||||||
/* get the variables in the CSV */
|
/* get the variables in the CSV */
|
||||||
data _data_;
|
data _data_;
|
||||||
@@ -115,7 +136,9 @@ data &outds
|
|||||||
;
|
;
|
||||||
infile &inref dsd firstobs=2;
|
infile &inref dsd firstobs=2;
|
||||||
input &instat;
|
input &instat;
|
||||||
drop &dropvars;
|
%if %length(&dropvars)>0 %then %do;
|
||||||
|
drop &dropvars;
|
||||||
|
%end;
|
||||||
run;
|
run;
|
||||||
|
|
||||||
%mend;
|
%mend;
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
@file mp_streamfile.sas
|
@file
|
||||||
@brief Streams a file to _webout according to content type
|
@brief Streams a file to _webout according to content type
|
||||||
@details Will set headers using appropriate functions (SAS 9 vs Viya) and send
|
@details Will set headers using appropriate functions (SAS 9 vs Viya) and send
|
||||||
content as a binary stream.
|
content as a binary stream.
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
@param contenttype= Either TEXT, ZIP, CSV, EXCEL (default TEXT)
|
@param contenttype= Either TEXT, ZIP, CSV, EXCEL (default TEXT)
|
||||||
@param inloc= /path/to/file.ext to be sent
|
@param inloc= /path/to/file.ext to be sent
|
||||||
|
@param inref= fileref of file to be sent (if provided, overrides `inloc`)
|
||||||
@param outname= the name of the file, as downloaded by the browser
|
@param outname= the name of the file, as downloaded by the browser
|
||||||
|
|
||||||
@author Allan Bowe
|
@author Allan Bowe
|
||||||
@@ -27,6 +28,7 @@
|
|||||||
%macro mp_streamfile(
|
%macro mp_streamfile(
|
||||||
contenttype=TEXT
|
contenttype=TEXT
|
||||||
,inloc=
|
,inloc=
|
||||||
|
,inref=0
|
||||||
,outname=
|
,outname=
|
||||||
)/*/STORE SOURCE*/;
|
)/*/STORE SOURCE*/;
|
||||||
|
|
||||||
@@ -42,7 +44,7 @@
|
|||||||
%end;
|
%end;
|
||||||
%else %if &platform=SASVIYA %then %do;
|
%else %if &platform=SASVIYA %then %do;
|
||||||
filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name='_webout.zip'
|
filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name='_webout.zip'
|
||||||
contenttype='application/zip'
|
contenttype='application/zip'
|
||||||
contentdisp="attachment; filename=&outname";
|
contentdisp="attachment; filename=&outname";
|
||||||
%end;
|
%end;
|
||||||
%end;
|
%end;
|
||||||
@@ -56,7 +58,7 @@
|
|||||||
%end;
|
%end;
|
||||||
%else %if &platform=SASVIYA %then %do;
|
%else %if &platform=SASVIYA %then %do;
|
||||||
filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name='_webout.xls'
|
filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name='_webout.xls'
|
||||||
contenttype='application/vnd.ms-excel'
|
contenttype='application/vnd.ms-excel'
|
||||||
contentdisp="attachment; filename=&outname";
|
contentdisp="attachment; filename=&outname";
|
||||||
%end;
|
%end;
|
||||||
%end;
|
%end;
|
||||||
@@ -69,7 +71,7 @@
|
|||||||
%end;
|
%end;
|
||||||
%else %if &platform=SASVIYA %then %do;
|
%else %if &platform=SASVIYA %then %do;
|
||||||
filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name='_webout.xls'
|
filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name='_webout.xls'
|
||||||
contenttype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
contenttype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
||||||
contentdisp="attachment; filename=&outname";
|
contentdisp="attachment; filename=&outname";
|
||||||
%end;
|
%end;
|
||||||
%end;
|
%end;
|
||||||
@@ -102,7 +104,7 @@
|
|||||||
%else %if &contentype=HTML %then %do;
|
%else %if &contentype=HTML %then %do;
|
||||||
%if &platform=SASVIYA %then %do;
|
%if &platform=SASVIYA %then %do;
|
||||||
filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name="_webout.json"
|
filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name="_webout.json"
|
||||||
contenttype="text/html";
|
contenttype="text/html";
|
||||||
%end;
|
%end;
|
||||||
%end;
|
%end;
|
||||||
%else %do;
|
%else %do;
|
||||||
@@ -110,6 +112,11 @@
|
|||||||
%return;
|
%return;
|
||||||
%end;
|
%end;
|
||||||
|
|
||||||
%mp_binarycopy(inloc="&inloc",outref=_webout)
|
%if &inref ne 0 %then %do;
|
||||||
|
%mp_binarycopy(inref=&inref,outref=_webout)
|
||||||
|
%end;
|
||||||
|
%else %do;
|
||||||
|
%mp_binarycopy(inloc="&inloc",outref=_webout)
|
||||||
|
%end;
|
||||||
|
|
||||||
%mend;
|
%mend;
|
||||||
Reference in New Issue
Block a user