Compare commits

...

33 Commits

Author SHA1 Message Date
yabwon
387898e01a version 20200730
Adjusted to SPF v.20200730
2020-07-31 22:20:10 +02:00
yabwon
e801f99e1c version 20200730
version 20200730, change list:

1) All elements of the SAS Packages Framework were moved to the SPFinit.sas file in directory SPF [SAS Packages Framework].

2) The public repository reordered [two new folders] and location link in the %installPackages() macro changed.

3) New directories: SPF [for SAS Packages Framework content and documentation] and packages [for packages repository]

4) Package FunctionsImissinBASE renamed to BasePlus.

5) All packages recompiled with new setup.

6) Help info improved and spellings corrected.
2020-07-31 14:43:40 +02:00
yabwon
850e003ea9 folder name corrected
folder name corrected
2020-07-31 11:34:06 +02:00
yabwon
21827e7ffa version 20200730
example added
2020-07-30 19:02:34 +02:00
yabwon
d59fb10575 version 20200730
Adjustments for version 20200730
2020-07-30 16:00:07 +02:00
yabwon
8e6a2d0da5 Update LICENSE 2020-07-30 15:30:59 +02:00
yabwon
0c75cf373e Merge branch 'master' of https://github.com/yabwon/SAS_PACKAGES 2020-07-30 15:28:43 +02:00
yabwon
42ede60e73 version 20200703
info about available packages
2020-07-30 15:28:33 +02:00
yabwon
a33d67528a version 20200730
Adjustments for version 20200730.
2020-07-30 15:25:21 +02:00
yabwon
9459b110d6 version 20200730
version 20200730, change list:

1) All elements of the SAS Packages Framework were moved to the SPFinit.sas file in directory SPF [SAS Packages Framework].

2) The public repository reordered [two new folders] and location link in the %installPackages() macro changed.

3) New directories: SPF [for SAS Packages Framework content and documentation] and packages [for packages repository]

4) Package FunctionsImissinBASE renamed to BasePlus.

5) All packages recompiled with new setup.
2020-07-30 15:01:05 +02:00
yabwon
0c49d2a5b1 version 20200730
adjusted to new setup
2020-07-30 14:56:06 +02:00
yabwon
98a6beeb8c version 0.5
recompiled with new framework setup

package FunctionsImissinBASE renamed to BasePlus
2020-07-30 14:46:45 +02:00
yabwon
6e03570afb version 0.3
recompiled with new framework setup
2020-07-30 14:46:05 +02:00
yabwon
b4bb3296c3 version 0.2
recompiled with new framework setup
2020-07-30 14:45:56 +02:00
yabwon
6841f6bd08 version 2.1
recompiled with new framework setup
2020-07-30 14:45:19 +02:00
yabwon
f4493aef1c version 20200730
version 20200730, change list:

1) All elements of the SAS Packages Framework were moved to the SPFinit.sas file in directory SPF [SAS Packages Framework].

2) The public repository reordered [two new folders] and location link in the %installPackages() macro changed.

3) New directories: SPF [for SAS Packages Framework content and documentation] and packages [for packages repository]

4) Package FunctionsImissinBASE renamed to BasePlus.

5) All packages recompiled with new setup.
2020-07-30 14:43:42 +02:00
yabwon
3e117ce8ef version 20200730
Deleted because repository was rerganised.
2020-07-30 14:39:26 +02:00
yabwon
f73e7c4c68 Update README.md
update about FunctionsImissinBASE 0.5
2020-07-27 19:37:36 +02:00
yabwon
e15ddd22cd version 0.5
some functions were renamed: arrRepNull() is now arrFillMiss(), the "shifting" functions are now arrMissToLeft/Right().
corrected help info.

thanks to ChrisNZ @ communities.sas.com for great feedback and valuable suggestions!
2020-07-27 19:35:50 +02:00
yabwon
f36dcd369e Update README.md
info about FunctionsImissinBASE 0.4
2020-07-26 17:35:59 +02:00
yabwon
84705927f1 version 0.4
some functions were renamed: arrVal() is arrFill(), replaceNull() is now arrRepNull(), kill() is now delDataset() ,and the "shifting" functions have "arr" prefix.
macros have new parameters: quote=,
new format added: boolz,
corrected help info.

thanks to ChrisNZ @ communities.sas.com for great feedback and valuable suggestions!
2020-07-26 17:35:23 +02:00
yabwon
51a921162f version 20200725
version 20200725, descriptions to macros added
2020-07-25 12:37:39 +02:00
yabwon
50adc7818b Update README.md
Latest version is 20200725.
2020-07-25 12:26:31 +02:00
yabwon
57fd048276 version 20200725
version 20200725, descriptions to macros added
2020-07-25 12:22:14 +02:00
yabwon
757d7a9ccc Update README.md
New macros: getVars() amd QgetVars() added to the functionsImissinBASE package.
2020-07-25 11:36:47 +02:00
yabwon
365f8b459e version 0.3
New macros getVars() amd QgetVars() added.
2020-07-25 11:28:57 +02:00
yabwon
c712bfd162 Update README.md
FunctionsImissinBASE 0.2
2020-06-29 21:59:30 +02:00
yabwon
70912499d5 Merge branch 'master' of https://github.com/yabwon/SAS_PACKAGES 2020-06-29 21:57:24 +02:00
yabwon
a5e428aa3f version 0.2
4 formats added
2020-06-29 21:56:59 +02:00
yabwon
d1cc2e7a8b Update README.md 2020-06-29 21:29:15 +02:00
yabwon
19f6889945 new package FunctionsImissinBASE added
new package FunctionsImissinBASE added
2020-06-25 16:50:30 +02:00
yabwon
f0336647e0 version 0.1
Functions I miss in BASE: a bunch of functions and functionalities I am missing in BASE SAS
2020-06-25 16:44:56 +02:00
yabwon
499846dbb1 [2020.06.21] Extended and up to date version of the SGF article
[2020.06.21] Extended and up to date version of the SGF article

formating update in the "User's session."
2020-06-21 12:06:00 +02:00
26 changed files with 1055 additions and 960 deletions

View File

@@ -1,6 +1,6 @@
MIT License
Copyright (c) 2019 Bartosz Jablonski
Copyright (c) since 2019 Bartosz Jablonski
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -6,7 +6,9 @@ A **SAS package** is an automatically generated, single, stand alone *zip* file
The *purpose of a package* is to be a simple, and easy to access, code sharing medium, which will allow: on the one hand, to separate the code complex dependencies created by the developer from the user experience with the final product and, on the other hand, reduce developer's and user's unnecessary frustration related to a remote deployment process.
In this repository we are presenting a **standalone Base SAS framework** which allows to develop and use SAS packages. Read the **`SAS(r) packages - the way to share (a how to)- Paper 4725-2020 - extended.pdf`** to learn more.
In this repository we are presenting the **SAS Packages Framework** which allows to develop and use SAS packages. The latest version of SPF is `20200730`.
Read the **`SAS(r) packages - the way to share (a how to)- Paper 4725-2020 - extended.pdf`** to learn more (see the `./SPF/Documentation` directory).
**General overview video:**
- SAS Global Forum 2020 V.E.: `https://www.youtube.com/watch?v=qCkb-bx0Dv8&t=0s`
@@ -18,14 +20,15 @@ To use a package:
and then either:
- Download the `loadpackage.sas` file (user part of the framework) into the packages folder.
- \[Optional\] Download the `<packageName>.zip` file into the packages folder.
- Download the `SPFinit.sas` file (the SAS Packages Framework) into the local packages folder.
- \[Optional\] Manually download the `<packageName>.zip` file into the local packages folder.
- and Execute:
```
filename packages "<directory/containing/packages/>"; /* setup directory for packages */
%include packages(loadpackage.sas); /* enable the framework */
%include packages(SPFinit.sas); /* enable the framework */
/* %installPackage(packageName) */ /* install the package, unless you downloaded it manually */
%installPackage(packageName) /* install the package, unless you downloaded it manually */
%helpPackage(packageName) /* get help about the package */
%loadPackage(packageName) /* load the package content into the SAS session */
```
@@ -33,37 +36,40 @@ filename packages "<directory/containing/packages/>"; /* setup directory for pac
or if you need it just for "one time" only Execute:
```
filename packages "<directory/containing/packages/>"; /* setup directory for packages */
filename spfinit url "https://raw.githubusercontent.com/yabwon/SAS_PACKAGES/master/loadpackage.sas";
%include spfinit; /* enable the framework */
filename packages "%sysfunc(pathname(work))"; /* setup temporary directory for packages in the WORK */
filename SPFinit url "https://raw.githubusercontent.com/yabwon/SAS_PACKAGES/master/SPF/SPFinit.sas";
%include SPFinit; /* enable the framework */
%installPackage(packageName) /* install the package */
%helpPackage(packageName) /* get help about the package */
%loadPackage(packageName) /* load the package content into the SAS session */
```
**Workshop video for User**\[May 6th, 2020\]**: `https://youtu.be/qX_-HJ76g8Y`**
**Workshop video for the User**\[May 6th, 2020\]**: `https://youtu.be/qX_-HJ76g8Y`** [a bit outdated but gives the idea how it works]
### The Developer:
To create your own package:
- Read the **`SAS(r) packages - the way to share (a how to)- Paper 4725-2020 - extended.pdf`** to learn more.
- Download and use the `generatePackage.sas` file (developer part of the framework) and the `loadpackage.sas` file (user part of the framework but required for *testing*).
- Read the **`SAS(r) packages - the way to share (a how to)- Paper 4725-2020 - extended.pdf`** to learn more details.
- Download and use the `SPFinit.sas` file (the SAS Packages Framework) file (user part of the framework required for *testing* is there too).
#### If you have any questions, suggestions, or ideas do not hesitate to contact me!
**Update**\[June 3rd, 2020\]**:** `%installPackage()` **macro is available**. The `%installPackage()` macro is embedded in the `loadpackage.sas` part of the framework.
**Update**\[June 10th, 2020\]**:** To see help info about framework macros and their parameters just run: `%generatePackage()`, `%installPackage()`, `%helpPackage()`, `%loadPackage()`, and `%unloadPackage()` with empty parameter list.
**Update**\[July 30th, 2020\]**:** All components of SAS Packages Framework are now in one file `SPFinit.sas` (located in the `./SPF` directory). Documentation moved to `./SPF/Documentation` directory. Packages zip files moved to `./packages` directory.
## Available packages:
Currently the following packages are available:
Currently the following packages are available (see the `./packages` directory):
- **SQLinDS**\[2.1\], based on Mike Rhoads' article *Use the Full Power of SAS in Your Function-Style Macros*. The package allows to write SQL queries in the datastep, e.g.
- **SQLinDS**\[2.1\], based on Mike Rhoads' article *Use the Full Power of SAS in Your Function-Style Macros*. The package allows to write SQL queries in the data step, e.g.
```
data class;
set %SQL(select * from sashelp.class order by age);
run;
```
- **DFA** (Dynamic Function Arrays)\[0.2\], contains set of macros and FCMP functions which implement: a dynamically allocated array, a stack, a fifo queue, an ordered stack, and a priority queue, run `%helpPackage(DFA,createDFArray)` to find examples.
- **macroArray**\[0.3\], implementation of an array concept in a macrolanguage, e.g.
```
@@ -79,6 +85,22 @@ run;
%put &i.) %ABC(&i.);
%end;
```
- **dynMacroArray**\[0.2\], set of macros (wrappers for a hash table) emulating dynamic array in the datastep (macro predecessor of DFA)
- **BasePlus**\[0.5\] adds a bunch of functionalities I am missing in BASE SAS, such as:
```
call arrMissToRight(myArray);
call arrFillMiss(17, myArray);
call arrFill(42, myArray);
rc = delDataset("DataSetToDrop");
string = catXFn("date9.", "#", myArray);
format x bool.;
%put %getVars(sashelp.class, patern = ght$, sep = +, varRange = _numeric_);
```
- **dynMacroArray**\[0.2\], set of macros (wrappers for a hash table) emulating dynamic array in the data step (macro predecessor of DFA)
### ======

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,4 @@
Copyright (c) 2019 Bartosz Jablonski
Copyright (c) 2019 - 2020 Bartosz Jablonski
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -1,164 +0,0 @@
/*** HELP START ***/
/**############################################################################**/
/* */
/* Copyright Bartosz Jablonski, July 2019. */
/* */
/* Code is free and open source. If you want - you can use it. */
/* I tested it the best I could */
/* but it comes with absolutely no warranty whatsoever. */
/* If you cause any damage or something - it will be your own fault. */
/* You have been warned! You are using it on your own risk. */
/* However, if you decide to use it do not forget to mention author: */
/* Bartosz Jablonski (yabwon@gmail.com) */
/* */
/* Here is the official version: */
/*
Copyright (c) 2019 Bartosz Jablonski (yabwon@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**#############################################################################**/
/* Macros to install SAS packages, version 20200603 */
/* A SAS package is a zip file containing a group of files
with SAS code (macros, functions, datasteps generating
data, etc.) wrapped up together and %INCLUDEed by
a single load.sas file (also embedded inside the zip).
*/
/*** HELP END ***/
/*** HELP START ***/
%macro installPackage(
packageName /* package name, without the zip extension */
, sourcePath = /* location of the package, e.g. "www.some.page/", mind the "/" at the end */
, replace = 1 /* 1 = replace if the package already exist, 0 = otherwise */
)
/*** HELP END ***/
/
secure;
%local ls_tmp ps_tmp notes_tmp source_tmp fullstimer_tmp stimer_tmp msglevel_tmp;
%let ls_tmp = %sysfunc(getoption(ls));
%let ps_tmp = %sysfunc(getoption(ps));
%let notes_tmp = %sysfunc(getoption(notes));
%let source_tmp = %sysfunc(getoption(source));
%let stimer_tmp = %sysfunc(getoption(stimer));
%let fullstimer_tmp = %sysfunc(getoption(fullstimer));
%let msglevel_tmp = %sysfunc(getoption(msglevel));
options NOnotes NOsource ls=MAX ps=MAX NOfullstimer NOstimer msglevel=N;
%local in out;
%let in = i%sysfunc(md5(&packageName.),hex7.);
%let out = o%sysfunc(md5(&packageName.),hex7.);
/*options MSGLEVEL=i;*/
/*
Reference:
https://blogs.sas.com/content/sasdummy/2011/06/17/how-to-use-sas-data-step-to-copy-a-file-from-anywhere/
*/
%if %superq(sourcePath)= %then
%do;
%let sourcePath = https://raw.githubusercontent.com/yabwon/SAS_PACKAGES/master/;
%end;
filename &in URL "&sourcePath.%lowcase(&packageName.).zip" recfm=N lrecl=1;
filename &out "%sysfunc(pathname(packages))/%lowcase(&packageName.).zip" recfm=N lrecl=1;
/*
filename in list;
filename out list;
*/
/* copy the file byte-by-byte */
data _null_;
length filein 8 out_path in_path $ 4096;
out_path = pathname ("&out");
in_path = pathname ("&in" );
filein = fopen( "&in", 'S', 1, 'B');
if filein = 0 then
put "ERROR: Source file:" /
"ERROR- " in_path /
"ERROR- is unavaliable!";
if filein > 0;
put @2 "Source information:";
infonum = FOPTNUM(filein);
length infoname $ 32 infoval $ 128;
do i=1 to coalesce(infonum, -1);
infoname = FOPTNAME(filein, i);
infoval = FINFO(filein, infoname);
put @4 infoname ":"
/ @6 infoval
;
end;
rc = FCLOSE(filein);
put;
if FEXIST("&out") = 0 then
do;
put @2 "Installing the &packageName. package.";
rc = FCOPY("&in", "&out");
end;
else if FEXIST("&out") = 1 then
do;
if symget("replace")="1" then
do;
put @2 "The following file will be replaced during "
/ @2 "instalation of the &packageName. package: "
/ @5 out_path;
rc = FDELETE("&out");
rc = FCOPY("&in", "&out");
end;
else
do;
put @2 "The following file will NOT be replaced: "
/ @5 out_path;
rc = 1;
end;
end;
put @2 "Done with return code " rc=;
run;
filename &in clear;
filename &out clear;
options ls = &ls_tmp. ps = &ps_tmp.
&notes_tmp. &source_tmp.
&stimer_tmp. &fullstimer_tmp.
msglevel=&msglevel_tmp.;
%mend installPackage;
/*** HELP START ***/
/* Example 1:
filename packages "C:/Users/&sysuserid/Desktop/download_test/";
%installPackage(SQLinDS);
%installPackage(SQLinDS);
%installPackage(SQLinDS,replace=0);
%installPackage(NotExistingPackage);
*/
/*** HELP END ***/

View File

@@ -1,129 +0,0 @@
/*** HELP START ***/
/**############################################################################**/
/* */
/* Copyright Bartosz Jablonski, July 2019. */
/* */
/* Code is free and open source. If you want - you can use it. */
/* I tested it the best I could */
/* but it comes with absolutely no warranty whatsoever. */
/* If you cause any damage or something - it will be your own fault. */
/* You've been warned! You are using it on your own risk. */
/* However, if you decide to use it don't forget to mention author: */
/* Bartosz Jablonski (yabwon@gmail.com) */
/* */
/* Here is the official version: */
/*
Copyright (c) 2019 Bartosz Jablonski (yabwon@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**#############################################################################**/
/* Macros to list SAS packages in packages' folder, version 20200608 */
/* A SAS package is a zip file containing a group
of SAS codes (macros, functions, datasteps generating
data, etc.) wrapped up together and %INCLUDEed by
a single load.sas file (also embedded inside the zip).
*/
/*
* Example 1:
filename packages "C:\SAS_PACKAGES";
%include packages(listpackages.sas);
%listPackages()
*/
/*** HELP END ***/
%macro listPackages();
%local ls_tmp ps_tmp notes_tmp source_tmp;
%let filesWithCodes = WORK._%sysfunc(datetime(), hex16.)_;
%local ls_tmp ps_tmp notes_tmp source_tmp;
%let ls_tmp = %sysfunc(getoption(ls));
%let ps_tmp = %sysfunc(getoption(ps));
%let notes_tmp = %sysfunc(getoption(notes));
%let source_tmp = %sysfunc(getoption(source));
options NOnotes NOsource ls=MAX ps=MAX;
data _null_;
base = "%sysfunc(pathname(packages))";
if base = " " then
do;
put "NOTE: The filereference PACKAGES is not assigned.";
stop;
end;
length folder file $ 256 folderRef fileRef $ 8;
folderRef = "_%sysfunc(datetime(), hex6.)0";
rc=filename(folderRef, base);
folderid=dopen(folderRef);
put;
put "/*" 100*"+" ;
do i=1 to dnum(folderId); drop i;
folder = dread(folderId, i);
fileRef = "_%sysfunc(datetime(), hex6.)1";
rc = filename(fileRef, catx("/", base, folder));
fileId = dopen(fileRef);
EOF = 0;
if fileId = 0 and lowcase(scan(folder, -1, ".")) = 'zip' then
do;
file = catx('/',base, folder);
length nn $ 96;
nn = repeat("*", (96-lengthn(file)));
putlog " ";
put " * " file @; put nn /;
infile package ZIP FILEVAR=file member="description.sas" end=EOF;
do until(EOF);
input;
if lowcase(scan(_INFILE_,1,":")) in ("package" "title" "version" "author" "maintainer" "license") then
do;
_INFILE_ = scan(_INFILE_,1,":") !! ":" !! scan(_INFILE_,2,":");
putlog " * " _INFILE_;
end;
if strip(_INFILE_) = "DESCRIPTION START:" then leave;
end;
end;
rc = dclose(fileId);
rc = filename(fileRef);
end;
putlog " ";
put 100*"+" "*/";
rc = dclose(folderid);
rc = filename(folderRef);
stop;
run;
options ls = &ls_tmp. ps = &ps_tmp. &notes_tmp. &source_tmp.;
%mend listPackages;

View File

@@ -1,595 +0,0 @@
/*** HELP START ***/
/**############################################################################**/
/* */
/* Copyright Bartosz Jablonski, July 2019. */
/* */
/* Code is free and open source. If you want - you can use it. */
/* I tested it the best I could */
/* but it comes with absolutely no warranty whatsoever. */
/* If you cause any damage or something - it will be your own fault. */
/* You have been warned! You are using it on your own risk. */
/* However, if you decide to use it do not forget to mention author: */
/* Bartosz Jablonski (yabwon@gmail.com) */
/* */
/* Here is the official version: */
/*
Copyright (c) 2019 Bartosz Jablonski (yabwon@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**#############################################################################**/
/* Macros to load, to get help, or to unload SAS packages, version 20200610 */
/* A SAS package is a zip file containing a group of files
with SAS code (macros, functions, datasteps generating
data, etc.) wrapped up together and %INCLUDEed by
a single load.sas file (also embedded inside the zip).
*/
/*** HELP END ***/
/*** HELP START ***/
%macro loadPackage(
packageName /* name of a package,
e.g. myPackage,
required and not null */
, path = %sysfunc(pathname(packages)) /* location of a package,
by default it looks for
location of "packages" fileref */
, options = %str(LOWCASE_MEMNAME) /* posible options for ZIP filename */
, source2 = /*source2*/ /* option to print out details,
null by default */
, requiredVersion = . /* option to test if loaded package
is provided in required version */
, lazyData = /* a list of names of lazy datasets
to be loaded, if not null then
datasets from the list are loaded
instead of a package, asterisk
means "load all datasets" */
, zip = zip /* standard package is zip (lowcase),
e.g. %loadPackage(PiPackage)
if the zip is not avaliable use a folder
unpack data to "pipackage.disk" folder
and use loadPackage in the form:
%loadPackage(PiPackage, zip=disk, options=)
*/
)/secure;
/*** HELP END ***/
%if %superq(packageName) = %then
%do;
%put ;
%put ###############################################################################;
%put # This is short help information for the loadPackage macro #;
%put ###############################################################################;
%put # #;
%put # Macro to load SAS packages, version 20200610 #;
%put # #;
%put # A SAS package is a zip file containing a group #;
%put # of SAS codes (macros, functions, datasteps generating #;
%put # data, etc.) wrapped up together and included by #;
%put # a single load.sas file (also embedded inside the zip). #;
%put # #;
%put # Parameters: #;
%put # #;
%put # packageName Name of a package, e.g. myPackage, #;
%put # Required and not null, default use case: #;
%put # %nrstr(%%loadPackage(myPackage)). #;
%put # If empty displays this help information. #;
%put # #;
%put # path= Location of a package. By default it looks for #;
%put # location of the "packages" fileref, i.e. #;
%put # %nrstr(%%sysfunc(pathname(packages))) #;
%put # #;
%put # options= Posible options for ZIP filename, #;
%put # default value: LOWCASE_MEMNAME #;
%put # #;
%put # source2= Option to print out details, null by default. #;
%put # #;
%put # requiredVersion= Option to test if the loaded package #;
%put # is provided in required version, #;
%put # default value: . #;
%put # #;
%put # lazyData= A list of names of lazy datasets to be loaded. #;
%put # If not null datasets from the list are loaded #;
%put # instead of the package. #;
%put # Asterisk (*) means "load all datasets". #;
%put # #;
%put # zip=zip Standard package is zip (lowcase), #;
%put # e.g. %nrstr(%%loadPackage(PiPackage)). #;
%put # If the zip is not avaliable use a folder. #;
%put # Unpack data to "pipackage.disk" folder #;
%put # and use loadPackage in the following form: #;
%put # %nrstr(%%loadPackage(PiPackage, zip=disk, options=)) #;
%put # #;
%put ###############################################################################;
%put ;
%GOTO ENDloadPackage;
%end;
%local ls_tmp ps_tmp notes_tmp source_tmp fullstimer_tmp stimer_tmp msglevel_tmp;
%let ls_tmp = %sysfunc(getoption(ls));
%let ps_tmp = %sysfunc(getoption(ps));
%let notes_tmp = %sysfunc(getoption(notes));
%let source_tmp = %sysfunc(getoption(source));
%let stimer_tmp = %sysfunc(getoption(stimer));
%let fullstimer_tmp = %sysfunc(getoption(fullstimer));
%let msglevel_tmp = %sysfunc(getoption(msglevel));
options NOnotes NOsource ls=MAX ps=MAX NOfullstimer NOstimer msglevel=N;
%local _PackageFileref_;
%let _PackageFileref_ = P%sysfunc(MD5(%lowcase(&packageName.)),hex7.);
filename &_PackageFileref_. &ZIP.
/* put location of package myPackageFile.zip here */
"&path./%lowcase(&packageName.).&zip." %unquote(&options.)
;
%if %sysfunc(fexist(&_PackageFileref_.)) %then
%do;
%include &_PackageFileref_.(packagemetadata.sas) / &source2.;
filename &_PackageFileref_. clear;
/* test if required version of package is "good enough" */
%if %sysevalf(&requiredVersion. > &packageVersion.) %then
%do;
%put ERROR: Required version is &requiredVersion.;
%put ERROR- Provided version is &packageVersion.;
%ABORT;
%end;
options ls = &ls_tmp. ps = &ps_tmp. &notes_tmp. &source_tmp.;
filename &_PackageFileref_. &ZIP.
"&path./%lowcase(&packageName.).&zip." %unquote(&options.)
ENCODING =
%if %bquote(&packageEncoding.) NE %then &packageEncoding. ;
%else utf8 ;
;
%if %bquote(&lazyData.) = %then
%do;
%include &_PackageFileref_.(load.sas) / &source2.;
%end;
%else
%do;
%include &_PackageFileref_.(lazydata.sas) / &source2.;
%end;
%end;
%else %put ERROR:[&sysmacroname] File "&path./&packageName..&zip." does not exist;
filename &_PackageFileref_. clear;
options ls = &ls_tmp. ps = &ps_tmp.
&notes_tmp. &source_tmp.
&stimer_tmp. &fullstimer_tmp.
msglevel=&msglevel_tmp.;
/* jump here after running %loadPackage() - only help is displayed */
%ENDloadPackage:
%mend loadPackage;
/*** HELP START ***/
%macro unloadPackage(
packageName /* name of a package,
e.g. myPackage,
required and not null */
, path = %sysfunc(pathname(packages)) /* location of a package,
by default it looks for
location of "packages" fileref */
, options = %str(LOWCASE_MEMNAME) /* possible options for ZIP filename */
, source2 = /*source2*/ /* option to print out details,
null by default */
, zip = zip /* standard package is zip (lowcase),
e.g. %unloadPackage(PiPackage)
if the zip is not avaliable use a folder
unpack data to "pipackage.disk" folder
and use unloadPackage in the form:
%unloadPackage(PiPackage, zip=disk, options=)
*/
)/secure;
/*** HELP END ***/
%if %superq(packageName) = %then
%do;
%put ;
%put ###############################################################################;
%put # This is short help information for the unloadPackage macro #;
%put ###############################################################################;
%put # #;
%put # Macro to unload SAS packages, version 20200610 #;
%put # #;
%put # A SAS package is a zip file containing a group #;
%put # of SAS codes (macros, functions, datasteps generating #;
%put # data, etc.) wrapped up together and included by #;
%put # a single load.sas file (also embedded inside the zip). #;
%put # #;
%put # Parameters: #;
%put # #;
%put # packageName Name of a package, e.g. myPackage, #;
%put # Required and not null, default use case: #;
%put # %nrstr(%%unloadPackage(myPackage)). #;
%put # If empty displays this help information. #;
%put # #;
%put # path= Location of a package. By default it looks for #;
%put # location of the "packages" fileref, i.e. #;
%put # %nrstr(%%sysfunc(pathname(packages))) #;
%put # #;
%put # options= Posible options for ZIP filename, #;
%put # default value: LOWCASE_MEMNAME #;
%put # #;
%put # source2= Option to print out details, null by default. #;
%put # #;
%put # zip=zip Standard package is zip (lowcase), #;
%put # e.g. %nrstr(%%unloadPackage(PiPackage)). #;
%put # If the zip is not avaliable use a folder. #;
%put # Unpack data to "pipackage.disk" folder #;
%put # and use loadPackage in the following form: #;
%put # %nrstr(%%unloadPackage(PiPackage, zip=disk, options=)) #;
%put # #;
%put ###############################################################################;
%put ;
%GOTO ENDunloadPackage;
%end;
%local ls_tmp ps_tmp notes_tmp source_tmp msglevel_tmp;
%let ls_tmp = %sysfunc(getoption(ls));
%let ps_tmp = %sysfunc(getoption(ps));
%let notes_tmp = %sysfunc(getoption(notes));
%let source_tmp = %sysfunc(getoption(source));
%let msglevel_tmp = %sysfunc(getoption(msglevel));
options NOnotes NOsource ls=MAX ps=MAX msglevel=N;
%local _PackageFileref_;
%let _PackageFileref_ = P%sysfunc(MD5(%lowcase(&packageName.)),hex7.);
filename &_PackageFileref_. &ZIP.
/* put location of package myPackageFile.zip here */
"&path./%lowcase(&packageName.).&zip." %unquote(&options.)
;
%if %sysfunc(fexist(&_PackageFileref_.)) %then
%do;
%include &_PackageFileref_.(packagemetadata.sas) / &source2.;
filename &_PackageFileref_. clear;
options ls = &ls_tmp. ps = &ps_tmp. &notes_tmp. &source_tmp.;
filename &_PackageFileref_. &ZIP.
"&path./%lowcase(&packageName.).&zip." %unquote(&options.)
ENCODING =
%if %bquote(&packageEncoding.) NE %then &packageEncoding. ;
%else utf8 ;
;
%include &_PackageFileref_.(unload.sas) / &source2.;
%end;
%else %put ERROR:[&sysmacroname] File "&path./&packageName..&zip." does not exist;
filename &_PackageFileref_. clear;
options ls = &ls_tmp. ps = &ps_tmp. &notes_tmp. &source_tmp. msglevel = &msglevel_tmp.;
/* jump here after running %unloadPackage() - only help is displayed */
%ENDunloadPackage:
%mend unloadPackage;
/*** HELP START ***/
%macro helpPackage(
packageName /* name of a package,
e.g. myPackageFile.zip,
required and not null */
, helpKeyword /* phrase to search in help,
when empty prints description
"*" means prints all help
"license" prints license */
, path = %sysfunc(pathname(packages)) /* location of a package,
by default it looks for
location of "packages" fileref */
, options = %str(LOWCASE_MEMNAME) /* possible options for ZIP filename */
, source2 = /*source2*/ /* option to print out details,
null by default */
, zip = zip /* standard package is zip (lowcase),
e.g. %helpPackage(PiPackage,*)
if the zip is not avaliable use a folder
unpack data to "pipackage.disk" folder
and use helpPackage in the form:
%helpPackage(PiPackage, *, zip=disk, options=)
*/
)/secure;
/*** HELP END ***/
%if %superq(packageName) = %then
%do;
%put ;
%put ###############################################################################;
%put # This is short help information for the helpPackage macro #;
%put ###############################################################################;
%put # #;
%put # Macro to get help about SAS packages, version 20200610 #;
%put # #;
%put # A SAS package is a zip file containing a group #;
%put # of SAS codes (macros, functions, datasteps generating #;
%put # data, etc.) wrapped up together and included by #;
%put # a single load.sas file (also embedded inside the zip). #;
%put # #;
%put # Parameters: #;
%put # #;
%put # packageName Name of a package, e.g. myPackage, #;
%put # Required and not null, default use case: #;
%put # %nrstr(%%helpPackage(myPackage)). #;
%put # If empty displays this help information. #;
%put # #;
%put # helpKeyword Phrase to search in help, #;
%put # - when empty prints description, #;
%put # - "*" means prints all help, #;
%put # - "license" prints license. #;
%put # #;
%put # path= Location of a package. By default it looks for #;
%put # location of the "packages" fileref, i.e. #;
%put # %nrstr(%%sysfunc(pathname(packages))) #;
%put # #;
%put # options= Posible options for ZIP filename, #;
%put # default value: LOWCASE_MEMNAME #;
%put # #;
%put # source2= Option to print out details, null by default. #;
%put # #;
%put # zip=zip Standard package is zip (lowcase), #;
%put # e.g. %nrstr(%%helpPackage(PiPackage)). #;
%put # If the zip is not avaliable use a folder. #;
%put # Unpack data to "pipackage.disk" folder #;
%put # and use loadPackage in the following form: #;
%put # %nrstr(%%helpPackage(PiPackage, zip=disk, options=)) #;
%put # #;
%put ###############################################################################;
%put ;
%GOTO ENDhelpPackage;
%end;
%local ls_tmp ps_tmp notes_tmp source_tmp msglevel_tmp;
%let ls_tmp = %sysfunc(getoption(ls));
%let ps_tmp = %sysfunc(getoption(ps));
%let notes_tmp = %sysfunc(getoption(notes));
%let source_tmp = %sysfunc(getoption(source));
%let msglevel_tmp = %sysfunc(getoption(msglevel));
options NOnotes NOsource ls=MAX ps=MAX msglevel=N;
%local _PackageFileref_;
%let _PackageFileref_ = P%sysfunc(MD5(%lowcase(&packageName.)),hex7.);
filename &_PackageFileref_. &ZIP.
/* put location of package myPackageFile.zip here */
"&path./%lowcase(&packageName.).&zip." %unquote(&options.)
;
%if %sysfunc(fexist(&_PackageFileref_.)) %then
%do;
%include &_PackageFileref_.(packagemetadata.sas) / &source2.;
filename &_PackageFileref_. clear;
options ls = &ls_tmp. ps = &ps_tmp. &notes_tmp. &source_tmp.;
filename &_PackageFileref_. &ZIP.
"&path./%lowcase(&packageName.).&zip." %unquote(&options.)
ENCODING =
%if %bquote(&packageEncoding.) NE %then &packageEncoding. ;
%else utf8 ;
;
%include &_PackageFileref_.(help.sas) / &source2.;
%end;
%else %put ERROR:[&sysmacroname] File "&path./&packageName..&zip." does not exist;
filename &_PackageFileref_. clear;
options ls = &ls_tmp. ps = &ps_tmp. &notes_tmp. &source_tmp. msglevel = &msglevel_tmp.;
/* jump here after running %helpPackage() - only help is displayed */
%ENDhelpPackage:
%mend helpPackage;
/*
TODO:
- macro for testing available packages in the packages folder [DONE] checkout: %listPackages()
- add MD5(&packageName.) value hash instead "package" word in filenames [DONE]
*/
/*** HELP START ***/
/*
* Filenames references "packages" and "package" are keywords;
* the first one should be used to point folder with packages;
* the second is used internally by macros;
* Example 1:
* assuming that _THIS_FILE_ and the SQLinDS package (sqlinds.zip file)
* are located in the "C:/SAS_PACKAGES/" folder
* copy the following code into autoexec.sas
* or run it in your SAS session
**/
/*
filename packages "C:/SAS_PACKAGES";
%include packages(loadpackage.sas);
%loadpackage(SQLinDS)
%helpPackage(SQLinDS)
%unloadPackage(SQLinDS)
* optional;
libname packages "C:/SAS_PACKAGES/";
%include "%sysfunc(pathname(packages))/loadpackage.sas";
%loadPackage(SQLinDS)
%helpPackage(SQLinDS)
%unloadPackage(SQLinDS)
* in case when user SAS session does not support ZIP fileref ;
* the following solution could be used, ;
* unzip packagename.zip content into packagename.disk folder ;
* and run macros with following options: ;
%loadPackage(packageName,zip=disk,options=)
%helpPackage(packageName,,zip=disk,options=) %* mind double comma! ;
%unloadPackage(packageName,zip=disk,options=)
*/
/*** HELP END ***/
/*** HELP START ***/
/* Macros to install SAS packages, version 20200603 */
/* A SAS package is a zip file containing a group of files
with SAS code (macros, functions, datasteps generating
data, etc.) wrapped up together and %INCLUDEed by
a single load.sas file (also embedded inside the zip).
*/
/*** HELP END ***/
/*** HELP START ***/
%macro installPackage(
packageName /* package name, without the zip extension */
, sourcePath = /* location of the package, e.g. "www.some.page/", mind the "/" at the end */
, replace = 1 /* 1 = replace if the package already exist, 0 = otherwise */
)
/*** HELP END ***/
/
secure;
%if %superq(packageName) = %then
%do;
%put ;
%put ###############################################################################;
%put # This is short help information for the installPackage macro #;
%put ###############################################################################;
%put # #;
%put # Macro to install SAS packages, version 20200610 #;
%put # #;
%put # A SAS package is a zip file containing a group #;
%put # of SAS codes (macros, functions, datasteps generating #;
%put # data, etc.) wrapped up together and included by #;
%put # a single load.sas file (also embedded inside the zip). #;
%put # #;
%put # Parameters: #;
%put # #;
%put # packageName Name of a package, e.g. myPackage, #;
%put # Required and not null, default use case: #;
%put # %nrstr(%%installPackage(myPackage)). #;
%put # If empty displays this help information. #;
%put # #;
%put # sourcePath= Location of the package, e.g. "www.some.web.page/" #;
%put # Mind the "/" at the end of the path! #;
%put # Current default location: #;
%put # https://raw.githubusercontent.com/yabwon/SAS_PACKAGES/master/ #;
%put # #;
%put # replace= With default value of 1 it causes existing package file #;
%put # to be replaceed by new downloaded file. #;
%put # #;
%put ###############################################################################;
%put ;
%GOTO ENDinstallPackage;
%end;
%local ls_tmp ps_tmp notes_tmp source_tmp fullstimer_tmp stimer_tmp msglevel_tmp;
%let ls_tmp = %sysfunc(getoption(ls));
%let ps_tmp = %sysfunc(getoption(ps));
%let notes_tmp = %sysfunc(getoption(notes));
%let source_tmp = %sysfunc(getoption(source));
%let stimer_tmp = %sysfunc(getoption(stimer));
%let fullstimer_tmp = %sysfunc(getoption(fullstimer));
%let msglevel_tmp = %sysfunc(getoption(msglevel));
options NOnotes NOsource ls=MAX ps=MAX NOfullstimer NOstimer msglevel=N;
%local in out;
%let in = i%sysfunc(md5(&packageName.),hex7.);
%let out = o%sysfunc(md5(&packageName.),hex7.);
/*options MSGLEVEL=i;*/
/*
Reference:
https://blogs.sas.com/content/sasdummy/2011/06/17/how-to-use-sas-data-step-to-copy-a-file-from-anywhere/
*/
%if %superq(sourcePath)= %then
%do;
%let sourcePath = https://raw.githubusercontent.com/yabwon/SAS_PACKAGES/master/;
%end;
filename &in URL "&sourcePath.%lowcase(&packageName.).zip" recfm=N lrecl=1;
filename &out "%sysfunc(pathname(packages))/%lowcase(&packageName.).zip" recfm=N lrecl=1;
/*
filename in list;
filename out list;
*/
/* copy the file byte-by-byte */
data _null_;
length filein 8 out_path in_path $ 4096;
out_path = pathname ("&out");
in_path = pathname ("&in" );
filein = fopen( "&in", 'S', 1, 'B');
if filein = 0 then
put "ERROR: Source file:" /
"ERROR- " in_path /
"ERROR- is unavaliable!";
if filein > 0;
put @2 "Source information:";
infonum = FOPTNUM(filein);
length infoname $ 32 infoval $ 128;
do i=1 to coalesce(infonum, -1);
infoname = FOPTNAME(filein, i);
infoval = FINFO(filein, infoname);
put @4 infoname ":"
/ @6 infoval
;
end;
rc = FCLOSE(filein);
put;
if FEXIST("&out") = 0 then
do;
put @2 "Installing the &packageName. package.";
rc = FCOPY("&in", "&out");
end;
else if FEXIST("&out") = 1 then
do;
if symget("replace")="1" then
do;
put @2 "The following file will be replaced during "
/ @2 "instalation of the &packageName. package: "
/ @5 out_path;
rc = FDELETE("&out");
rc = FCOPY("&in", "&out");
end;
else
do;
put @2 "The following file will NOT be replaced: "
/ @5 out_path;
rc = 1;
end;
end;
put @2 "Done with return code " rc=;
run;
filename &in clear;
filename &out clear;
options ls = &ls_tmp. ps = &ps_tmp.
&notes_tmp. &source_tmp.
&stimer_tmp. &fullstimer_tmp.
msglevel=&msglevel_tmp.;
/* jump here after running %installPackage() - only help is displayed */
%ENDinstallPackage:
%mend installPackage;
/*** HELP START ***/
/* Example 1:
filename packages "C:/Users/&sysuserid/Desktop/download_test/";
%installPackage(SQLinDS);
%installPackage(SQLinDS);
%installPackage(SQLinDS,replace=0);
%installPackage(NotExistingPackage);
*/
/*** HELP END ***/

76
packages/README.md Normal file
View File

@@ -0,0 +1,76 @@
## Available packages:
Currently the following packages are available:
- **SQLinDS**\[2.1\], based on Mike Rhoads' article *Use the Full Power of SAS in Your Function-Style Macros*. The package allows to write SQL queries in the data step, e.g.
```
data class;
set %SQL(
select age, name, weight, height
from sashelp.class
order by age
);
WH = weight + height;
run;
```
- **DFA** (Dynamic Function Arrays)\[0.2\], contains set of macros and FCMP functions which implement: a dynamically allocated array, a stack, a fifo queue, an ordered stack, and a priority queue, run `%helpPackage(DFA,createDFArray)` to find examples.
```
%createDFArray(ArrDynamic, resizefactor=17);
data _null_;
call ArrDynamic("Allocate", -2, 2);
do i = -2 to 2;
call ArrDynamic("Input", i, 2**i);
end;
L = .; H = .;
call ArrDynamic("Dim", L, H);
put L= H=;
call ArrDynamic("+", 3, 8);
call ArrDynamic("+",-3, 0.125);
call ArrDynamic("Dim", L, H);
put L= H=;
Value = .;
do i = L to H;
call ArrDynamic("O", i, Value);
put i= Value=;
end;
run;
```
- **macroArray**\[0.3\], implementation of an array concept in a macrolanguage, e.g.
```
%array(ABC[17] (111:127), macarray=Y);
%do i = 1 %to 17;
%put &i.) %ABC(&i.);
%end;
%let %ABC(13,i) = 999; /* i = insert */
%do i = 1 %to 17;
%put &i.) %ABC(&i.);
%end;
```
- **BasePlus**\[0.5\] adds a bunch of functionalities I am missing in BASE SAS, such as:
```
call arrMissToRight(myArray);
call arrFillMiss(17, myArray);
call arrFill(42, myArray);
rc = delDataset("DataSetToDrop");
string = catXFn("date9.", "#", myArray);
format x bool.;
%put %getVars(sashelp.class, patern = ght$, sep = +, varRange = _numeric_);
```
- **dynMacroArray**\[0.2\], set of macros (wrappers for a hash table) emulating dynamic array in the data step (macro predecessor of DFA)

View File

@@ -1,7 +1,7 @@
filename packages "C:\SAS_PACKAGES";
%include packages(generatePackage.sas);
filename packages "C:\SAS_PACKAGES\SASPackagesFramework";
%include packages(SPFinit.sas);
ods html;
%generatePackage(filesLocation=C:\SAS_PACKAGES_DEV\SQLinDS)
@@ -13,7 +13,7 @@ ods html;
* the second is used internally by macros;
filename packages "C:\SAS_PACKAGES";
%include packages(loadpackage.sas);
%include packages(SPFinit.sas);
dm 'log;clear';
%loadpackage(SQLinDS)

BIN
packages/baseplus.zip Normal file

Binary file not shown.

Binary file not shown.

BIN
packages/sqlinds.zip Normal file

Binary file not shown.

Binary file not shown.