mirror of
https://github.com/yabwon/SAS_PACKAGES.git
synced 2025-12-11 11:14:35 +00:00
Compare commits
33 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
387898e01a | ||
|
|
e801f99e1c | ||
|
|
850e003ea9 | ||
|
|
21827e7ffa | ||
|
|
d59fb10575 | ||
|
|
8e6a2d0da5 | ||
|
|
0c75cf373e | ||
|
|
42ede60e73 | ||
|
|
a33d67528a | ||
|
|
9459b110d6 | ||
|
|
0c49d2a5b1 | ||
|
|
98a6beeb8c | ||
|
|
6e03570afb | ||
|
|
b4bb3296c3 | ||
|
|
6841f6bd08 | ||
|
|
f4493aef1c | ||
|
|
3e117ce8ef | ||
|
|
f73e7c4c68 | ||
|
|
e15ddd22cd | ||
|
|
f36dcd369e | ||
|
|
84705927f1 | ||
|
|
51a921162f | ||
|
|
50adc7818b | ||
|
|
57fd048276 | ||
|
|
757d7a9ccc | ||
|
|
365f8b459e | ||
|
|
c712bfd162 | ||
|
|
70912499d5 | ||
|
|
a5e428aa3f | ||
|
|
d1cc2e7a8b | ||
|
|
19f6889945 | ||
|
|
f0336647e0 | ||
|
|
499846dbb1 |
2
LICENSE
2
LICENSE
@@ -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
|
||||
|
||||
50
README.md
50
README.md
@@ -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)
|
||||
|
||||
### ======
|
||||
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@@ -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
|
||||
@@ -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.
|
||||
¬es_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 ***/
|
||||
129
listpackages.sas
129
listpackages.sas
@@ -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. ¬es_tmp. &source_tmp.;
|
||||
%mend listPackages;
|
||||
|
||||
595
loadpackage.sas
595
loadpackage.sas
@@ -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. ¬es_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.
|
||||
¬es_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. ¬es_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. ¬es_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. ¬es_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. ¬es_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.
|
||||
¬es_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
76
packages/README.md
Normal 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)
|
||||
|
||||
@@ -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
BIN
packages/baseplus.zip
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
packages/sqlinds.zip
Normal file
BIN
packages/sqlinds.zip
Normal file
Binary file not shown.
BIN
sqlinds.zip
BIN
sqlinds.zip
Binary file not shown.
Reference in New Issue
Block a user