mirror of
https://github.com/sasjs/core.git
synced 2026-01-09 18:30:06 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f50cb03fd3 | |||
| ac46489f11 | |||
|
|
5e45701e74 | ||
|
|
8caaacd9f0 | ||
|
|
91983e0a91 |
65
all.sas
65
all.sas
@@ -1316,13 +1316,23 @@ Usage:
|
|||||||
**/
|
**/
|
||||||
|
|
||||||
%macro mf_trimstr(basestr,trimstr);
|
%macro mf_trimstr(basestr,trimstr);
|
||||||
%local trimlen trimval;
|
%local baselen trimlen trimval;
|
||||||
|
|
||||||
|
/* return if basestr is shorter than trimstr (or 0) */
|
||||||
|
%let baselen=%length(%superq(basestr));
|
||||||
%let trimlen=%length(%superq(trimstr));
|
%let trimlen=%length(%superq(trimstr));
|
||||||
|
%if &baselen < &trimlen or &baselen=0 %then %return;
|
||||||
|
|
||||||
|
/* obtain the characters from the end of basestr */
|
||||||
%let trimval=%qsubstr(%superq(basestr)
|
%let trimval=%qsubstr(%superq(basestr)
|
||||||
,%length(%superq(basestr))-&trimlen+1
|
,%length(%superq(basestr))-&trimlen+1
|
||||||
,&trimlen);
|
,&trimlen);
|
||||||
|
|
||||||
%if %superq(trimval)=%superq(trimstr) %then %do;
|
/* compare and if matching, chop it off! */
|
||||||
|
%if %superq(basestr)=%superq(trimstr) %then %do;
|
||||||
|
%return;
|
||||||
|
%end;
|
||||||
|
%else %if %superq(trimval)=%superq(trimstr) %then %do;
|
||||||
%qsubstr(%superq(basestr),1,%length(%superq(basestr))-&trimlen)
|
%qsubstr(%superq(basestr),1,%length(%superq(basestr))-&trimlen)
|
||||||
%end;
|
%end;
|
||||||
%else %do;
|
%else %do;
|
||||||
@@ -1541,8 +1551,15 @@ Usage:
|
|||||||
%end;
|
%end;
|
||||||
|
|
||||||
%if %symexist(SYS_JES_JOB_URI) %then %do;
|
%if %symexist(SYS_JES_JOB_URI) %then %do;
|
||||||
/* refer web service output to file service in one hit */
|
/* setup webout */
|
||||||
filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name="_webout.json";
|
OPTIONS NOBOMFILE;
|
||||||
|
%if "X&SYS_JES_JOB_URI.X"="XX" %then %do;
|
||||||
|
filename _webout temp lrecl=999999 mod;
|
||||||
|
%end;
|
||||||
|
%else %do;
|
||||||
|
filename _webout filesrvc parenturi="&SYS_JES_JOB_URI"
|
||||||
|
name="_webout.json" lrecl=999999 mod;
|
||||||
|
%end;
|
||||||
%end;
|
%end;
|
||||||
|
|
||||||
/* send response in SASjs JSON format */
|
/* send response in SASjs JSON format */
|
||||||
@@ -2280,8 +2297,7 @@ proc sql
|
|||||||
order by ranuni(42)
|
order by ranuni(42)
|
||||||
%end;
|
%end;
|
||||||
;
|
;
|
||||||
|
reset outobs=max;
|
||||||
|
|
||||||
create table datalines1 as
|
create table datalines1 as
|
||||||
select name,type,length,varnum,format,label from dictionary.columns
|
select name,type,length,varnum,format,label from dictionary.columns
|
||||||
where libname="%upcase(%scan(&base_ds,1))"
|
where libname="%upcase(%scan(&base_ds,1))"
|
||||||
@@ -3703,7 +3719,7 @@ proc sort; by descending sumcols memname libname; run;
|
|||||||
@brief Searches all data in a library
|
@brief Searches all data in a library
|
||||||
@details
|
@details
|
||||||
Scans an entire library and creates a copy of any table
|
Scans an entire library and creates a copy of any table
|
||||||
containing a specific string or numeric value. Only
|
containing a specific string OR numeric value. Only
|
||||||
matching records are written out.
|
matching records are written out.
|
||||||
If both a string and numval are provided, the string
|
If both a string and numval are provided, the string
|
||||||
will take precedence.
|
will take precedence.
|
||||||
@@ -3744,9 +3760,13 @@ proc sort; by descending sumcols memname libname; run;
|
|||||||
,filter_text=%str(1=1)
|
,filter_text=%str(1=1)
|
||||||
)/*/STORE SOURCE*/;
|
)/*/STORE SOURCE*/;
|
||||||
|
|
||||||
%local table_list table table_num table colnum col start_tm vars type coltype;
|
%local table_list table table_num table colnum col start_tm check_tm vars type coltype;
|
||||||
%put process began at %sysfunc(datetime(),datetime19.);
|
%put process began at %sysfunc(datetime(),datetime19.);
|
||||||
|
|
||||||
|
%if &syscc ge 4 %then %do;
|
||||||
|
%put %str(WAR)NING: SYSCC=&syscc on macro entry;
|
||||||
|
%return;
|
||||||
|
%end;
|
||||||
|
|
||||||
%if &string = %then %let type=N;
|
%if &string = %then %let type=N;
|
||||||
%else %let type=C;
|
%else %let type=C;
|
||||||
@@ -3778,6 +3798,7 @@ proc sql
|
|||||||
%put NO COLUMNS IN &lib..&table! This will be skipped.;
|
%put NO COLUMNS IN &lib..&table! This will be skipped.;
|
||||||
%end;
|
%end;
|
||||||
%else %do;
|
%else %do;
|
||||||
|
%let check_tm=%sysfunc(datetime());
|
||||||
/* build sql statement */
|
/* build sql statement */
|
||||||
create table mpsearch.&table as select * from &lib..&table
|
create table mpsearch.&table as select * from &lib..&table
|
||||||
where %unquote(&filter_text) and
|
where %unquote(&filter_text) and
|
||||||
@@ -3788,14 +3809,19 @@ proc sql
|
|||||||
%let coltype=%mf_getvartype(&lib..&table,&col);
|
%let coltype=%mf_getvartype(&lib..&table,&col);
|
||||||
%if &type=C and &coltype=C %then %do;
|
%if &type=C and &coltype=C %then %do;
|
||||||
/* if a char column, see if it contains the string */
|
/* if a char column, see if it contains the string */
|
||||||
or (&col ? "&string")
|
or ("&col"n ? "&string")
|
||||||
%end;
|
%end;
|
||||||
%else %if &type=N and &coltype=N %then %do;
|
%else %if &type=N and &coltype=N %then %do;
|
||||||
/* if numeric match exactly */
|
/* if numeric match exactly */
|
||||||
or (&col = &numval)
|
or ("&col"n = &numval)
|
||||||
%end;
|
%end;
|
||||||
%end;
|
%end;
|
||||||
);
|
);
|
||||||
|
%put Search query for &table took %sysevalf(%sysfunc(datetime())-&check_tm) seconds;
|
||||||
|
%if &sqlrc ne 0 %then %do;
|
||||||
|
%put %str(WAR)NING: SQLRC=&sqlrc when processing &table;
|
||||||
|
%return;
|
||||||
|
%end;
|
||||||
%if %mf_nobs(mpsearch.&table)=0 %then %do;
|
%if %mf_nobs(mpsearch.&table)=0 %then %do;
|
||||||
drop table mpsearch.&table;
|
drop table mpsearch.&table;
|
||||||
%end;
|
%end;
|
||||||
@@ -11452,24 +11478,15 @@ libname &libref1 clear;
|
|||||||
%mend;/**
|
%mend;/**
|
||||||
@file mv_getusergroups.sas
|
@file mv_getusergroups.sas
|
||||||
@brief Creates a dataset with a list of groups for a particular user
|
@brief Creates a dataset with a list of groups for a particular user
|
||||||
@details First, be sure you have an access token (which requires an app token).
|
@details If using outside of Viya SPRE, then an access token is needed.
|
||||||
|
|
||||||
Using the macros here:
|
Compile the macros here:
|
||||||
|
|
||||||
filename mc url
|
filename mc url
|
||||||
"https://raw.githubusercontent.com/sasjs/core/main/all.sas";
|
"https://raw.githubusercontent.com/sasjs/core/main/all.sas";
|
||||||
%inc mc;
|
%inc mc;
|
||||||
|
|
||||||
An administrator needs to set you up with an access code:
|
Then run the macro!
|
||||||
|
|
||||||
%mv_registerclient(outds=client)
|
|
||||||
|
|
||||||
Navigate to the url from the log (opting in to the groups) and paste the
|
|
||||||
access code below:
|
|
||||||
|
|
||||||
%mv_tokenauth(inds=client,code=wKDZYTEPK6)
|
|
||||||
|
|
||||||
Now we can run the macro!
|
|
||||||
|
|
||||||
%mv_getusergroups(&sysuserid,outds=users)
|
%mv_getusergroups(&sysuserid,outds=users)
|
||||||
|
|
||||||
@@ -11855,7 +11872,7 @@ run;
|
|||||||
%end;
|
%end;
|
||||||
|
|
||||||
/* prepare url */
|
/* prepare url */
|
||||||
%if &grant_type=authorization_code %then %do;
|
%if %index(%superq(grant_type),authorization_code) %then %do;
|
||||||
data _null_;
|
data _null_;
|
||||||
if symexist('_baseurl') then do;
|
if symexist('_baseurl') then do;
|
||||||
url=symget('_baseurl');
|
url=symget('_baseurl');
|
||||||
@@ -11874,7 +11891,7 @@ run;
|
|||||||
%put CLIENT_SECRET=&client_secret;
|
%put CLIENT_SECRET=&client_secret;
|
||||||
%put GRANT_TYPE=&grant_type;
|
%put GRANT_TYPE=&grant_type;
|
||||||
%put;
|
%put;
|
||||||
%if &grant_type=authorization_code %then %do;
|
%if %index(%superq(grant_type),authorization_code) %then %do;
|
||||||
/* cannot use base_uri here as it includes the protocol which may be incorrect externally */
|
/* cannot use base_uri here as it includes the protocol which may be incorrect externally */
|
||||||
%put NOTE: The developer must also register below and select 'openid' to get the grant code:;
|
%put NOTE: The developer must also register below and select 'openid' to get the grant code:;
|
||||||
%put NOTE- ;
|
%put NOTE- ;
|
||||||
|
|||||||
@@ -23,13 +23,23 @@
|
|||||||
**/
|
**/
|
||||||
|
|
||||||
%macro mf_trimstr(basestr,trimstr);
|
%macro mf_trimstr(basestr,trimstr);
|
||||||
%local trimlen trimval;
|
%local baselen trimlen trimval;
|
||||||
|
|
||||||
|
/* return if basestr is shorter than trimstr (or 0) */
|
||||||
|
%let baselen=%length(%superq(basestr));
|
||||||
%let trimlen=%length(%superq(trimstr));
|
%let trimlen=%length(%superq(trimstr));
|
||||||
|
%if &baselen < &trimlen or &baselen=0 %then %return;
|
||||||
|
|
||||||
|
/* obtain the characters from the end of basestr */
|
||||||
%let trimval=%qsubstr(%superq(basestr)
|
%let trimval=%qsubstr(%superq(basestr)
|
||||||
,%length(%superq(basestr))-&trimlen+1
|
,%length(%superq(basestr))-&trimlen+1
|
||||||
,&trimlen);
|
,&trimlen);
|
||||||
|
|
||||||
%if %superq(trimval)=%superq(trimstr) %then %do;
|
/* compare and if matching, chop it off! */
|
||||||
|
%if %superq(basestr)=%superq(trimstr) %then %do;
|
||||||
|
%return;
|
||||||
|
%end;
|
||||||
|
%else %if %superq(trimval)=%superq(trimstr) %then %do;
|
||||||
%qsubstr(%superq(basestr),1,%length(%superq(basestr))-&trimlen)
|
%qsubstr(%superq(basestr),1,%length(%superq(basestr))-&trimlen)
|
||||||
%end;
|
%end;
|
||||||
%else %do;
|
%else %do;
|
||||||
|
|||||||
@@ -71,8 +71,15 @@
|
|||||||
%end;
|
%end;
|
||||||
|
|
||||||
%if %symexist(SYS_JES_JOB_URI) %then %do;
|
%if %symexist(SYS_JES_JOB_URI) %then %do;
|
||||||
/* refer web service output to file service in one hit */
|
/* setup webout */
|
||||||
filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name="_webout.json";
|
OPTIONS NOBOMFILE;
|
||||||
|
%if "X&SYS_JES_JOB_URI.X"="XX" %then %do;
|
||||||
|
filename _webout temp lrecl=999999 mod;
|
||||||
|
%end;
|
||||||
|
%else %do;
|
||||||
|
filename _webout filesrvc parenturi="&SYS_JES_JOB_URI"
|
||||||
|
name="_webout.json" lrecl=999999 mod;
|
||||||
|
%end;
|
||||||
%end;
|
%end;
|
||||||
|
|
||||||
/* send response in SASjs JSON format */
|
/* send response in SASjs JSON format */
|
||||||
|
|||||||
@@ -103,8 +103,7 @@ proc sql
|
|||||||
order by ranuni(42)
|
order by ranuni(42)
|
||||||
%end;
|
%end;
|
||||||
;
|
;
|
||||||
|
reset outobs=max;
|
||||||
|
|
||||||
create table datalines1 as
|
create table datalines1 as
|
||||||
select name,type,length,varnum,format,label from dictionary.columns
|
select name,type,length,varnum,format,label from dictionary.columns
|
||||||
where libname="%upcase(%scan(&base_ds,1))"
|
where libname="%upcase(%scan(&base_ds,1))"
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
@brief Searches all data in a library
|
@brief Searches all data in a library
|
||||||
@details
|
@details
|
||||||
Scans an entire library and creates a copy of any table
|
Scans an entire library and creates a copy of any table
|
||||||
containing a specific string or numeric value. Only
|
containing a specific string OR numeric value. Only
|
||||||
matching records are written out.
|
matching records are written out.
|
||||||
If both a string and numval are provided, the string
|
If both a string and numval are provided, the string
|
||||||
will take precedence.
|
will take precedence.
|
||||||
@@ -44,9 +44,13 @@
|
|||||||
,filter_text=%str(1=1)
|
,filter_text=%str(1=1)
|
||||||
)/*/STORE SOURCE*/;
|
)/*/STORE SOURCE*/;
|
||||||
|
|
||||||
%local table_list table table_num table colnum col start_tm vars type coltype;
|
%local table_list table table_num table colnum col start_tm check_tm vars type coltype;
|
||||||
%put process began at %sysfunc(datetime(),datetime19.);
|
%put process began at %sysfunc(datetime(),datetime19.);
|
||||||
|
|
||||||
|
%if &syscc ge 4 %then %do;
|
||||||
|
%put %str(WAR)NING: SYSCC=&syscc on macro entry;
|
||||||
|
%return;
|
||||||
|
%end;
|
||||||
|
|
||||||
%if &string = %then %let type=N;
|
%if &string = %then %let type=N;
|
||||||
%else %let type=C;
|
%else %let type=C;
|
||||||
@@ -78,6 +82,7 @@ proc sql
|
|||||||
%put NO COLUMNS IN &lib..&table! This will be skipped.;
|
%put NO COLUMNS IN &lib..&table! This will be skipped.;
|
||||||
%end;
|
%end;
|
||||||
%else %do;
|
%else %do;
|
||||||
|
%let check_tm=%sysfunc(datetime());
|
||||||
/* build sql statement */
|
/* build sql statement */
|
||||||
create table mpsearch.&table as select * from &lib..&table
|
create table mpsearch.&table as select * from &lib..&table
|
||||||
where %unquote(&filter_text) and
|
where %unquote(&filter_text) and
|
||||||
@@ -88,14 +93,19 @@ proc sql
|
|||||||
%let coltype=%mf_getvartype(&lib..&table,&col);
|
%let coltype=%mf_getvartype(&lib..&table,&col);
|
||||||
%if &type=C and &coltype=C %then %do;
|
%if &type=C and &coltype=C %then %do;
|
||||||
/* if a char column, see if it contains the string */
|
/* if a char column, see if it contains the string */
|
||||||
or (&col ? "&string")
|
or ("&col"n ? "&string")
|
||||||
%end;
|
%end;
|
||||||
%else %if &type=N and &coltype=N %then %do;
|
%else %if &type=N and &coltype=N %then %do;
|
||||||
/* if numeric match exactly */
|
/* if numeric match exactly */
|
||||||
or (&col = &numval)
|
or ("&col"n = &numval)
|
||||||
%end;
|
%end;
|
||||||
%end;
|
%end;
|
||||||
);
|
);
|
||||||
|
%put Search query for &table took %sysevalf(%sysfunc(datetime())-&check_tm) seconds;
|
||||||
|
%if &sqlrc ne 0 %then %do;
|
||||||
|
%put %str(WAR)NING: SQLRC=&sqlrc when processing &table;
|
||||||
|
%return;
|
||||||
|
%end;
|
||||||
%if %mf_nobs(mpsearch.&table)=0 %then %do;
|
%if %mf_nobs(mpsearch.&table)=0 %then %do;
|
||||||
drop table mpsearch.&table;
|
drop table mpsearch.&table;
|
||||||
%end;
|
%end;
|
||||||
|
|||||||
@@ -1,24 +1,15 @@
|
|||||||
/**
|
/**
|
||||||
@file mv_getusergroups.sas
|
@file mv_getusergroups.sas
|
||||||
@brief Creates a dataset with a list of groups for a particular user
|
@brief Creates a dataset with a list of groups for a particular user
|
||||||
@details First, be sure you have an access token (which requires an app token).
|
@details If using outside of Viya SPRE, then an access token is needed.
|
||||||
|
|
||||||
Using the macros here:
|
Compile the macros here:
|
||||||
|
|
||||||
filename mc url
|
filename mc url
|
||||||
"https://raw.githubusercontent.com/sasjs/core/main/all.sas";
|
"https://raw.githubusercontent.com/sasjs/core/main/all.sas";
|
||||||
%inc mc;
|
%inc mc;
|
||||||
|
|
||||||
An administrator needs to set you up with an access code:
|
Then run the macro!
|
||||||
|
|
||||||
%mv_registerclient(outds=client)
|
|
||||||
|
|
||||||
Navigate to the url from the log (opting in to the groups) and paste the
|
|
||||||
access code below:
|
|
||||||
|
|
||||||
%mv_tokenauth(inds=client,code=wKDZYTEPK6)
|
|
||||||
|
|
||||||
Now we can run the macro!
|
|
||||||
|
|
||||||
%mv_getusergroups(&sysuserid,outds=users)
|
%mv_getusergroups(&sysuserid,outds=users)
|
||||||
|
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ run;
|
|||||||
%end;
|
%end;
|
||||||
|
|
||||||
/* prepare url */
|
/* prepare url */
|
||||||
%if &grant_type=authorization_code %then %do;
|
%if %index(%superq(grant_type),authorization_code) %then %do;
|
||||||
data _null_;
|
data _null_;
|
||||||
if symexist('_baseurl') then do;
|
if symexist('_baseurl') then do;
|
||||||
url=symget('_baseurl');
|
url=symget('_baseurl');
|
||||||
@@ -206,7 +206,7 @@ run;
|
|||||||
%put CLIENT_SECRET=&client_secret;
|
%put CLIENT_SECRET=&client_secret;
|
||||||
%put GRANT_TYPE=&grant_type;
|
%put GRANT_TYPE=&grant_type;
|
||||||
%put;
|
%put;
|
||||||
%if &grant_type=authorization_code %then %do;
|
%if %index(%superq(grant_type),authorization_code) %then %do;
|
||||||
/* cannot use base_uri here as it includes the protocol which may be incorrect externally */
|
/* cannot use base_uri here as it includes the protocol which may be incorrect externally */
|
||||||
%put NOTE: The developer must also register below and select 'openid' to get the grant code:;
|
%put NOTE: The developer must also register below and select 'openid' to get the grant code:;
|
||||||
%put NOTE- ;
|
%put NOTE- ;
|
||||||
|
|||||||
Reference in New Issue
Block a user