macroArray, version 0.5

macroArray, version 0.5
- documentation updated
- the do_overs automatically unquote `betwee=` parameter
This commit is contained in:
yabwon
2020-09-15 11:28:54 +02:00
parent 73e8d10200
commit 5c640cba21
5 changed files with 110 additions and 75 deletions

View File

@@ -98,7 +98,9 @@ SHA256 digest for DFA: BB8768E977D62429368CFF2E5338A6553C35C998AEC09AF24088BA713
which = 1:H:2 which = 1:H:2
); );
``` ```
SHA256 digest for macroArray: 69F6CF496F921D0E21F3524FC7FD130B4B8290C1E0B9BB3ABEA212B734EBE8A1 SHA256 digest for macroArray: ACE3E9374256826AB1E25C2BBDA6CA4CCFB50137B8ACE6E1F11BCDBE7AE24B09
[Documentation for macroArray](https://github.com/yabwon/SAS_PACKAGES/blob/master/packages/macroarray.md "Documentation for macroArray")
- **BasePlus**\[0.62\] adds a bunch of functionalities I am missing in BASE SAS, such as: - **BasePlus**\[0.62\] adds a bunch of functionalities I am missing in BASE SAS, such as:

View File

@@ -49,7 +49,7 @@ run;
SHA256 digest for DFA: BB8768E977D62429368CFF2E5338A6553C35C998AEC09AF24088BA713BB54DDA SHA256 digest for DFA: BB8768E977D62429368CFF2E5338A6553C35C998AEC09AF24088BA713BB54DDA
- **macroArray**\[0.5\], implementation of an array concept in a macrolanguage, e.g. - **macroArray**\[0.5\], implementation of an array concept in a macro language, e.g.
``` ```
%array(ABC[17] (111:127), macarray=Y); %array(ABC[17] (111:127), macarray=Y);
@@ -68,8 +68,9 @@ SHA256 digest for DFA: BB8768E977D62429368CFF2E5338A6553C35C998AEC09AF24088BA713
which = 1:H:2 which = 1:H:2
); );
``` ```
SHA256 digest for macroArray: 69F6CF496F921D0E21F3524FC7FD130B4B8290C1E0B9BB3ABEA212B734EBE8A1 SHA256 digest for macroArray: ACE3E9374256826AB1E25C2BBDA6CA4CCFB50137B8ACE6E1F11BCDBE7AE24B09
[Documentation for macroArray](https://github.com/yabwon/SAS_PACKAGES/blob/master/packages/macroarray.md "Documentation for macroArray")
- **BasePlus**\[0.62\] adds a bunch of functionalities I am missing in BASE SAS, such as: - **BasePlus**\[0.62\] adds a bunch of functionalities I am missing in BASE SAS, such as:
``` ```

View File

@@ -1,3 +1,6 @@
/* 20200914 */
macroArray: ACE3E9374256826AB1E25C2BBDA6CA4CCFB50137B8ACE6E1F11BCDBE7AE24B09
/* 20200914 */ /* 20200914 */
SQLinDS: DD5E319EB5AA29C7054EC428072F987E77C29D36874DED1AE5C62E4B300845EB SQLinDS: DD5E319EB5AA29C7054EC428072F987E77C29D36874DED1AE5C62E4B300845EB
macroArray: 69F6CF496F921D0E21F3524FC7FD130B4B8290C1E0B9BB3ABEA212B734EBE8A1 macroArray: 69F6CF496F921D0E21F3524FC7FD130B4B8290C1E0B9BB3ABEA212B734EBE8A1

View File

@@ -1,4 +1,19 @@
# The macroArray package [ver. 0.5] ############################################### - [The macroArray package [ver. 0.5]](#macroarray)
- [Content description](#content-description)
* [`%appendArray()` macro](#appendarray-macro)
* [`%appendCell()` macro](#appendcell-macro)
* [`%array()` macro](#array-macro)
* [`%concatArrays()` macro](#concatarrays-macro)
* [`%deleteMacArray()` macro](#deletemacarray-macro)
* [`%do_over()` macro](#do-over-macro)
* [`%do_over2()` macro](#do-over2-macro)
* [`%do_over3()` macro](#do-over3-macro)
* [`%make_do_over()` macro](#make-do-over-macro)
* [License](#license)
---
# The macroArray package [ver. 0.5] <a name="macroarray-package"></a> ###############################################
The **macroArray** package implements a macro array facility: The **macroArray** package implements a macro array facility:
- `%array()`, - `%array()`,
@@ -17,7 +32,7 @@ programming level, is provided.
If you are working with BIG macroarrays do not If you are working with BIG macroarrays do not
forget to verify your session setting for macro forget to verify your session setting for macro
memory limits. Run: memory limits. Run:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
proc options group = macro; proc options group = macro;
run; run;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -29,29 +44,31 @@ to verify the following options:
|`MSYMTABMAX=` | specifies the maximum amount of memory available to the macro variable symbol table or tables. | |`MSYMTABMAX=` | specifies the maximum amount of memory available to the macro variable symbol table or tables. |
|`MVARSIZE=` | specifies the maximum size for a macro variable that is stored in memory. | |`MVARSIZE=` | specifies the maximum size for a macro variable that is stored in memory. |
---
Package contains: Package contains:
1. macro appendarray, 1. macro appendarray
2. macro appendcell, 2. macro appendcell
3. macro array, 3. macro array
4. macro concatarrays, 4. macro concatarrays
5. macro deletemacarray, 5. macro deletemacarray
6. macro do_over, 6. macro do_over
7. macro do_over2, 7. macro do_over2
8. macro do_over3, 8. macro do_over3
9. macro make_do_over, 9. macro make_do_over
Required SAS Components: Required SAS Components:
*Base SAS Software* *Base SAS Software*
*SAS package generated by generatePackage, version 20200911* *SAS package generated by generatePackage, version 20200911*
The SHA256 hash digest for package macroArray The SHA256 hash digest for package macroArray:
`69F6CF496F921D0E21F3524FC7FD130B4B8290C1E0B9BB3ABEA212B734EBE8A1` `ACE3E9374256826AB1E25C2BBDA6CA4CCFB50137B8ACE6E1F11BCDBE7AE24B09`
### Content description #######################################################
## >>> `%appendArray()` macro: <<< ############################################## # Content description ############################################################################################
## >>> `%appendArray()` macro: <<< <a name="appendarray-macro"></a> ##############################################
The `%appendArray()` macro is a macrowrapper The `%appendArray()` macro is a macrowrapper
which allows to concatenate two macroarrays which allows to concatenate two macroarrays
@@ -66,7 +83,7 @@ The `%appendArray()` macro executes like a pure macro code.
### SYNTAX: ################################################################### ### SYNTAX: ###################################################################
The basic syntax is the following, the `<...>` means optional parameters: The basic syntax is the following, the `<...>` means optional parameters:
~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~sas
%appendArray( %appendArray(
first first
,second ,second
@@ -80,11 +97,12 @@ The basic syntax is the following, the `<...>` means optional parameters:
2. second - *Required*, a name of a macroarray created by the `%array()` macro. 2. second - *Required*, a name of a macroarray created by the `%array()` macro.
### EXAMPLES AND USECASES: #################################################### ### EXAMPLES AND USECASES: ####################################################
**EXAMPLE 1.** Append macroarrays LL and MM. **EXAMPLE 1.** Append macroarrays LL and MM.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
%array(ll[2:4] $ 12, %array(ll[2:4] $ 12,
function = quote(put(today() + 10*_I_, yymmdd10.)), function = quote(put(today() + 10*_I_, yymmdd10.)),
macarray=Y macarray=Y
@@ -104,15 +122,16 @@ The basic syntax is the following, the `<...>` means optional parameters:
**EXAMPLE 2.** Error handling. **EXAMPLE 2.** Error handling.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
%appendArray(ll, ) %appendArray(ll, )
%appendArray(, mm) %appendArray(, mm)
%appendArray(noExistA, noExistB) %appendArray(noExistA, noExistB)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---
## >>> `%appendCell()` macro: <<< ############################################### ## >>> `%appendCell()` macro: <<< <a name="appendcell-macro"></a> ###############################################
The `%appendCell()` macro allows to append The `%appendCell()` macro allows to append
a macrovariable to a macroarray created by the `%array()` macro. a macrovariable to a macroarray created by the `%array()` macro.
@@ -124,7 +143,7 @@ The `%appendCell()` macro executes like a pure macro code.
### SYNTAX: ################################################################### ### SYNTAX: ###################################################################
The basic syntax is the following, the `<...>` means optional parameters: The basic syntax is the following, the `<...>` means optional parameters:
~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~sas
%appendCell( %appendCell(
first first
,second ,second
@@ -147,7 +166,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
**EXAMPLE 1.** Create two macro wrappers. **EXAMPLE 1.** Create two macro wrappers.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
%* Macro wrapper to append a macrovariable to the end of a macroarray; %* Macro wrapper to append a macrovariable to the end of a macroarray;
%macro appendHC(array,cell); %macro appendHC(array,cell);
%appendCell(&array.,&cell.,H) %appendCell(&array.,&cell.,H)
@@ -180,7 +199,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
**EXAMPLE 2.** Error handling **EXAMPLE 2.** Error handling
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
%appendCell(X,Y,blahblah) %appendCell(X,Y,blahblah)
%appendCell(X,,H) %appendCell(X,,H)
@@ -188,7 +207,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
**EXAMPLE 3.** Adding variable below lower bound. **EXAMPLE 3.** Adding variable below lower bound.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
%array(zero[0:2] $ ("AAA", "BBB", "CCC"), macarray=Y) %array(zero[0:2] $ ("AAA", "BBB", "CCC"), macarray=Y)
%let belowzero=zzz; %let belowzero=zzz;
@@ -196,9 +215,10 @@ The basic syntax is the following, the `<...>` means optional parameters:
%appendCell(zero,belowzero,L) %appendCell(zero,belowzero,L)
%put AFTER *%do_over(zero)**&=zeroLBOUND*&=zeroHBOUND*&=zeroN*; %put AFTER *%do_over(zero)**&=zeroLBOUND*&=zeroHBOUND*&=zeroN*;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---
## >>> `%array()` macro: <<< #################################################### ## >>> `%array()` macro: <<< <a name="array-macro"></a> ####################################################
The code of a macro was inspired by The code of a macro was inspired by
*Ted Clay's* and *David Katz's* macro `%array()`. *Ted Clay's* and *David Katz's* macro `%array()`.
@@ -229,7 +249,7 @@ The `%array()` macro executes like a pure macro code.
### SYNTAX: ################################################################### ### SYNTAX: ###################################################################
The basic syntax is the following, the `<...>` means optional parameters: The basic syntax is the following, the `<...>` means optional parameters:
~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~sas
%array( %array(
array array
<,function=> <,function=>
@@ -302,7 +322,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
4) macroarray "AGE" with UNIQUE(|) values of variable "age", 4) macroarray "AGE" with UNIQUE(|) values of variable "age",
### EXAMPLES AND USECASES: #################################################### ### EXAMPLES AND USECASES: ####################################################
@@ -311,7 +331,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
values are used by default; values are used by default;
different types of brackets are allowed; different types of brackets are allowed;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
%array(a[*] x1-x5 (1:5)) %array(a[*] x1-x5 (1:5))
%array(b{5} (5*17)) %array(b{5} (5*17))
@@ -332,7 +352,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
the `<arrayname>N` returns number of the `<arrayname>N` returns number of
elements in the array `(Hbound - Lbound + 1)`. elements in the array `(Hbound - Lbound + 1)`.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
%array(d[-2:2] $ ("a" "b" "c" "d" "e")) %array(d[-2:2] $ ("a" "b" "c" "d" "e"))
%put &=dLBOUND. &=dHBOUND. &=dN.; %put &=dLBOUND. &=dHBOUND. &=dN.;
%put &=d0. &=d1. &=d2. &=d3. &=d4.; %put &=d0. &=d1. &=d2. &=d3. &=d4.;
@@ -346,7 +366,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
You can use an iterator in a function. You can use an iterator in a function.
As in case of usual arrays it is `_I_`. As in case of usual arrays it is `_I_`.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
%array(e[-3:3] $, function = "A" ) %array(e[-3:3] $, function = "A" )
%put &=eLBOUND. &=eHBOUND. &=eN.; %put &=eLBOUND. &=eHBOUND. &=eN.;
%put &=e0. &=e1. &=e2. &=e3. &=e4. &=e5. &=e6.; %put &=e0. &=e1. &=e2. &=e3. &=e4. &=e5. &=e6.;
@@ -369,7 +389,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
**EXAMPLE 4.** Functions cont. **EXAMPLE 4.** Functions cont.
If there is need for set-up something *before* or *after*: If there is need for set-up something *before* or *after*:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
%array(h[10:12] %array(h[10:12]
,function = rand('Uniform') ,function = rand('Uniform')
,before = call streaminit(123) ,before = call streaminit(123)
@@ -381,7 +401,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
**EXAMPLE 5.** Fibonacci series. **EXAMPLE 5.** Fibonacci series.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
%array(i[1:10] (10*0) %array(i[1:10] (10*0)
,function = ifn(_I_ < 2, 1, sum(i[max(_I_-2,1)], i[max(_I_-1,2)]) ) ) ,function = ifn(_I_ < 2, 1, sum(i[max(_I_-2,1)], i[max(_I_-1,2)]) ) )
%put &=i1 &=i2 &=i3 &=i4 &=i5 &=i6 &=i7 &=i8 &=i9 &=i10; %put &=i1 &=i2 &=i3 &=i4 &=i5 &=i6 &=i7 &=i8 &=i9 &=i10;
@@ -390,7 +410,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
**EXAMPLE 6a.** "Uppercas Letters" **EXAMPLE 6a.** "Uppercas Letters"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
%array(UL[26] $, function = byte(rank("A")+_I_-1) ) %array(UL[26] $, function = byte(rank("A")+_I_-1) )
%put &=UL1 &=UL2 ... &=UL25 &=UL26; %put &=UL1 &=UL2 ... &=UL25 &=UL26;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -400,7 +420,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
Extended by `macarray=Y` option and Extended by `macarray=Y` option and
the input mode support (with `I`). the input mode support (with `I`).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
%array(ll[26] $, function = byte(rank("a")+_I_-1), macarray=Y) %array(ll[26] $, function = byte(rank("a")+_I_-1), macarray=Y)
%put *%ll(&llLBOUND.)*%ll(3)*%ll(4)*%ll(5)*...*%ll(25)*%ll(&llHBOUND.)*; %put *%ll(&llLBOUND.)*%ll(3)*%ll(4)*%ll(5)*...*%ll(25)*%ll(&llHBOUND.)*;
@@ -419,7 +439,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
**EXAMPLE 7.** The use of `vnames=Y` **EXAMPLE 7.** The use of `vnames=Y`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
%array(R R1978-R1982) %array(R R1978-R1982)
%put &=R1 &=R2 &=R3 &=R4 &=R5; %put &=R1 &=R2 &=R3 &=R4 &=R5;
@@ -436,7 +456,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
**EXAMPLE 8.** A "no name" array i.e. the `_[*]` array **EXAMPLE 8.** A "no name" array i.e. the `_[*]` array
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
%array(_[*] x1-x5 (1:5)) %array(_[*] x1-x5 (1:5))
%put _user_; %put _user_;
@@ -451,7 +471,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
**EXAMPLE 9.** Pure macro code can be used in a data step. **EXAMPLE 9.** Pure macro code can be used in a data step.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
data test1; data test1;
set sashelp.class; set sashelp.class;
%array(ds[*] d1-d4 (4*17)) %array(ds[*] d1-d4 (4*17))
@@ -515,7 +535,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
**EXAMPLE 10.** Creating an array from a dataset, basic case. **EXAMPLE 10.** Creating an array from a dataset, basic case.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
%array(ds = sashelp.class, vars = height weight age) %array(ds = sashelp.class, vars = height weight age)
%put _user_; %put _user_;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -530,7 +550,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
4. macroarray "age" with UNIQUE(|) values of variable "age" 4. macroarray "age" with UNIQUE(|) values of variable "age"
Currently the only separator in VARS is a space. Currently the only separator in VARS is a space.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
%array(ds = sashelp.class, vars = height#h weight weight|w age|) %array(ds = sashelp.class, vars = height#h weight weight|w age|)
%put _user_; %put _user_;
@@ -541,13 +561,14 @@ The basic syntax is the following, the `<...>` means optional parameters:
**EXAMPLE 12.** Creating an array from a dataset with dataset options **EXAMPLE 12.** Creating an array from a dataset with dataset options
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
%array(ds = sashelp.cars(obs=100 where=(Cylinders=6)), vars = Make| Type| Model, macarray=Y) %array(ds = sashelp.cars(obs=100 where=(Cylinders=6)), vars = Make| Type| Model, macarray=Y)
%put *%make(&makeLBOUND.)*%Model(2)*%Model(3)*%Model(4)*%type(&typeHBOUND.)*; %put *%make(&makeLBOUND.)*%Model(2)*%Model(3)*%Model(4)*%type(&typeHBOUND.)*;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---
## >>> `%concatArrays()` macro: <<< ############################################# ## >>> `%concatArrays()` macro: <<< <a name="concatarrays-macro"></a> #############################################
The `%concatArrays()` macro allows to concatenate The `%concatArrays()` macro allows to concatenate
two macroarrays created by the `%array()` macro. two macroarrays created by the `%array()` macro.
@@ -561,7 +582,7 @@ The `%concatArrays()` macro executes like a pure macro code.
### SYNTAX: ################################################################### ### SYNTAX: ###################################################################
The basic syntax is the following, the `<...>` means optional parameters: The basic syntax is the following, the `<...>` means optional parameters:
~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~sas
%concatArrays( %concatArrays(
first first
,second ,second
@@ -579,11 +600,12 @@ The basic syntax is the following, the `<...>` means optional parameters:
the second array is removed. the second array is removed.
### EXAMPLES AND USECASES: #################################################### ### EXAMPLES AND USECASES: ####################################################
**EXAMPLE 1.** Concatenate macroarrays LL and MM. **EXAMPLE 1.** Concatenate macroarrays LL and MM.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
%array(ll[2:4] $ 12, %array(ll[2:4] $ 12,
function = quote(put(today() + 10*_I_, yymmdd10.)), function = quote(put(today() + 10*_I_, yymmdd10.)),
macarray=Y macarray=Y
@@ -603,15 +625,16 @@ The basic syntax is the following, the `<...>` means optional parameters:
**EXAMPLE 2.** Error handling. **EXAMPLE 2.** Error handling.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
%concatArrays(ll, ) %concatArrays(ll, )
%concatArrays(, mm) %concatArrays(, mm)
%concatArrays(noExistA, noExistB) %concatArrays(noExistA, noExistB)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---
## >>> `%deleteMacArray()` macro: <<< ########################################### ## >>> `%deleteMacArray()` macro: <<< <a name="deletemacarray-macro"></a> ###########################################
The `%deleteMacArray()` macro allows to delete The `%deleteMacArray()` macro allows to delete
macroarrays created by the `%array()` macro. macroarrays created by the `%array()` macro.
@@ -621,7 +644,7 @@ The `%deleteMacArray()` macro executes like a pure macro code.
### SYNTAX: ################################################################### ### SYNTAX: ###################################################################
The basic syntax is the following, the `<...>` means optional parameters: The basic syntax is the following, the `<...>` means optional parameters:
~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~sas
%deleteMacArray( %deleteMacArray(
arrs arrs
<,macarray=N> <,macarray=N>
@@ -639,7 +662,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
## >>> `%do_over()` macro: <<< ################################################ ## >>> `%do_over()` macro: <<< <a name="do-over-macro"></a>################################################
The code of the macro was inspired by The code of the macro was inspired by
*Ted Clay's* and *David Katz's* macro `%do_over()`. *Ted Clay's* and *David Katz's* macro `%do_over()`.
@@ -652,7 +675,7 @@ The `%do_over()` macro executes like a pure macro code.
### SYNTAX: ################################################################### ### SYNTAX: ###################################################################
The basic syntax is the following, the `<...>` means optional parameters: The basic syntax is the following, the `<...>` means optional parameters:
~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~sas
%do_over( %do_over(
array array
<,phrase=%nrstr(%&array(&_I_.))> <,phrase=%nrstr(%&array(&_I_.))>
@@ -692,7 +715,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
**EXAMPLE 1.** Simple looping. **EXAMPLE 1.** Simple looping.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
%array(beta[*] j k l m (101 102 103 104), vnames=Y, macarray=Y) %array(beta[*] j k l m (101 102 103 104), vnames=Y, macarray=Y)
%put #%do_over(beta)#; %put #%do_over(beta)#;
@@ -709,7 +732,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
**EXAMPLE 2.** Multiple arrays looping. **EXAMPLE 2.** Multiple arrays looping.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
%array(alpha[*] j k l m n, vnames=Y, macarray=Y) %array(alpha[*] j k l m n, vnames=Y, macarray=Y)
%array( beta[5] $ , function = "a", macarray=Y) %array( beta[5] $ , function = "a", macarray=Y)
%array(gamma[4] (101 102 103 104), macarray=Y) %array(gamma[4] (101 102 103 104), macarray=Y)
@@ -728,7 +751,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
**EXAMPLE 3.** Multiple arrays looping, cont. **EXAMPLE 3.** Multiple arrays looping, cont.
Create multiple datasets. Create multiple datasets.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
%do_over(beta %do_over(beta
, phrase = %nrstr( , phrase = %nrstr(
data %alpha(&_I_.)2; data %alpha(&_I_.)2;
@@ -744,7 +767,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
**EXAMPLE 4.** Multiple arrays looping, cont. **EXAMPLE 4.** Multiple arrays looping, cont.
Create multiple datasets using a macro. Create multiple datasets using a macro.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
%macro doit(ds, var=a, val=1); %macro doit(ds, var=a, val=1);
data &ds.; data &ds.;
call streaminit(123); call streaminit(123);
@@ -763,7 +786,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
**EXAMPLE 5.** `%do_over()` inside `%array()` **EXAMPLE 5.** `%do_over()` inside `%array()`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
%array(test[*] x1-x12 (1:12), macarray=Y) %array(test[*] x1-x12 (1:12), macarray=Y)
%put **%test(1)**%test(12)**; %put **%test(1)**%test(12)**;
@@ -780,7 +803,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
**EXAMPLE 6.** Looping over array with *macroquoted* separator. **EXAMPLE 6.** Looping over array with *macroquoted* separator.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
%array(alpha[11] (5:15), macarray=Y) %array(alpha[11] (5:15), macarray=Y)
%let x = %do_over(alpha %let x = %do_over(alpha
@@ -794,7 +817,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
**EXAMPLE 7.** Working with the `WHICH=` optional parameter **EXAMPLE 7.** Working with the `WHICH=` optional parameter
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
%array(test[*] x01-x12, vnames= Y, macarray=Y) %array(test[*] x01-x12, vnames= Y, macarray=Y)
%put #%do_over(test)#; %put #%do_over(test)#;
@@ -815,9 +838,10 @@ The basic syntax is the following, the `<...>` means optional parameters:
%put #%do_over(test, which= L:H h:l:-1 13 14, between=%str(,))#; %put #%do_over(test, which= L:H h:l:-1 13 14, between=%str(,))#;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---
## >>> `%do_over2()` macro: <<< ################################################ ## >>> `%do_over2()` macro: <<< <a name="do-over2-macro"></a>################################################
The code of the macro was inspired by The code of the macro was inspired by
*Ted Clay's* and *David Katz's* macro `%do_over()`. *Ted Clay's* and *David Katz's* macro `%do_over()`.
@@ -830,7 +854,7 @@ The `%do_over2()` macro executes like a pure macro code.
### SYNTAX: ################################################################### ### SYNTAX: ###################################################################
The basic syntax is the following, the `<...>` means optional parameters: The basic syntax is the following, the `<...>` means optional parameters:
~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~sas
%do_over2( %do_over2(
arrayI arrayI
,arrayJ ,arrayJ
@@ -862,11 +886,12 @@ The basic syntax is the following, the `<...>` means optional parameters:
function is automatically applied. function is automatically applied.
### EXAMPLES AND USECASES: #################################################### ### EXAMPLES AND USECASES: ####################################################
**EXAMPLE 1.** Looping over two arrays. **EXAMPLE 1.** Looping over two arrays.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
%array(alpha[*] j k l m n, vnames=Y, macarray=Y) %array(alpha[*] j k l m n, vnames=Y, macarray=Y)
%array( beta[4] (101 102 103 104), macarray=Y) %array( beta[4] (101 102 103 104), macarray=Y)
@@ -878,7 +903,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
**EXAMPLE 2.** Looping over two arrays with a separator. **EXAMPLE 2.** Looping over two arrays with a separator.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
%array(alpha[11] (5:15), macarray=Y) %array(alpha[11] (5:15), macarray=Y)
%array( beta[ 4] (101 102 103 104), macarray=Y) %array( beta[ 4] (101 102 103 104), macarray=Y)
@@ -893,7 +918,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
**EXAMPLE 3.** Looping over two arrays with *macroquoted* separator. **EXAMPLE 3.** Looping over two arrays with *macroquoted* separator.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
%array(alpha[11] (5:15), macarray=Y) %array(alpha[11] (5:15), macarray=Y)
%array( beta[ 4] (101 102 103 104), macarray=Y) %array( beta[ 4] (101 102 103 104), macarray=Y)
@@ -904,9 +929,10 @@ The basic syntax is the following, the `<...>` means optional parameters:
%put &=x.; %put &=x.;
%put %sysevalf(&x.); %put %sysevalf(&x.);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---
## >>> `%do_over3()` macro: <<< ################################################ ## >>> `%do_over3()` macro: <<< <a name="do-over3-macro"></a>################################################
The code of the macro was inspired by The code of the macro was inspired by
*Ted Clay's* and *David Katz's* macro `%do_over()`. *Ted Clay's* and *David Katz's* macro `%do_over()`.
@@ -919,7 +945,7 @@ The `%do_over3()` macro executes like a pure macro code.
### SYNTAX: ################################################################### ### SYNTAX: ###################################################################
The basic syntax is the following, the `<...>` means optional parameters: The basic syntax is the following, the `<...>` means optional parameters:
~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~sas
%do_over2( %do_over2(
arrayI arrayI
,arrayJ ,arrayJ
@@ -960,7 +986,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
**EXAMPLE 1.** Looping over 3 macroarrays. **EXAMPLE 1.** Looping over 3 macroarrays.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
%array(a1_[2] (0 1), macarray=Y) %array(a1_[2] (0 1), macarray=Y)
%array(a2_[2] (2 3), macarray=Y) %array(a2_[2] (2 3), macarray=Y)
%array(a3_[2] (4 5), macarray=Y) %array(a3_[2] (4 5), macarray=Y)
@@ -972,16 +998,17 @@ The basic syntax is the following, the `<...>` means optional parameters:
**EXAMPLE 2.** Looping 3 times over a macroarray. **EXAMPLE 2.** Looping 3 times over a macroarray.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
%array(a[0:2] (0 1 2), macarray=Y) %array(a[0:2] (0 1 2), macarray=Y)
%do_over3(a, a, a %do_over3(a, a, a
, phrase = %NRSTR(%put (%a(&_I_.), %a(&_J_), %a(&_K_));) , phrase = %NRSTR(%put (%a(&_I_.), %a(&_J_), %a(&_K_));)
) )
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---
## >>> `%make_do_over()` macro: <<< ########################################### ## >>> `%make_do_over()` macro: <<< <a name="make-do-over-macro"></a> ###########################################
The code of the macro was inspired by The code of the macro was inspired by
*Ted Clay's* and *David Katz's* macro `%do_over()`. *Ted Clay's* and *David Katz's* macro `%do_over()`.
@@ -994,7 +1021,7 @@ The `%make_do_over()` macro does *not* executes like a pure macro code.
### SYNTAX: ################################################################### ### SYNTAX: ###################################################################
The basic syntax is the following, the `<...>` means optional parameters: The basic syntax is the following, the `<...>` means optional parameters:
~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~sas
%make_do_over( %make_do_over(
size size
) )
@@ -1011,7 +1038,7 @@ size - Required, indicates the number of dimensions
**EXAMPLE 1.** Code of created "4-loop" %DO_OVER4() macro **EXAMPLE 1.** Code of created "4-loop" %DO_OVER4() macro
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
%macro do_over4( %macro do_over4(
arrayI1, arrayI1,
arrayI2, arrayI2,
@@ -1047,7 +1074,7 @@ size - Required, indicates the number of dimensions
**EXAMPLE 3.** Create a 4-loop `%DO_OVER4()` macro **EXAMPLE 3.** Create a 4-loop `%DO_OVER4()` macro
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
%make_do_over(4); %make_do_over(4);
%array(a1_[2] (0 1), macarray=Y) %array(a1_[2] (0 1), macarray=Y)
@@ -1063,7 +1090,7 @@ size - Required, indicates the number of dimensions
**EXAMPLE 3.** Create a 5-loop `%DO_OVER5()` macro **EXAMPLE 3.** Create a 5-loop `%DO_OVER5()` macro
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
%make_do_over(5); %make_do_over(5);
%array(a1_[2] (0 1), macarray=Y) %array(a1_[2] (0 1), macarray=Y)
@@ -1090,7 +1117,7 @@ size - Required, indicates the number of dimensions
**EXAMPLE 4.** Create all from 6 to 10 "do_overs" **EXAMPLE 4.** Create all from 6 to 10 "do_overs"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
%array(loop[6:10] (6:10), macarray=Y) %array(loop[6:10] (6:10), macarray=Y)
%do_over(loop %do_over(loop
, phrase = %nrstr( , phrase = %nrstr(
@@ -1098,8 +1125,10 @@ size - Required, indicates the number of dimensions
) )
); );
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---
## License #################################################################### ## License ####################################################################
Copyright (c) Bartosz Jablonski, since January 2019 Copyright (c) Bartosz Jablonski, since January 2019
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -1118,4 +1147,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 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 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.

Binary file not shown.