1
0
mirror of https://github.com/sasjs/core.git synced 2026-01-07 01:20:05 +00:00

Compare commits

..

8 Commits

8 changed files with 144 additions and 97 deletions

119
all.sas
View File

@@ -380,7 +380,7 @@ options noquotelenmax;
@brief Returns the engine type of a SAS library @brief Returns the engine type of a SAS library
@details Usage: @details Usage:
%put %mf_getEngine(SASHELP); %put %mf_getengine(SASHELP);
returns: returns:
> V9 > V9
@@ -398,9 +398,10 @@ options noquotelenmax;
@version 9.2 @version 9.2
@author Allan Bowe @author Allan Bowe
**/
%macro mf_getEngine(libref **/ /** \cond */
%macro mf_getengine(libref
)/*/STORE SOURCE*/; )/*/STORE SOURCE*/;
%local dsid engnum rc engine; %local dsid engnum rc engine;
@@ -419,7 +420,8 @@ 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:
@@ -1551,8 +1553,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 */
@@ -1948,17 +1957,17 @@ run;
%mend;/** %mend;/**
@file @file
@brief Returns all files and subdirectories within a specified parent @brief Returns all files and subdirectories within a specified parent
@details When used with getattrs=NO, is not OS specific (uses dopen / dread). @details When used with getattrs=NO, is not OS specific (uses dopen / dread).
If getattrs=YES then the doptname / foptname functions are used to scan all If getattrs=YES then the doptname / foptname functions are used to scan all
properties - any characters that are not valid in a SAS name (v7) are simply properties - any characters that are not valid in a SAS name (v7) are simply
stripped, and the table is transposed so theat each property is a column stripped, and the table is transposed so theat each property is a column
and there is one file per row. An attempt is made to get all properties and there is one file per row. An attempt is made to get all properties
whether a file or folder, but some files/folders cannot be accessed, and so whether a file or folder, but some files/folders cannot be accessed, and so
not all properties can / will be populated. not all properties can / will be populated.
Credit for the rename approach: Credit for the rename approach:
https://communities.sas.com/t5/SAS-Programming/SAS-Function-to-convert-string-to-Legal-SAS-Name/m-p/27375/highlight/true#M5003 https://communities.sas.com/t5/SAS-Programming/SAS-Function-to-convert-string-to-Legal-SAS-Name/m-p/27375/highlight/true#M5003
usage: usage:
@@ -1967,21 +1976,25 @@ run;
%mp_dirlist(outds=cwdfileprops, getattrs=YES) %mp_dirlist(outds=cwdfileprops, getattrs=YES)
@warning In a Unix environment, the existence of a named pipe will cause this %mp_dirlist(fref=MYFREF)
@warning In a Unix environment, the existence of a named pipe will cause this
macro to hang. Therefore this tool should be used with caution in a SAS 9 web macro to hang. Therefore this tool should be used with caution in a SAS 9 web
application, as it can use up all available multibridge sessions if requests application, as it can use up all available multibridge sessions if requests
are resubmitted. are resubmitted.
If anyone finds a way to positively identify a named pipe using SAS (without If anyone finds a way to positively identify a named pipe using SAS (without
X CMD) do please raise an issue! X CMD) do please raise an issue!
@param path= for which to return contents @param path= for which to return contents
@param fref= Provide a DISK engine fileref as an alternative to PATH
@param outds= the output dataset to create @param outds= the output dataset to create
@param getattrs= YES/NO (default=NO). Uses doptname and foptname to return @param getattrs= YES/NO (default=NO). Uses doptname and foptname to return
all attributes for each file / folder. all attributes for each file / folder.
@returns outds contains the following variables: @returns outds contains the following variables:
- directory (containing folder)
- file_or_folder (file / folder) - file_or_folder (file / folder)
- filepath (path/to/file.name) - filepath (path/to/file.name)
- filename (just the file name) - filename (just the file name)
@@ -1994,18 +2007,26 @@ run;
**/ **/
%macro mp_dirlist(path=%sysfunc(pathname(work)) %macro mp_dirlist(path=%sysfunc(pathname(work))
, fref=0
, outds=work.mp_dirlist , outds=work.mp_dirlist
, getattrs=NO , getattrs=NO
)/*/STORE SOURCE*/; )/*/STORE SOURCE*/;
%let getattrs=%upcase(&getattrs)XX; %let getattrs=%upcase(&getattrs)XX;
data &outds (compress=no keep=file_or_folder filepath filename ext msg); data &outds (compress=no keep=file_or_folder filepath filename ext msg directory);
length filepath $500 fref fref2 $8 file_or_folder $6 filename $80 ext $20 msg $200; length directory filepath $500 fref fref2 $8 file_or_folder $6 filename $80 ext $20 msg $200;
rc = filename(fref, "&path"); %if &fref=0 %then %do;
rc = filename(fref, "&path");
%end;
%else %do;
fref="&fref";
rc=0;
%end;
if rc = 0 then do; if rc = 0 then do;
did = dopen(fref); did = dopen(fref);
directory=dinfo(did,'Directory');
if did=0 then do; if did=0 then do;
putlog "NOTE: This directory is empty - &path"; putlog "NOTE: This directory is empty - " directory;
msg=sysmsg(); msg=sysmsg();
put _all_; put _all_;
stop; stop;
@@ -2020,7 +2041,8 @@ data &outds (compress=no keep=file_or_folder filepath filename ext msg);
dnum = dnum(did); dnum = dnum(did);
do i = 1 to dnum; do i = 1 to dnum;
filename = dread(did, i); filename = dread(did, i);
rc = filename(fref2, "&path/"!!filename); filepath=cats(directory,'/',filename);
rc = filename(fref2,filepath);
midd=dopen(fref2); midd=dopen(fref2);
dmsg=sysmsg(); dmsg=sysmsg();
if did > 0 then file_or_folder='folder'; if did > 0 then file_or_folder='folder';
@@ -2029,12 +2051,12 @@ data &outds (compress=no keep=file_or_folder filepath filename ext msg);
fmsg=sysmsg(); fmsg=sysmsg();
if midf > 0 then file_or_folder='file'; if midf > 0 then file_or_folder='file';
rc=fclose(midf); rc=fclose(midf);
if index(fmsg,'File is in use') or index(dmsg,'is not a directory') if index(fmsg,'File is in use') or index(dmsg,'is not a directory')
then file_or_folder='file'; then file_or_folder='file';
else if index(fmsg, 'Insufficient authorization') then file_or_folder='file'; else if index(fmsg, 'Insufficient authorization') then file_or_folder='file';
else if file_or_folder='' then file_or_folder='locked'; else if file_or_folder='' then file_or_folder='locked';
if file_or_folder='file' then do; if file_or_folder='file' then do;
ext = prxchange('s/.*\.{1,1}(.*)/$1/', 1, filename); ext = prxchange('s/.*\.{1,1}(.*)/$1/', 1, filename);
if filename = ext then ext = ' '; if filename = ext then ext = ' ';
@@ -2043,7 +2065,6 @@ data &outds (compress=no keep=file_or_folder filepath filename ext msg);
ext=''; ext='';
file_or_folder='folder'; file_or_folder='folder';
end; end;
filepath="&path/"!!filename;
output; output;
end; end;
rc = dclose(did); rc = dclose(did);
@@ -2067,7 +2088,7 @@ run;
else do i=1 to foptnum(fid); else do i=1 to foptnum(fid);
infoname=foptname(fid,i); infoname=foptname(fid,i);
infoval=finfo(fid,infoname); infoval=finfo(fid,infoname);
sasname=compress(infoname, '_', 'adik'); sasname=compress(infoname, '_', 'adik');
if anydigit(sasname)=1 then sasname=substr(sasname,anyalpha(sasname)); if anydigit(sasname)=1 then sasname=substr(sasname,anyalpha(sasname));
if upcase(sasname) ne 'FILENAME' then output; if upcase(sasname) ne 'FILENAME' then output;
end; end;
@@ -2084,7 +2105,7 @@ run;
else do i=1 to doptnum(fid); else do i=1 to doptnum(fid);
infoname=doptname(fid,i); infoname=doptname(fid,i);
infoval=dinfo(fid,infoname); infoval=dinfo(fid,infoname);
sasname=compress(infoname, '_', 'adik'); sasname=compress(infoname, '_', 'adik');
if anydigit(sasname)=1 then sasname=substr(sasname,anyalpha(sasname)); if anydigit(sasname)=1 then sasname=substr(sasname,anyalpha(sasname));
if upcase(sasname) ne 'FILENAME' then output; if upcase(sasname) ne 'FILENAME' then output;
end; end;
@@ -2290,8 +2311,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))"
@@ -2521,7 +2541,6 @@ create table &outds as
datetime2 format or regular decimal type datetime2 format or regular decimal type
@version 9.3 @version 9.3
@author Allan Bowe @author Allan Bowe
@source https://github.com/sasjs/core
**/ **/
%macro mp_getddl(libref,ds,fref=getddl,flavour=SAS,showlog=NO,schema= %macro mp_getddl(libref,ds,fref=getddl,flavour=SAS,showlog=NO,schema=
@@ -2623,7 +2642,7 @@ run;
%let curds=%scan(&dsnlist,&x); %let curds=%scan(&dsnlist,&x);
data _null_; data _null_;
file &fref mod; file &fref mod;
length nm lab $1024; length nm lab $1024 typ $20;
set &colinfo (where=(upcase(memname)="&curds")) end=last; set &colinfo (where=(upcase(memname)="&curds")) end=last;
if _n_=1 then do; if _n_=1 then do;
@@ -2637,10 +2656,12 @@ run;
end; end;
else put " ,"@@; else put " ,"@@;
if length(format)>1 then fmt=" format="!!cats(format); if length(format)>1 then fmt=" format="!!cats(format);
len=" length="!!cats(length); if length(label)>1 then lab=" label="!!quote(trim(label));
lab=" label="!!quote(trim(label));
if notnull='yes' then notnul=' not null'; if notnull='yes' then notnul=' not null';
put name type len fmt notnul lab; if type='char' then typ=cats('char(',length,')');
else if length ne 8 then typ='num length='!!left(length);
else typ='num';
put name typ fmt notnul lab;
run; run;
/* Extra step for data constraints */ /* Extra step for data constraints */
@@ -2650,7 +2671,7 @@ 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. */ /* Create Unique Indexes, but only if they were not already defined within the Constraints section. */
data _null_; data _null_;
*length ds $128; *length ds $128;
@@ -2830,7 +2851,7 @@ run;
%end; %end;
%end; %end;
%if &showlog=YES %then %do; %if %upcase(&showlog)=YES %then %do;
options ps=max; options ps=max;
data _null_; data _null_;
infile &fref; infile &fref;
@@ -2915,9 +2936,9 @@ create table &outds (rename=(
@brief Guess the primary key of a table @brief Guess the primary key of a table
@details Tries to guess the primary key of a table based on the following logic: @details Tries to guess the primary key of a table based on the following logic:
* Columns with nulls are ignored * Columns with nulls are ignored
* Return only column combinations that provide unique results * Return only column combinations that provide unique results
* Start from one column, then move out to include composite keys of 2 to 6 columns * Start from one column, then move out to include composite keys of 2 to 6 columns
The library of the target should be assigned before using this macro. The library of the target should be assigned before using this macro.
@@ -2963,7 +2984,7 @@ create table &outds (rename=(
/* get null count and row count */ /* get null count and row count */
%let tmpvar=%mf_getuniquename(); %let tmpvar=%mf_getuniquename();
proc sql noprint; proc sql noprint;
create table _data_ as select create table _data_ as select
count(*) as &tmpvar count(*) as &tmpvar
%do i=1 %to &vcnt; %do i=1 %to &vcnt;
%let var=%scan(&vars,&i); %let var=%scan(&vars,&i);
@@ -2997,10 +3018,10 @@ create table &outds (rename=(
%put &sysmacroname: &baseds has no combination of unique records! Exiting.; %put &sysmacroname: &baseds has no combination of unique records! Exiting.;
%return; %return;
%end; %end;
/* now check cardinality */ /* now check cardinality */
proc sql noprint; proc sql noprint;
create table _data_ as select create table _data_ as select
%do i=1 %to &ppkcnt; %do i=1 %to &ppkcnt;
%let var=%scan(&posspks,&i); %let var=%scan(&posspks,&i);
count(distinct &var) as &var count(distinct &var) as &var
@@ -3124,7 +3145,7 @@ create table &outds (rename=(
%end; %end;
%end; %end;
%end; %end;
%if &ppkcnt=4 %then %do; %if &ppkcnt=4 %then %do;
%put &sysmacroname: No more PK guess possible; %put &sysmacroname: No more PK guess possible;
%return; %return;
@@ -3140,7 +3161,7 @@ create table &outds (rename=(
%let lev3=%scan(&posspks,&k); %let lev3=%scan(&posspks,&k);
%if &lev1 ne &lev3 and &lev2 ne &lev3 %then %do l=4 %to &ppkcnt; %if &lev1 ne &lev3 and &lev2 ne &lev3 %then %do l=4 %to &ppkcnt;
%let lev4=%scan(&posspks,&l); %let lev4=%scan(&posspks,&l);
%if &lev1 ne &lev4 and &lev2 ne &lev4 and &lev3 ne &lev4 %then %if &lev1 ne &lev4 and &lev2 ne &lev4 and &lev3 ne &lev4 %then
%do m=5 %to &ppkcnt; %do m=5 %to &ppkcnt;
%let lev5=%scan(&posspks,&m); %let lev5=%scan(&posspks,&m);
%if &lev1 ne &lev5 & &lev2 ne &lev5 & &lev3 ne &lev5 & &lev4 ne &lev5 %then %do; %if &lev1 ne &lev5 & &lev2 ne &lev5 & &lev3 ne &lev5 & &lev4 ne &lev5 %then %do;
@@ -3162,7 +3183,7 @@ create table &outds (rename=(
%end; %end;
%end; %end;
%end; %end;
%if &ppkcnt=5 %then %do; %if &ppkcnt=5 %then %do;
%put &sysmacroname: No more PK guess possible; %put &sysmacroname: No more PK guess possible;
%return; %return;
@@ -3178,17 +3199,17 @@ create table &outds (rename=(
%let lev3=%scan(&posspks,&k); %let lev3=%scan(&posspks,&k);
%if &lev1 ne &lev3 and &lev2 ne &lev3 %then %do l=4 %to &ppkcnt; %if &lev1 ne &lev3 and &lev2 ne &lev3 %then %do l=4 %to &ppkcnt;
%let lev4=%scan(&posspks,&l); %let lev4=%scan(&posspks,&l);
%if &lev1 ne &lev4 and &lev2 ne &lev4 and &lev3 ne &lev4 %then %if &lev1 ne &lev4 and &lev2 ne &lev4 and &lev3 ne &lev4 %then
%do m=5 %to &ppkcnt; %do m=5 %to &ppkcnt;
%let lev5=%scan(&posspks,&m); %let lev5=%scan(&posspks,&m);
%if &lev1 ne &lev5 & &lev2 ne &lev5 & &lev3 ne &lev5 & &lev4 ne &lev5 %then %if &lev1 ne &lev5 & &lev2 ne &lev5 & &lev3 ne &lev5 & &lev4 ne &lev5 %then
%do n=6 %to &ppkcnt; %do n=6 %to &ppkcnt;
%let lev6=%scan(&posspks,&n); %let lev6=%scan(&posspks,&n);
%if &lev1 ne &lev6 & &lev2 ne &lev6 & &lev3 ne &lev6 %if &lev1 ne &lev6 & &lev2 ne &lev6 & &lev3 ne &lev6
& &lev4 ne &lev6 & &lev5 ne &lev6 %then & &lev4 ne &lev6 & &lev5 ne &lev6 %then
%do; %do;
/* check for four level uniqueness */ /* check for four level uniqueness */
proc sort data=&pkds(keep=&lev1 &lev2 &lev3 &lev4 &lev5 &lev6) proc sort data=&pkds(keep=&lev1 &lev2 &lev3 &lev4 &lev5 &lev6)
out=&tmpds noduprec; out=&tmpds noduprec;
by _all_; by _all_;
run; run;
@@ -3207,7 +3228,7 @@ create table &outds (rename=(
%end; %end;
%end; %end;
%end; %end;
%if &ppkcnt=6 %then %do; %if &ppkcnt=6 %then %do;
%put &sysmacroname: No more PK guess possible; %put &sysmacroname: No more PK guess possible;
%return; %return;

View File

@@ -3,7 +3,7 @@
@brief Returns the engine type of a SAS library @brief Returns the engine type of a SAS library
@details Usage: @details Usage:
%put %mf_getEngine(SASHELP); %put %mf_getengine(SASHELP);
returns: returns:
> V9 > V9
@@ -21,9 +21,10 @@
@version 9.2 @version 9.2
@author Allan Bowe @author Allan Bowe
**/
%macro mf_getEngine(libref **/ /** \cond */
%macro mf_getengine(libref
)/*/STORE SOURCE*/; )/*/STORE SOURCE*/;
%local dsid engnum rc engine; %local dsid engnum rc engine;
@@ -42,3 +43,5 @@
&engine &engine
%mend; %mend;
/** \endcond */

View File

@@ -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 */

View File

@@ -1,17 +1,17 @@
/** /**
@file @file
@brief Returns all files and subdirectories within a specified parent @brief Returns all files and subdirectories within a specified parent
@details When used with getattrs=NO, is not OS specific (uses dopen / dread). @details When used with getattrs=NO, is not OS specific (uses dopen / dread).
If getattrs=YES then the doptname / foptname functions are used to scan all If getattrs=YES then the doptname / foptname functions are used to scan all
properties - any characters that are not valid in a SAS name (v7) are simply properties - any characters that are not valid in a SAS name (v7) are simply
stripped, and the table is transposed so theat each property is a column stripped, and the table is transposed so theat each property is a column
and there is one file per row. An attempt is made to get all properties and there is one file per row. An attempt is made to get all properties
whether a file or folder, but some files/folders cannot be accessed, and so whether a file or folder, but some files/folders cannot be accessed, and so
not all properties can / will be populated. not all properties can / will be populated.
Credit for the rename approach: Credit for the rename approach:
https://communities.sas.com/t5/SAS-Programming/SAS-Function-to-convert-string-to-Legal-SAS-Name/m-p/27375/highlight/true#M5003 https://communities.sas.com/t5/SAS-Programming/SAS-Function-to-convert-string-to-Legal-SAS-Name/m-p/27375/highlight/true#M5003
usage: usage:
@@ -20,21 +20,25 @@
%mp_dirlist(outds=cwdfileprops, getattrs=YES) %mp_dirlist(outds=cwdfileprops, getattrs=YES)
@warning In a Unix environment, the existence of a named pipe will cause this %mp_dirlist(fref=MYFREF)
@warning In a Unix environment, the existence of a named pipe will cause this
macro to hang. Therefore this tool should be used with caution in a SAS 9 web macro to hang. Therefore this tool should be used with caution in a SAS 9 web
application, as it can use up all available multibridge sessions if requests application, as it can use up all available multibridge sessions if requests
are resubmitted. are resubmitted.
If anyone finds a way to positively identify a named pipe using SAS (without If anyone finds a way to positively identify a named pipe using SAS (without
X CMD) do please raise an issue! X CMD) do please raise an issue!
@param path= for which to return contents @param path= for which to return contents
@param fref= Provide a DISK engine fileref as an alternative to PATH
@param outds= the output dataset to create @param outds= the output dataset to create
@param getattrs= YES/NO (default=NO). Uses doptname and foptname to return @param getattrs= YES/NO (default=NO). Uses doptname and foptname to return
all attributes for each file / folder. all attributes for each file / folder.
@returns outds contains the following variables: @returns outds contains the following variables:
- directory (containing folder)
- file_or_folder (file / folder) - file_or_folder (file / folder)
- filepath (path/to/file.name) - filepath (path/to/file.name)
- filename (just the file name) - filename (just the file name)
@@ -47,18 +51,26 @@
**/ **/
%macro mp_dirlist(path=%sysfunc(pathname(work)) %macro mp_dirlist(path=%sysfunc(pathname(work))
, fref=0
, outds=work.mp_dirlist , outds=work.mp_dirlist
, getattrs=NO , getattrs=NO
)/*/STORE SOURCE*/; )/*/STORE SOURCE*/;
%let getattrs=%upcase(&getattrs)XX; %let getattrs=%upcase(&getattrs)XX;
data &outds (compress=no keep=file_or_folder filepath filename ext msg); data &outds (compress=no keep=file_or_folder filepath filename ext msg directory);
length filepath $500 fref fref2 $8 file_or_folder $6 filename $80 ext $20 msg $200; length directory filepath $500 fref fref2 $8 file_or_folder $6 filename $80 ext $20 msg $200;
rc = filename(fref, "&path"); %if &fref=0 %then %do;
rc = filename(fref, "&path");
%end;
%else %do;
fref="&fref";
rc=0;
%end;
if rc = 0 then do; if rc = 0 then do;
did = dopen(fref); did = dopen(fref);
directory=dinfo(did,'Directory');
if did=0 then do; if did=0 then do;
putlog "NOTE: This directory is empty - &path"; putlog "NOTE: This directory is empty - " directory;
msg=sysmsg(); msg=sysmsg();
put _all_; put _all_;
stop; stop;
@@ -73,7 +85,8 @@ data &outds (compress=no keep=file_or_folder filepath filename ext msg);
dnum = dnum(did); dnum = dnum(did);
do i = 1 to dnum; do i = 1 to dnum;
filename = dread(did, i); filename = dread(did, i);
rc = filename(fref2, "&path/"!!filename); filepath=cats(directory,'/',filename);
rc = filename(fref2,filepath);
midd=dopen(fref2); midd=dopen(fref2);
dmsg=sysmsg(); dmsg=sysmsg();
if did > 0 then file_or_folder='folder'; if did > 0 then file_or_folder='folder';
@@ -82,12 +95,12 @@ data &outds (compress=no keep=file_or_folder filepath filename ext msg);
fmsg=sysmsg(); fmsg=sysmsg();
if midf > 0 then file_or_folder='file'; if midf > 0 then file_or_folder='file';
rc=fclose(midf); rc=fclose(midf);
if index(fmsg,'File is in use') or index(dmsg,'is not a directory') if index(fmsg,'File is in use') or index(dmsg,'is not a directory')
then file_or_folder='file'; then file_or_folder='file';
else if index(fmsg, 'Insufficient authorization') then file_or_folder='file'; else if index(fmsg, 'Insufficient authorization') then file_or_folder='file';
else if file_or_folder='' then file_or_folder='locked'; else if file_or_folder='' then file_or_folder='locked';
if file_or_folder='file' then do; if file_or_folder='file' then do;
ext = prxchange('s/.*\.{1,1}(.*)/$1/', 1, filename); ext = prxchange('s/.*\.{1,1}(.*)/$1/', 1, filename);
if filename = ext then ext = ' '; if filename = ext then ext = ' ';
@@ -96,7 +109,6 @@ data &outds (compress=no keep=file_or_folder filepath filename ext msg);
ext=''; ext='';
file_or_folder='folder'; file_or_folder='folder';
end; end;
filepath="&path/"!!filename;
output; output;
end; end;
rc = dclose(did); rc = dclose(did);
@@ -120,7 +132,7 @@ run;
else do i=1 to foptnum(fid); else do i=1 to foptnum(fid);
infoname=foptname(fid,i); infoname=foptname(fid,i);
infoval=finfo(fid,infoname); infoval=finfo(fid,infoname);
sasname=compress(infoname, '_', 'adik'); sasname=compress(infoname, '_', 'adik');
if anydigit(sasname)=1 then sasname=substr(sasname,anyalpha(sasname)); if anydigit(sasname)=1 then sasname=substr(sasname,anyalpha(sasname));
if upcase(sasname) ne 'FILENAME' then output; if upcase(sasname) ne 'FILENAME' then output;
end; end;
@@ -137,7 +149,7 @@ run;
else do i=1 to doptnum(fid); else do i=1 to doptnum(fid);
infoname=doptname(fid,i); infoname=doptname(fid,i);
infoval=dinfo(fid,infoname); infoval=dinfo(fid,infoname);
sasname=compress(infoname, '_', 'adik'); sasname=compress(infoname, '_', 'adik');
if anydigit(sasname)=1 then sasname=substr(sasname,anyalpha(sasname)); if anydigit(sasname)=1 then sasname=substr(sasname,anyalpha(sasname));
if upcase(sasname) ne 'FILENAME' then output; if upcase(sasname) ne 'FILENAME' then output;
end; end;

View File

@@ -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))"

View File

@@ -30,7 +30,6 @@
datetime2 format or regular decimal type datetime2 format or regular decimal type
@version 9.3 @version 9.3
@author Allan Bowe @author Allan Bowe
@source https://github.com/sasjs/core
**/ **/
%macro mp_getddl(libref,ds,fref=getddl,flavour=SAS,showlog=NO,schema= %macro mp_getddl(libref,ds,fref=getddl,flavour=SAS,showlog=NO,schema=
@@ -132,7 +131,7 @@ run;
%let curds=%scan(&dsnlist,&x); %let curds=%scan(&dsnlist,&x);
data _null_; data _null_;
file &fref mod; file &fref mod;
length nm lab $1024; length nm lab $1024 typ $20;
set &colinfo (where=(upcase(memname)="&curds")) end=last; set &colinfo (where=(upcase(memname)="&curds")) end=last;
if _n_=1 then do; if _n_=1 then do;
@@ -146,10 +145,12 @@ run;
end; end;
else put " ,"@@; else put " ,"@@;
if length(format)>1 then fmt=" format="!!cats(format); if length(format)>1 then fmt=" format="!!cats(format);
len=" length="!!cats(length); if length(label)>1 then lab=" label="!!quote(trim(label));
lab=" label="!!quote(trim(label));
if notnull='yes' then notnul=' not null'; if notnull='yes' then notnul=' not null';
put name type len fmt notnul lab; if type='char' then typ=cats('char(',length,')');
else if length ne 8 then typ='num length='!!left(length);
else typ='num';
put name typ fmt notnul lab;
run; run;
/* Extra step for data constraints */ /* Extra step for data constraints */
@@ -159,7 +160,7 @@ 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. */ /* Create Unique Indexes, but only if they were not already defined within the Constraints section. */
data _null_; data _null_;
*length ds $128; *length ds $128;
@@ -339,7 +340,7 @@ run;
%end; %end;
%end; %end;
%if &showlog=YES %then %do; %if %upcase(&showlog)=YES %then %do;
options ps=max; options ps=max;
data _null_; data _null_;
infile &fref; infile &fref;

View File

@@ -3,9 +3,9 @@
@brief Guess the primary key of a table @brief Guess the primary key of a table
@details Tries to guess the primary key of a table based on the following logic: @details Tries to guess the primary key of a table based on the following logic:
* Columns with nulls are ignored * Columns with nulls are ignored
* Return only column combinations that provide unique results * Return only column combinations that provide unique results
* Start from one column, then move out to include composite keys of 2 to 6 columns * Start from one column, then move out to include composite keys of 2 to 6 columns
The library of the target should be assigned before using this macro. The library of the target should be assigned before using this macro.
@@ -51,7 +51,7 @@
/* get null count and row count */ /* get null count and row count */
%let tmpvar=%mf_getuniquename(); %let tmpvar=%mf_getuniquename();
proc sql noprint; proc sql noprint;
create table _data_ as select create table _data_ as select
count(*) as &tmpvar count(*) as &tmpvar
%do i=1 %to &vcnt; %do i=1 %to &vcnt;
%let var=%scan(&vars,&i); %let var=%scan(&vars,&i);
@@ -85,10 +85,10 @@
%put &sysmacroname: &baseds has no combination of unique records! Exiting.; %put &sysmacroname: &baseds has no combination of unique records! Exiting.;
%return; %return;
%end; %end;
/* now check cardinality */ /* now check cardinality */
proc sql noprint; proc sql noprint;
create table _data_ as select create table _data_ as select
%do i=1 %to &ppkcnt; %do i=1 %to &ppkcnt;
%let var=%scan(&posspks,&i); %let var=%scan(&posspks,&i);
count(distinct &var) as &var count(distinct &var) as &var
@@ -212,7 +212,7 @@
%end; %end;
%end; %end;
%end; %end;
%if &ppkcnt=4 %then %do; %if &ppkcnt=4 %then %do;
%put &sysmacroname: No more PK guess possible; %put &sysmacroname: No more PK guess possible;
%return; %return;
@@ -228,7 +228,7 @@
%let lev3=%scan(&posspks,&k); %let lev3=%scan(&posspks,&k);
%if &lev1 ne &lev3 and &lev2 ne &lev3 %then %do l=4 %to &ppkcnt; %if &lev1 ne &lev3 and &lev2 ne &lev3 %then %do l=4 %to &ppkcnt;
%let lev4=%scan(&posspks,&l); %let lev4=%scan(&posspks,&l);
%if &lev1 ne &lev4 and &lev2 ne &lev4 and &lev3 ne &lev4 %then %if &lev1 ne &lev4 and &lev2 ne &lev4 and &lev3 ne &lev4 %then
%do m=5 %to &ppkcnt; %do m=5 %to &ppkcnt;
%let lev5=%scan(&posspks,&m); %let lev5=%scan(&posspks,&m);
%if &lev1 ne &lev5 & &lev2 ne &lev5 & &lev3 ne &lev5 & &lev4 ne &lev5 %then %do; %if &lev1 ne &lev5 & &lev2 ne &lev5 & &lev3 ne &lev5 & &lev4 ne &lev5 %then %do;
@@ -250,7 +250,7 @@
%end; %end;
%end; %end;
%end; %end;
%if &ppkcnt=5 %then %do; %if &ppkcnt=5 %then %do;
%put &sysmacroname: No more PK guess possible; %put &sysmacroname: No more PK guess possible;
%return; %return;
@@ -266,17 +266,17 @@
%let lev3=%scan(&posspks,&k); %let lev3=%scan(&posspks,&k);
%if &lev1 ne &lev3 and &lev2 ne &lev3 %then %do l=4 %to &ppkcnt; %if &lev1 ne &lev3 and &lev2 ne &lev3 %then %do l=4 %to &ppkcnt;
%let lev4=%scan(&posspks,&l); %let lev4=%scan(&posspks,&l);
%if &lev1 ne &lev4 and &lev2 ne &lev4 and &lev3 ne &lev4 %then %if &lev1 ne &lev4 and &lev2 ne &lev4 and &lev3 ne &lev4 %then
%do m=5 %to &ppkcnt; %do m=5 %to &ppkcnt;
%let lev5=%scan(&posspks,&m); %let lev5=%scan(&posspks,&m);
%if &lev1 ne &lev5 & &lev2 ne &lev5 & &lev3 ne &lev5 & &lev4 ne &lev5 %then %if &lev1 ne &lev5 & &lev2 ne &lev5 & &lev3 ne &lev5 & &lev4 ne &lev5 %then
%do n=6 %to &ppkcnt; %do n=6 %to &ppkcnt;
%let lev6=%scan(&posspks,&n); %let lev6=%scan(&posspks,&n);
%if &lev1 ne &lev6 & &lev2 ne &lev6 & &lev3 ne &lev6 %if &lev1 ne &lev6 & &lev2 ne &lev6 & &lev3 ne &lev6
& &lev4 ne &lev6 & &lev5 ne &lev6 %then & &lev4 ne &lev6 & &lev5 ne &lev6 %then
%do; %do;
/* check for four level uniqueness */ /* check for four level uniqueness */
proc sort data=&pkds(keep=&lev1 &lev2 &lev3 &lev4 &lev5 &lev6) proc sort data=&pkds(keep=&lev1 &lev2 &lev3 &lev4 &lev5 &lev6)
out=&tmpds noduprec; out=&tmpds noduprec;
by _all_; by _all_;
run; run;
@@ -295,7 +295,7 @@
%end; %end;
%end; %end;
%end; %end;
%if &ppkcnt=6 %then %do; %if &ppkcnt=6 %then %do;
%put &sysmacroname: No more PK guess possible; %put &sysmacroname: No more PK guess possible;
%return; %return;

View File

@@ -36,5 +36,9 @@ echo 'core.sasjs.io' > CNAME
git add * git add *
git commit -m "build.sh build on $(date +%F:%H:%M:%S)" git commit -m "build.sh build on $(date +%F:%H:%M:%S)"
git push git push
npx sitemap-generator-cli https://core.sasjs.io
git add *
git commit -m "adding sitemap"
git push
echo "check it out: https://sasjs.github.io/core.github.io/files.html" echo "check it out: https://sasjs.github.io/core.github.io/files.html"