mirror of
https://github.com/SASPAC/macroarray.git
synced 2025-12-11 02:14:35 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
05e19344d5 | ||
|
|
c255bf9aeb | ||
|
|
3452ff5ac5 | ||
|
|
8c6b5e4b25 | ||
|
|
58e665069f | ||
|
|
b785e1c9e4 | ||
|
|
4b3d058e75 | ||
|
|
620ff4a74f |
@@ -22,7 +22,7 @@ The **macroArray** package implements an array, a hash table, and a dictionary c
|
||||
);
|
||||
```
|
||||
|
||||
SHA256 digest for the latest version of `macroArray`: F*4FAAEE7DF2854EA31933AE017A89C1615C7291A66A07CCE345041EB0D587ED4E
|
||||
SHA256 digest for the latest version of `macroArray`: F*3F3893F1FCD78719543703E4353F4CC19811D247C016F220FF729B283C1AD790
|
||||
|
||||
[**Documentation for macroArray**](./macroarray.md "Documentation for macroArray")
|
||||
|
||||
|
||||
BIN
extras/Paper_108-PharmaSUG2024.pdf
Normal file
BIN
extras/Paper_108-PharmaSUG2024.pdf
Normal file
Binary file not shown.
1319
extras/Paper_108-PharmaSUG2024.sas
Normal file
1319
extras/Paper_108-PharmaSUG2024.sas
Normal file
File diff suppressed because it is too large
Load Diff
2204
hist/1.1.0/macroarray.md
Normal file
2204
hist/1.1.0/macroarray.md
Normal file
File diff suppressed because it is too large
Load Diff
BIN
hist/1.1.0/macroarray.zip
Normal file
BIN
hist/1.1.0/macroarray.zip
Normal file
Binary file not shown.
2204
hist/1.1.1/macroarray.md
Normal file
2204
hist/1.1.1/macroarray.md
Normal file
File diff suppressed because it is too large
Load Diff
BIN
hist/1.1.1/macroarray.zip
Normal file
BIN
hist/1.1.1/macroarray.zip
Normal file
Binary file not shown.
2285
hist/1.2.0/macroarray.md
Normal file
2285
hist/1.2.0/macroarray.md
Normal file
File diff suppressed because it is too large
Load Diff
BIN
hist/1.2.0/macroarray.zip
Normal file
BIN
hist/1.2.0/macroarray.zip
Normal file
Binary file not shown.
2285
hist/1.2.1/macroarray.md
Normal file
2285
hist/1.2.1/macroarray.md
Normal file
File diff suppressed because it is too large
Load Diff
BIN
hist/1.2.1/macroarray.zip
Normal file
BIN
hist/1.2.1/macroarray.zip
Normal file
Binary file not shown.
2286
hist/1.2.3/macroarray.md
Normal file
2286
hist/1.2.3/macroarray.md
Normal file
File diff suppressed because it is too large
Load Diff
BIN
hist/1.2.3/macroarray.zip
Normal file
BIN
hist/1.2.3/macroarray.zip
Normal file
Binary file not shown.
2286
hist/1.2.5/macroarray.md
Normal file
2286
hist/1.2.5/macroarray.md
Normal file
File diff suppressed because it is too large
Load Diff
BIN
hist/1.2.5/macroarray.zip
Normal file
BIN
hist/1.2.5/macroarray.zip
Normal file
Binary file not shown.
2286
hist/1.2.6/macroarray.md
Normal file
2286
hist/1.2.6/macroarray.md
Normal file
File diff suppressed because it is too large
Load Diff
BIN
hist/1.2.6/macroarray.zip
Normal file
BIN
hist/1.2.6/macroarray.zip
Normal file
Binary file not shown.
153
macroarray.md
153
macroarray.md
@@ -19,9 +19,9 @@
|
||||
|
||||
---
|
||||
|
||||
# The macroArray package [ver. 1.0.6] <a name="macroarray-package"></a> ###############################################
|
||||
# The macroArray package [ver. 1.2.6] <a name="macroarray-package"></a> ###############################################
|
||||
|
||||
The **macroArray** package implements a macro array facility:
|
||||
The **macroArray** package implements a macroarray facility:
|
||||
- `%array()`,
|
||||
- `%do_over()`,
|
||||
- `%make_do_over()`,
|
||||
@@ -75,10 +75,10 @@ Package contains:
|
||||
Required SAS Components:
|
||||
*Base SAS Software*
|
||||
|
||||
*SAS package generated by generatePackage, version 20230905*
|
||||
*SAS package generated by generatePackage, version 20231123*
|
||||
|
||||
The SHA256 hash digest for package macroArray:
|
||||
`F*4FAAEE7DF2854EA31933AE017A89C1615C7291A66A07CCE345041EB0D587ED4E`
|
||||
`F*3F3893F1FCD78719543703E4353F4CC19811D247C016F220FF729B283C1AD790`
|
||||
|
||||
---
|
||||
# Content description ############################################################################################
|
||||
@@ -244,7 +244,7 @@ The code of a macro was inspired by
|
||||
|
||||
The `%array()` macro version provided in the package
|
||||
is designed to facilitate
|
||||
the idea of macro array concept, i.e. *a list of
|
||||
the idea of macroarray concept, i.e. *a list of
|
||||
macrovariables with common prefix and numerical suffixes*.
|
||||
Usually such construction is then resolved by
|
||||
double ampersand syntax, e.g. `&&perfix&i` or similar one.
|
||||
@@ -253,7 +253,7 @@ What is new/extension to the `%array()` macro concept are:
|
||||
|
||||
0. The syntax is closer to the data step one.
|
||||
1. It is a pure macro code (it can be executed in any place
|
||||
of 4GL code), this includes generating macro arrays out
|
||||
of 4GL code), this includes generating macroarrays out
|
||||
of datasets.
|
||||
2. When a macroarrray is created it allows also to generate
|
||||
a new macro (named the same as the array name) and replace
|
||||
@@ -278,6 +278,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
|
||||
<,macarray=N>
|
||||
<,ds=>
|
||||
<,vars=>
|
||||
<,q=>
|
||||
)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
@@ -312,8 +313,8 @@ The basic syntax is the following, the `<...>` means optional parameters:
|
||||
`%array(myArr[*] x1-x3 (4:6), vnames=Y)`
|
||||
will use `x1`, `x2`, and `x3` as values instead `4`, `5`, and `6`.
|
||||
|
||||
* `macarray=N` - *Optional*, default value `N`, if set to `Y`/`YES` then macro named with array
|
||||
name is compiled to create convenient envelope for multiple ampersands, e.g.
|
||||
* `macarray=N` - *Optional*, default value `N`, if set to `Y`/`YES` then a macro, named with the array
|
||||
name, is compiled to create convenient envelope for multiple ampersands, e.g.
|
||||
`%array(myArr[*] x1-x3 (4:6), macarray=Y)`
|
||||
will create `%myArr(J)` macro which will allow to extract "data"
|
||||
from macroarray like:
|
||||
@@ -325,8 +326,8 @@ The basic syntax is the following, the `<...>` means optional parameters:
|
||||
macrovariables with prefix like the array name and numeric suffixes,
|
||||
then the minimum and the maximum index is determined
|
||||
and all not existing global macrovariables are created and
|
||||
a macro is generated in the same way as for the `Y` value
|
||||
|
||||
a macro is generated in the same way as for the `Y` value.
|
||||
|
||||
* `ds=` - *Optional*, use a dataset as a basis for a macroarray data,
|
||||
if used by default overwrites use of the `array` parameter, honors `macarray=`
|
||||
argument, dataset options are allowed, e.g. `sashelp.class(obs=5)`
|
||||
@@ -343,23 +344,28 @@ The basic syntax is the following, the `<...>` means optional parameters:
|
||||
2) macroarray "WEIGHT" with ALL(no separator is equivalent to #)
|
||||
values of variable "weight" <br>
|
||||
3) macroarray "W" with UNIQUE(|) values of variable "weight" and <br>
|
||||
4) macroarray "AGE" with UNIQUE(|) values of variable "age",
|
||||
|
||||
4) macroarray "AGE" with UNIQUE(|) values of variable "age".
|
||||
|
||||
* `q=` - *Optional*, indicates (when set to `1` or '2') if the value should be surrounded by quotes.
|
||||
It uses `quote(cats(...))` combo under the hood. Default value is `0`.
|
||||
Value `1` is for apostrophes, value `2` is for double quotes.
|
||||
Ignored for `macarray=M`.
|
||||
|
||||
|
||||
---
|
||||
|
||||
### EXAMPLES AND USECASES: ####################################################
|
||||
|
||||
|
||||
**EXAMPLE 1.** Basic use-case.
|
||||
Creating macroarray like in the array statement;
|
||||
values are used by default;
|
||||
different types of brackets are allowed;
|
||||
Creating macroarray like in the array statement.
|
||||
Values not variables names are used by default.
|
||||
Different types of brackets are allowed.
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%array(a[*] x1-x5 (1:5))
|
||||
|
||||
%array(b{5} (5*17))
|
||||
%array(b{5} (5*17), q=1)
|
||||
|
||||
%* Mind the $ since it is a character array!;
|
||||
%array(c(3) $ 10 ("a A" "b,B" "c;C"))
|
||||
@@ -405,7 +411,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
|
||||
%put &=g0. &=g1. &=g2.;
|
||||
|
||||
%* Or something more complex;
|
||||
%array(gg[0:11] $ 11, function = put(intnx("MONTH", '1jun2018'd, _I_, "E"), yymmn.))
|
||||
%array(gg[0:11] $ 11, function = put(intnx("MONTH", '1jun2018'd, _I_, "E"), yymmn.), q=1)
|
||||
%put &=ggLBOUND. &=ggHBOUND. &=ggN.;
|
||||
%put &=gg0 &=gg1 &=gg2 ... &=gg11;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
@@ -433,10 +439,10 @@ The basic syntax is the following, the `<...>` means optional parameters:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
**EXAMPLE 6a.** "Uppercas Letters"
|
||||
**EXAMPLE 6a.** Quoted "Uppercas Letters"
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%array(UL[26] $, function = byte(rank("A")+_I_-1) )
|
||||
%array(UL[26] $, function = byte(rank("A")+_I_-1) , q=1)
|
||||
%put &=UL1 &=UL2 ... &=UL25 &=UL26;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
@@ -451,7 +457,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
|
||||
|
||||
%* The range handling, warning;
|
||||
%put *%ll(265)*;
|
||||
|
||||
|
||||
%* The input mode;
|
||||
%put *before:*%ll(2)*;
|
||||
%let %ll(2,I) = bbbbb;
|
||||
@@ -576,10 +582,10 @@ The basic syntax is the following, the `<...>` means optional parameters:
|
||||
Currently the only separator in VARS is a space.
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%array(ds = sashelp.class, vars = height#h weight weight|w age|)
|
||||
%array(ds = sashelp.class, vars = height#h weight weight|w age|, q=1)
|
||||
%put _user_;
|
||||
|
||||
%array(ds = sashelp.class, vars = height#hght weight weight|wght age|, macarray=Y)
|
||||
%array(ds = sashelp.class, vars = height#hght weight weight|wght age|, macarray=Y, q=1)
|
||||
%put *%hght(&hghtLBOUND.)**%weight(2)**%wght(&wghtHBOUND.)**%age(3)*;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
@@ -599,7 +605,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
|
||||
%let myTest6 = 16;
|
||||
%let myTest9 = 19;
|
||||
|
||||
%array(myTest, macarray=M)
|
||||
%array(myTest, macarray=M, q=1)
|
||||
%do_over(myTest, phrase = %nrstr(%put *&_I_.*%myTest(&_I_.)*;))
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
@@ -1205,7 +1211,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
|
||||
1. `H` - *Required*, a hash table macro name and a declaration/definition,
|
||||
e.g. `mcHashTable(HT)`. It names a macro which is generated by
|
||||
the `%mcHashTable()` macro. Provided name cannot be empty
|
||||
or an underscore (`_`). No longer than *16* characters.
|
||||
or an underscore (`_`). No longer than *10* characters.
|
||||
|
||||
2. `METHOD` - *Optional*, if empty (or DECLARE or DCL) then the code of
|
||||
a macro hash table is compiled.
|
||||
@@ -1551,6 +1557,9 @@ The basic syntax is the following, the `<...>` means optional parameters:
|
||||
%mcDictionary(
|
||||
H
|
||||
<,METHOD>
|
||||
<,DS=>
|
||||
<,K=Key>
|
||||
<,D=Data>
|
||||
)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
@@ -1559,13 +1568,25 @@ The basic syntax is the following, the `<...>` means optional parameters:
|
||||
1. `H` - *Required*, a dictionary macro name and a declaration/definition,
|
||||
e.g. `mcDictionary(HT)`. It names a macro which is generated by
|
||||
the `%mcDictionary()` macro. Provided name cannot be empty
|
||||
or an underscore (`_`). No longer than *16* characters.
|
||||
or an underscore (`_`). No longer than *13* characters.
|
||||
|
||||
2. `METHOD` - *Optional*, if empty (or DECLARE or DCL) then the code of
|
||||
a macro dictionary is compiled.
|
||||
If `DELETE` then the macro dictionary named by `H` and all
|
||||
macrovariables named like "`&H._`" are deleted.
|
||||
|
||||
* `DS=` - *Optional*, if NOT empty then the `&DS.` dataset is used to
|
||||
populate dictionary with keys from variable `&K.` and data
|
||||
from variable `&D.` Works only during declaration.
|
||||
|
||||
* `K=` - *Optional*, if the `&DS.` is NOT empty then `&K.` holds a name of
|
||||
a variable which keeps or an expression which generates keys values.
|
||||
Default is `Key`.
|
||||
|
||||
* `D=` - *Optional*, if the `&DS.` is NOT empty then `&D.` holds a name of
|
||||
a variable which keeps or an expression which generates data values.
|
||||
Default is `Data`.
|
||||
|
||||
---
|
||||
|
||||
### THE CREATED MACRO `%&H.()`: ####################################################
|
||||
@@ -1699,7 +1720,7 @@ See examples below to see use cases.
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
**EXAMPLE 2.** Populate macro dictionary from a dataset.
|
||||
**EXAMPLE 2A.** Populate macro dictionary from a dataset "by hand".
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%mcDictionary(CLASS)
|
||||
@@ -1709,6 +1730,7 @@ data _null_;
|
||||
call execute('%CLASS(ADD,key=' !! name !! ',data=' !! age !! ')');
|
||||
run;
|
||||
%put t = %sysevalf(%sysfunc(datetime()) - &t.);
|
||||
%put &=Class_KEYSNUM.;
|
||||
%put _user_;
|
||||
%CLASS(CLEAR)
|
||||
|
||||
@@ -1716,25 +1738,52 @@ run;
|
||||
%mcDictionary(CARS)
|
||||
%let t = %sysfunc(datetime());
|
||||
data _null_;
|
||||
set sashelp.cars;
|
||||
call execute('%CARS(ADD,key=' !! catx("|",make,model,type) !! ',data=' !! MPG_CITY !! ')');
|
||||
set sashelp.cars(obs=42);
|
||||
call execute('%CARS(ADD,key=' !! catx("|",make,model,type) !! ',data=' !! put(MPG_CITY*10,dollar10.2) !! ')');
|
||||
run;
|
||||
%put t = %sysevalf(%sysfunc(datetime()) - &t.);
|
||||
%put &=CARS_KEYSNUM.;
|
||||
%CARS(LIST);
|
||||
|
||||
%put %CARS(F,key=Audi|TT 3.2 coupe 2dr (convertible)|Sports);
|
||||
|
||||
%CARS(CLEAR)
|
||||
%put &=CARS_KEYSNUM.;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
**EXAMPLE 3.** Data portion may require quoting and un-quoting..
|
||||
**EXAMPLE 2B.** Populate macro dictionary from a dataset "automatically".
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%let t = %sysfunc(datetime());
|
||||
%mcDictionary(CLASS,DCL,DS=sashelp.class,k=name,d=_N_)
|
||||
%put t = %sysevalf(%sysfunc(datetime()) - &t.);
|
||||
%put &=CLASS_KEYSNUM.;
|
||||
%put _user_;
|
||||
%CLASS(CLEAR)
|
||||
|
||||
|
||||
%let t = %sysfunc(datetime());
|
||||
%mcDictionary(CARS,DCL,DS=sashelp.cars(obs=42),k=catx("|",make,model,type),d=put(MPG_CITY*10,dollar10.2))
|
||||
%put t = %sysevalf(%sysfunc(datetime()) - &t.);
|
||||
%put &=CARS_KEYSNUM.;
|
||||
%CARS(LIST);
|
||||
|
||||
%put %CARS(F,key=Audi|TT 3.2 coupe 2dr (convertible)|Sports);
|
||||
|
||||
%CARS(CLEAR)
|
||||
%put &=CARS_KEYSNUM.;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
**EXAMPLE 3.** Data portion may require quoting and un-quoting.
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%mcDictionary(CODE)
|
||||
%CODE(CLEAR)
|
||||
%CODE(ADD,key=data, data=%str(data test; x = 42; run;))
|
||||
%CODE(ADD,key=proc, data=%str(proc print; run;))
|
||||
%CODE(ADD,key=macro,data=%nrstr(%put *****;))
|
||||
%CODE(ADD,key=macro,data=%nrstr(%put *1*2*3*4*;))
|
||||
|
||||
%CODE(FIND,key=data)
|
||||
%CODE(FIND,key=proc)
|
||||
@@ -1760,6 +1809,7 @@ data _null_;
|
||||
end;
|
||||
run;
|
||||
%put t = %sysevalf(%sysfunc(datetime()) - &t.);
|
||||
%put %AAA(F,key=A555) %AAA(CHECK,key=A555);
|
||||
%put &=AAA_KEYSNUM;
|
||||
%AAA(CLEAR)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
@@ -1775,13 +1825,50 @@ run;
|
||||
%mcDictionary(ABCDEFGHIJKLMNOP) %* good;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
**EXAMPLE 6.** More fun with datasets.
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
|
||||
data work.metadata;
|
||||
input key :$16. data :$128.;
|
||||
cards;
|
||||
ID ABC-123-XYZ
|
||||
path /path/to/study/data
|
||||
cutoffDT 2023-01-01
|
||||
startDT 2020-01-01
|
||||
endDT 2024-12-31
|
||||
MedDRA v26.0
|
||||
;
|
||||
run;
|
||||
proc print;
|
||||
run;
|
||||
|
||||
%mcDictionary(Study,dcl,DS=work.metadata)
|
||||
|
||||
%put _user_;
|
||||
|
||||
%put *%Study(F,key=ID)**%Study(C,key=ID)*;
|
||||
|
||||
title1 "Study %Study(F,key=ID) is located at %Study(F,key=path)";
|
||||
title2 "it starts %Study(F,key=startDT) and ends %Study(F,key=endDT)";
|
||||
footnote "MedDRA version: %Study(F,key=MedDRA)";
|
||||
|
||||
proc print data=sashelp.class(obs=7);
|
||||
run;
|
||||
|
||||
title;
|
||||
footnote;
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
---
|
||||
|
||||
## >>> `%QzipArrays()` macro: <<< <a name="qziparrays-macro"></a> #######################
|
||||
|
||||
The zipArrays() and QzipArrays() macros
|
||||
allow to use a function on elements of pair of
|
||||
macro arrays.
|
||||
macroarrays.
|
||||
|
||||
For two macroarrays the corresponding
|
||||
elements are taken and the macro applies a function, provided by user,
|
||||
@@ -1892,7 +1979,7 @@ See examples in `%zipArrays()` help for the details.
|
||||
|
||||
The zipArrays() and QzipArrays() macros
|
||||
allow to use a function on elements of pair of
|
||||
macro arrays.
|
||||
macroarrays.
|
||||
|
||||
For two macroarrays the corresponding
|
||||
elements are taken and the macro applies a function, provided by user,
|
||||
@@ -2091,7 +2178,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
|
||||
## >>> `%sortMacroArray()` macro: <<< <a name="sortmacroarray-macro"></a> #######################
|
||||
|
||||
The sortMacroArray() macro
|
||||
allow to sort elements of a macro array.
|
||||
allow to sort elements of a macroarray.
|
||||
|
||||
The **limitation** is that sorted values are limited to 32767 bytes of length.
|
||||
|
||||
|
||||
BIN
macroarray.zip
BIN
macroarray.zip
Binary file not shown.
Reference in New Issue
Block a user