1
0
mirror of https://github.com/sasjs/core.git synced 2025-12-12 23:14:35 +00:00

Compare commits

...

8 Commits

Author SHA1 Message Date
vrh
33189743cd fix: accidental end comment 2020-09-03 18:07:18 +02:00
vrh
459beff4fa feat: mf_trimstr macro 2020-09-03 17:49:44 +02:00
vrh
1c873afe57 fix: base_uri for mv_deletejes 2020-09-03 16:29:21 +02:00
Allan Bowe
2b683509ac Merge pull request #4 from sasjs/change
fix: base_uri
2020-09-03 16:26:48 +02:00
vrh
dcccd1491d fix: base_uri 2020-09-03 16:24:32 +02:00
vrh
8d9b84037c fix: base_uri missing 2020-09-03 16:06:47 +02:00
vrh
029c1a29ed feat: xlsx support in mp_streamfile 2020-08-18 23:09:13 +02:00
vrh
c4dbd5971f docs: formatting 2020-08-08 15:26:02 +02:00
8 changed files with 223 additions and 44 deletions

193
all.sas
View File

@@ -510,6 +510,7 @@ options noquotelenmax;
<h4> Dependencies </h4> <h4> Dependencies </h4>
@li mf_mval.sas @li mf_mval.sas
@li mf_trimstr.sas
@version 9.4 / 3.4 @version 9.4 / 3.4
@author Allan Bowe @author Allan Bowe
@@ -555,7 +556,7 @@ options noquotelenmax;
%else 0; %else 0;
%end; %end;
%else %if &switch=VIYARESTAPI %then %do; %else %if &switch=VIYARESTAPI %then %do;
%sysfunc(getoption(servicesbaseurl)) %mf_trimstr(%sysfunc(getoption(servicesbaseurl)),/)
%end; %end;
%mend;/** %mend;/**
@file @file
@@ -1290,6 +1291,44 @@ Usage:
%macro mf_nobs(libds %macro mf_nobs(libds
)/*/STORE SOURCE*/; )/*/STORE SOURCE*/;
%mf_getattrn(&libds,NLOBS) %mf_getattrn(&libds,NLOBS)
%mend;/**
@file mf_trimstr.sas
@brief Removes character(s) from the end, if they exist
@details If the designated characters exist at the end of the string, they
are removed
%put %mf_trimstr(/blah/,/); * /blah;
%put %mf_trimstr(/blah/,h); * /blah/;
%put %mf_trimstr(/blah/,h/);* /bla;
<h4> Dependencies </h4>
@param basestr The string to be modified
@param trimstr The string to be removed from the end of `basestr`, if it exists
@return output returns result with the value of `trimstr` removed from the end
@version 9.2
@author Allan Bowe
**/
%macro mf_trimstr(basestr,trimstr);
%local trimlen trimval;
%let trimlen=%length(%superq(trimstr));
%let trimval=%qsubstr(%superq(basestr)
,%length(%superq(basestr))-&trimlen+1
,&trimlen);
%if %superq(trimval)=%superq(trimstr) %then %do;
%qsubstr(%superq(basestr),1,%length(%superq(basestr))-&trimlen)
%end;
%else %do;
&basestr
%end;
%mend;/** %mend;/**
@file @file
@brief Creates a Unique ID based on system time in a friendly format @brief Creates a Unique ID based on system time in a friendly format
@@ -2504,35 +2543,52 @@ create table _data_ as
separated by ' ' separated by ' '
from &syslast from &syslast
; ;
quit;
create table _data_ as
select * from dictionary.indexes
where upcase(libname)="%upcase(&libref)"
%if %length(&ds)>0 %then %do;
and upcase(memname)="%upcase(&ds)"
%end;
order by idxusage, indxname, indxpos
;
%local idxinfo; %let idxinfo=&syslast;
/* Extract all Primary Key and Unique data constraints */ /* Extract all Primary Key and Unique data constraints */
%mp_getconstraints(lib=%upcase(&libref),ds=%upcase(&ds),outds=_data_) %mp_getconstraints(lib=%upcase(&libref),ds=%upcase(&ds),outds=_data_)
%local colconst; %let colconst=&syslast; %local colconst; %let colconst=&syslast;
%macro addConst(); %macro addConst();
data _null_; %global constraints_used;
length ctype $11; data _null_;
set &colconst (where=(table_name="&curds" and constraint_type in ('PRIMARY','UNIQUE'))) end=last; length ctype $11 constraint_name_orig $256 constraints_used $5000;
file &fref mod; set &colconst (where=(table_name="&curds" and constraint_type in ('PRIMARY','UNIQUE'))) end=last;
by constraint_type constraint_name; file &fref mod;
if upcase(strip(constraint_type)) = 'PRIMARY' then ctype='PRIMARY KEY'; by constraint_type constraint_name;
else ctype=strip(constraint_type); retain constraints_used;
%if &flavour=TSQL %then %do; constraint_name_orig=constraint_name;
column_name=catt('[',column_name,']'); if upcase(strip(constraint_type)) = 'PRIMARY' then ctype='PRIMARY KEY';
constraint_name=catt('[',constraint_name,']'); else ctype=strip(constraint_type);
%end; %if &flavour=TSQL %then %do;
%else %if &flavour=PGSQL %then %do; column_name=catt('[',column_name,']');
column_name=catt('"',column_name,'"'); constraint_name=catt('[',constraint_name,']');
constraint_name=catt('"',constraint_name,'"'); %end;
%end; %else %if &flavour=PGSQL %then %do;
if first.constraint_name then do; column_name=catt('"',column_name,'"');
put " ,CONSTRAINT " constraint_name ctype "(" ; constraint_name=catt('"',constraint_name,'"');
put ' ' column_name; %end;
end; if first.constraint_name then do;
else put ' ,' column_name; constraints_used = catx(' ', constraints_used, constraint_name_orig);
if last.constraint_name then put " )"; put " ,CONSTRAINT " constraint_name ctype "(" ;
run; put ' ' column_name;
end;
else put ' ,' column_name;
if last.constraint_name then do;
put " )";
call symput('constraints_used',strip(constraints_used));
end;
run;
%put &=constraints_used;
%mend; %mend;
data _null_; data _null_;
@@ -2544,13 +2600,13 @@ run;
%if &flavour=SAS %then %do; %if &flavour=SAS %then %do;
data _null_; data _null_;
file &fref mod; file &fref mod;
put "/* SAS Flavour DDL for %upcase(&libref).&curds */";
put "proc sql;"; put "proc sql;";
run; run;
%do x=1 %to %sysfunc(countw(&dsnlist)); %do x=1 %to %sysfunc(countw(&dsnlist));
%let curds=%scan(&dsnlist,&x); %let curds=%scan(&dsnlist,&x);
data _null_; data _null_;
file &fref mod; file &fref mod;
if _n_ eq 1 then put "/* SAS Flavour DDL for %upcase(&libref).&curds */";
length nm lab $1024; length nm lab $1024;
set &colinfo (where=(upcase(memname)="&curds")) end=last; set &colinfo (where=(upcase(memname)="&curds")) end=last;
@@ -2578,6 +2634,25 @@ run;
file &fref mod; file &fref mod;
put ');'; put ');';
run; run;
/* Create Unique Indexes, but only if they were not already defined within the Constraints section. */
data _null_;
*length ds $128;
set &idxinfo (where=(memname="&curds" and unique='yes' and indxname not in (%sysfunc(tranwrd("&constraints_used",%str( ),%str(","))))));
file &fref mod;
by idxusage indxname;
/* ds=cats(libname,'.',memname); */
if first.indxname then do;
put 'CREATE UNIQUE INDEX ' indxname "ON &libref..&curds (" ;
put ' ' name ;
end;
else put ' ,' name ;
*else put ' ,' name ;
if last.indxname then do;
put ');';
end;
run;
/* /*
ods output IntegrityConstraints=ic; ods output IntegrityConstraints=ic;
proc contents data=testali out2=info; proc contents data=testali out2=info;
@@ -2627,6 +2702,24 @@ run;
/* Extra step for data constraints */ /* Extra step for data constraints */
%addConst() %addConst()
/* Create Unique Indexes, but only if they were not already defined within the Constraints section. */
data _null_;
*length ds $128;
set &idxinfo (where=(memname="&curds" and unique='yes' and indxname not in (%sysfunc(tranwrd("&constraints_used",%str( ),%str(","))))));
file &fref mod;
by idxusage indxname;
*ds=cats(libname,'.',memname);
if first.indxname then do;
/* add nonclustered in case of multiple unique indexes */
put ' ,index [' indxname +(-1) '] UNIQUE NONCLUSTERED (';
put ' [' name +(-1) ']';
end;
else put ' ,[' name +(-1) ']';
if last.indxname then do;
put ' )';
end;
run;
data _null_; data _null_;
file &fref mod; file &fref mod;
put ')'; put ')';
@@ -2701,6 +2794,24 @@ run;
put ');'; put ');';
run; run;
/* Create Unique Indexes, but only if they were not already defined within the Constraints section. */
data _null_;
*length ds $128;
set &idxinfo (where=(memname="&curds" and unique='yes' and indxname not in (%sysfunc(tranwrd("&constraints_used",%str( ),%str(","))))));
file &fref mod;
by idxusage indxname;
/* ds=cats(libname,'.',memname); */
if first.indxname then do;
put 'CREATE UNIQUE INDEX "' indxname +(-1) '" ' "ON &schema..&curds (" ;
put ' "' name +(-1) '"' ;
end;
else put ' ,"' name +(-1) '"';
*else put ' ,' name ;
if last.indxname then do;
put ');';
end;
run;
%end; %end;
%end; %end;
%if &showlog=YES %then %do; %if &showlog=YES %then %do;
@@ -3860,6 +3971,7 @@ proc sql
%end; %end;
%end; %end;
%else %if &contentype=EXCEL %then %do; %else %if &contentype=EXCEL %then %do;
/* suitable for XLS format */
%if &platform=SASMETA %then %do; %if &platform=SASMETA %then %do;
data _null_; data _null_;
rc=stpsrv_header('Content-type','application/vnd.ms-excel'); rc=stpsrv_header('Content-type','application/vnd.ms-excel');
@@ -3872,6 +3984,19 @@ proc sql
contentdisp="attachment; filename=&outname"; contentdisp="attachment; filename=&outname";
%end; %end;
%end; %end;
%else %if &contentype=XLSX %then %do;
%if &platform=SASMETA %then %do;
data _null_;
rc=stpsrv_header('Content-type','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
rc=stpsrv_header('Content-disposition',"attachment; filename=&outname");
run;
%end;
%else %if &platform=SASVIYA %then %do;
filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name='_webout.xls'
contenttype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
contentdisp="attachment; filename=&outname";
%end;
%end;
%else %if &contentype=TEXT %then %do; %else %if &contentype=TEXT %then %do;
%if &platform=SASMETA %then %do; %if &platform=SASMETA %then %do;
data _null_; data _null_;
@@ -8018,17 +8143,17 @@ run;
Usage: Usage:
- get a table id - get a table id
%mm_gettableid(libref=METALIB,ds=SOMETABLE,outds=iwant) %mm_gettableid(libref=METALIB,ds=SOMETABLE,outds=iwant)
@param libref= The libref to search @param libref= The libref to search
@param ds= The input dataset to check @param ds= The input dataset to check
@param outds= the dataset to create that contains the `tableuri`` @param outds= the dataset to create that contains the `tableuri`
@param mDebug= set to 1 to show debug messages in the log @param mDebug= set to 1 to show debug messages in the log
@returns outds dataset containing `tableuri` and `tablename` @returns outds dataset containing `tableuri` and `tablename`
@version 9.2 @version 9.3
@author Allan Bowe @author Allan Bowe
**/ **/
@@ -9658,7 +9783,7 @@ options noquotelenmax;
data _null_; data _null_;
set &libref1..links; set &libref1..links;
if rel='createChild' then if rel='createChild' then
call symputx('href',quote(trim(href)),'l'); call symputx('href',quote("&base_uri"!!trim(href)),'l');
run; run;
%end; %end;
%else %if &SYS_PROCHTTP_STATUS_CODE=404 %then %do; %else %if &SYS_PROCHTTP_STATUS_CODE=404 %then %do;
@@ -9857,7 +9982,7 @@ libname &libref1 JSON fileref=&fname1;
data _null_; data _null_;
set &libref1..links; set &libref1..links;
if rel='members' then call symputx('membercheck',quote(trim(href)),'l'); if rel='members' then call symputx('membercheck',quote("&base_uri"!!trim(href)),'l');
else if rel='self' then call symputx('parentFolderUri',href,'l'); else if rel='self' then call symputx('parentFolderUri',href,'l');
run; run;
data _null_; data _null_;
@@ -10323,7 +10448,7 @@ proc http method='POST'
in=&fname3 in=&fname3
out=&fname4 out=&fname4
&oauth_bearer &oauth_bearer
url="/jobDefinitions/definitions?parentFolderUri=&parentFolderUri"; url="&base_uri/jobDefinitions/definitions?parentFolderUri=&parentFolderUri";
headers 'Content-Type'='application/vnd.sas.job.definition+json' headers 'Content-Type'='application/vnd.sas.job.definition+json'
%if &grant_type=authorization_code %then %do; %if &grant_type=authorization_code %then %do;
"Authorization"="Bearer &&&access_token_var" "Authorization"="Bearer &&&access_token_var"
@@ -10617,7 +10742,7 @@ run;
libname &libref1 JSON fileref=&fname1; libname &libref1 JSON fileref=&fname1;
data _null_; data _null_;
set &libref1..links; set &libref1..links;
if rel='members' then call symputx('mref',quote(trim(href)),'l'); if rel='members' then call symputx('mref',quote("&base_uri"!!trim(href)),'l');
run; run;
/* get the children */ /* get the children */
@@ -10639,7 +10764,7 @@ libname &libref1a JSON fileref=&fname1a;
data _null_; data _null_;
set &libref1a..items; set &libref1a..items;
if contenttype='jobDefinition' and upcase(name)="%upcase(&name)" then do; if contenttype='jobDefinition' and upcase(name)="%upcase(&name)" then do;
call symputx('uri',uri,'l'); call symputx('uri',cats("&base_uri",uri),'l');
call symputx('found',1,'l'); call symputx('found',1,'l');
end; end;
run; run;

View File

@@ -12,6 +12,7 @@
<h4> Dependencies </h4> <h4> Dependencies </h4>
@li mf_mval.sas @li mf_mval.sas
@li mf_trimstr.sas
@version 9.4 / 3.4 @version 9.4 / 3.4
@author Allan Bowe @author Allan Bowe
@@ -57,6 +58,6 @@
%else 0; %else 0;
%end; %end;
%else %if &switch=VIYARESTAPI %then %do; %else %if &switch=VIYARESTAPI %then %do;
%sysfunc(getoption(servicesbaseurl)) %mf_trimstr(%sysfunc(getoption(servicesbaseurl)),/)
%end; %end;
%mend; %mend;

39
base/mf_trimstr.sas Normal file
View File

@@ -0,0 +1,39 @@
/**
@file mf_trimstr.sas
@brief Removes character(s) from the end, if they exist
@details If the designated characters exist at the end of the string, they
are removed
%put %mf_trimstr(/blah/,/); * /blah;
%put %mf_trimstr(/blah/,h); * /blah/;
%put %mf_trimstr(/blah/,h/);* /bla;
<h4> Dependencies </h4>
@param basestr The string to be modified
@param trimstr The string to be removed from the end of `basestr`, if it exists
@return output returns result with the value of `trimstr` removed from the end
@version 9.2
@author Allan Bowe
**/
%macro mf_trimstr(basestr,trimstr);
%local trimlen trimval;
%let trimlen=%length(%superq(trimstr));
%let trimval=%qsubstr(%superq(basestr)
,%length(%superq(basestr))-&trimlen+1
,&trimlen);
%if %superq(trimval)=%superq(trimstr) %then %do;
%qsubstr(%superq(basestr),1,%length(%superq(basestr))-&trimlen)
%end;
%else %do;
&basestr
%end;
%mend;

View File

@@ -47,6 +47,7 @@
%end; %end;
%end; %end;
%else %if &contentype=EXCEL %then %do; %else %if &contentype=EXCEL %then %do;
/* suitable for XLS format */
%if &platform=SASMETA %then %do; %if &platform=SASMETA %then %do;
data _null_; data _null_;
rc=stpsrv_header('Content-type','application/vnd.ms-excel'); rc=stpsrv_header('Content-type','application/vnd.ms-excel');
@@ -59,6 +60,19 @@
contentdisp="attachment; filename=&outname"; contentdisp="attachment; filename=&outname";
%end; %end;
%end; %end;
%else %if &contentype=XLSX %then %do;
%if &platform=SASMETA %then %do;
data _null_;
rc=stpsrv_header('Content-type','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
rc=stpsrv_header('Content-disposition',"attachment; filename=&outname");
run;
%end;
%else %if &platform=SASVIYA %then %do;
filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name='_webout.xls'
contenttype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
contentdisp="attachment; filename=&outname";
%end;
%end;
%else %if &contentype=TEXT %then %do; %else %if &contentype=TEXT %then %do;
%if &platform=SASMETA %then %do; %if &platform=SASMETA %then %do;
data _null_; data _null_;

View File

@@ -6,17 +6,17 @@
Usage: Usage:
- get a table id - get a table id
%mm_gettableid(libref=METALIB,ds=SOMETABLE,outds=iwant) %mm_gettableid(libref=METALIB,ds=SOMETABLE,outds=iwant)
@param libref= The libref to search @param libref= The libref to search
@param ds= The input dataset to check @param ds= The input dataset to check
@param outds= the dataset to create that contains the `tableuri`` @param outds= the dataset to create that contains the `tableuri`
@param mDebug= set to 1 to show debug messages in the log @param mDebug= set to 1 to show debug messages in the log
@returns outds dataset containing `tableuri` and `tablename` @returns outds dataset containing `tableuri` and `tablename`
@version 9.2 @version 9.3
@author Allan Bowe @author Allan Bowe
**/ **/

View File

@@ -96,7 +96,7 @@ options noquotelenmax;
data _null_; data _null_;
set &libref1..links; set &libref1..links;
if rel='createChild' then if rel='createChild' then
call symputx('href',quote(trim(href)),'l'); call symputx('href',quote("&base_uri"!!trim(href)),'l');
run; run;
%end; %end;
%else %if &SYS_PROCHTTP_STATUS_CODE=404 %then %do; %else %if &SYS_PROCHTTP_STATUS_CODE=404 %then %do;

View File

@@ -143,7 +143,7 @@ libname &libref1 JSON fileref=&fname1;
data _null_; data _null_;
set &libref1..links; set &libref1..links;
if rel='members' then call symputx('membercheck',quote(trim(href)),'l'); if rel='members' then call symputx('membercheck',quote("&base_uri"!!trim(href)),'l');
else if rel='self' then call symputx('parentFolderUri',href,'l'); else if rel='self' then call symputx('parentFolderUri',href,'l');
run; run;
data _null_; data _null_;
@@ -609,7 +609,7 @@ proc http method='POST'
in=&fname3 in=&fname3
out=&fname4 out=&fname4
&oauth_bearer &oauth_bearer
url="/jobDefinitions/definitions?parentFolderUri=&parentFolderUri"; url="&base_uri/jobDefinitions/definitions?parentFolderUri=&parentFolderUri";
headers 'Content-Type'='application/vnd.sas.job.definition+json' headers 'Content-Type'='application/vnd.sas.job.definition+json'
%if &grant_type=authorization_code %then %do; %if &grant_type=authorization_code %then %do;
"Authorization"="Bearer &&&access_token_var" "Authorization"="Bearer &&&access_token_var"

View File

@@ -95,7 +95,7 @@ run;
libname &libref1 JSON fileref=&fname1; libname &libref1 JSON fileref=&fname1;
data _null_; data _null_;
set &libref1..links; set &libref1..links;
if rel='members' then call symputx('mref',quote(trim(href)),'l'); if rel='members' then call symputx('mref',quote("&base_uri"!!trim(href)),'l');
run; run;
/* get the children */ /* get the children */
@@ -117,7 +117,7 @@ libname &libref1a JSON fileref=&fname1a;
data _null_; data _null_;
set &libref1a..items; set &libref1a..items;
if contenttype='jobDefinition' and upcase(name)="%upcase(&name)" then do; if contenttype='jobDefinition' and upcase(name)="%upcase(&name)" then do;
call symputx('uri',uri,'l'); call symputx('uri',cats("&base_uri",uri),'l');
call symputx('found',1,'l'); call symputx('found',1,'l');
end; end;
run; run;