mirror of
https://github.com/yabwon/SAS_PACKAGES.git
synced 2026-01-03 13:20:05 +00:00
macroArray, version 0.5
macroArray, version 0.5 - documentation updated - the do_overs automatically unquote `betwee=` parameter
This commit is contained in:
@@ -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:
|
||||
- `%array()`,
|
||||
@@ -17,7 +32,7 @@ programming level, is provided.
|
||||
If you are working with BIG macroarrays do not
|
||||
forget to verify your session setting for macro
|
||||
memory limits. Run:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
proc options group = macro;
|
||||
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. |
|
||||
|`MVARSIZE=` | specifies the maximum size for a macro variable that is stored in memory. |
|
||||
|
||||
---
|
||||
|
||||
Package contains:
|
||||
1. macro appendarray,
|
||||
2. macro appendcell,
|
||||
3. macro array,
|
||||
4. macro concatarrays,
|
||||
5. macro deletemacarray,
|
||||
6. macro do_over,
|
||||
7. macro do_over2,
|
||||
8. macro do_over3,
|
||||
9. macro make_do_over,
|
||||
1. macro appendarray
|
||||
2. macro appendcell
|
||||
3. macro array
|
||||
4. macro concatarrays
|
||||
5. macro deletemacarray
|
||||
6. macro do_over
|
||||
7. macro do_over2
|
||||
8. macro do_over3
|
||||
9. macro make_do_over
|
||||
|
||||
Required SAS Components:
|
||||
*Base SAS Software*
|
||||
|
||||
*SAS package generated by generatePackage, version 20200911*
|
||||
|
||||
The SHA256 hash digest for package macroArray
|
||||
`69F6CF496F921D0E21F3524FC7FD130B4B8290C1E0B9BB3ABEA212B734EBE8A1`
|
||||
The SHA256 hash digest for package macroArray:
|
||||
`ACE3E9374256826AB1E25C2BBDA6CA4CCFB50137B8ACE6E1F11BCDBE7AE24B09`
|
||||
|
||||
### Content description #######################################################
|
||||
|
||||
## >>> `%appendArray()` macro: <<< ##############################################
|
||||
# Content description ############################################################################################
|
||||
|
||||
## >>> `%appendArray()` macro: <<< <a name="appendarray-macro"></a> ##############################################
|
||||
|
||||
The `%appendArray()` macro is a macrowrapper
|
||||
which allows to concatenate two macroarrays
|
||||
@@ -66,7 +83,7 @@ The `%appendArray()` macro executes like a pure macro code.
|
||||
### SYNTAX: ###################################################################
|
||||
|
||||
The basic syntax is the following, the `<...>` means optional parameters:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%appendArray(
|
||||
first
|
||||
,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.
|
||||
|
||||
|
||||
|
||||
### EXAMPLES AND USECASES: ####################################################
|
||||
|
||||
**EXAMPLE 1.** Append macroarrays LL and MM.
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%array(ll[2:4] $ 12,
|
||||
function = quote(put(today() + 10*_I_, yymmdd10.)),
|
||||
macarray=Y
|
||||
@@ -104,15 +122,16 @@ The basic syntax is the following, the `<...>` means optional parameters:
|
||||
|
||||
**EXAMPLE 2.** Error handling.
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%appendArray(ll, )
|
||||
%appendArray(, mm)
|
||||
|
||||
%appendArray(noExistA, noExistB)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
---
|
||||
|
||||
|
||||
## >>> `%appendCell()` macro: <<< ###############################################
|
||||
|
||||
## >>> `%appendCell()` macro: <<< <a name="appendcell-macro"></a> ###############################################
|
||||
|
||||
The `%appendCell()` macro allows to append
|
||||
a macrovariable to a macroarray created by the `%array()` macro.
|
||||
@@ -124,7 +143,7 @@ The `%appendCell()` macro executes like a pure macro code.
|
||||
### SYNTAX: ###################################################################
|
||||
|
||||
The basic syntax is the following, the `<...>` means optional parameters:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%appendCell(
|
||||
first
|
||||
,second
|
||||
@@ -147,7 +166,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
|
||||
|
||||
**EXAMPLE 1.** Create two macro wrappers.
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%* Macro wrapper to append a macrovariable to the end of a macroarray;
|
||||
%macro appendHC(array,cell);
|
||||
%appendCell(&array.,&cell.,H)
|
||||
@@ -180,7 +199,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
|
||||
|
||||
|
||||
**EXAMPLE 2.** Error handling
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%appendCell(X,Y,blahblah)
|
||||
|
||||
%appendCell(X,,H)
|
||||
@@ -188,7 +207,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
**EXAMPLE 3.** Adding variable below lower bound.
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%array(zero[0:2] $ ("AAA", "BBB", "CCC"), macarray=Y)
|
||||
%let belowzero=zzz;
|
||||
|
||||
@@ -196,9 +215,10 @@ The basic syntax is the following, the `<...>` means optional parameters:
|
||||
%appendCell(zero,belowzero,L)
|
||||
%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
|
||||
*Ted Clay's* and *David Katz's* macro `%array()`.
|
||||
@@ -229,7 +249,7 @@ The `%array()` macro executes like a pure macro code.
|
||||
### SYNTAX: ###################################################################
|
||||
|
||||
The basic syntax is the following, the `<...>` means optional parameters:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%array(
|
||||
array
|
||||
<,function=>
|
||||
@@ -302,7 +322,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
|
||||
4) macroarray "AGE" with UNIQUE(|) values of variable "age",
|
||||
|
||||
|
||||
|
||||
|
||||
### EXAMPLES AND USECASES: ####################################################
|
||||
|
||||
|
||||
@@ -311,7 +331,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
|
||||
values are used by default;
|
||||
different types of brackets are allowed;
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%array(a[*] x1-x5 (1:5))
|
||||
|
||||
%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
|
||||
elements in the array `(Hbound - Lbound + 1)`.
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%array(d[-2:2] $ ("a" "b" "c" "d" "e"))
|
||||
%put &=dLBOUND. &=dHBOUND. &=dN.;
|
||||
%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.
|
||||
As in case of usual arrays it is `_I_`.
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%array(e[-3:3] $, function = "A" )
|
||||
%put &=eLBOUND. &=eHBOUND. &=eN.;
|
||||
%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.
|
||||
If there is need for set-up something *before* or *after*:
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%array(h[10:12]
|
||||
,function = rand('Uniform')
|
||||
,before = call streaminit(123)
|
||||
@@ -381,7 +401,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
|
||||
|
||||
**EXAMPLE 5.** Fibonacci series.
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%array(i[1:10] (10*0)
|
||||
,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;
|
||||
@@ -390,7 +410,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
|
||||
|
||||
**EXAMPLE 6a.** "Uppercas Letters"
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%array(UL[26] $, function = byte(rank("A")+_I_-1) )
|
||||
%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
|
||||
the input mode support (with `I`).
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%array(ll[26] $, function = byte(rank("a")+_I_-1), macarray=Y)
|
||||
%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`
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%array(R R1978-R1982)
|
||||
%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
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%array(_[*] x1-x5 (1:5))
|
||||
%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.
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
data test1;
|
||||
set sashelp.class;
|
||||
%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.
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%array(ds = sashelp.class, vars = height weight age)
|
||||
%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"
|
||||
Currently the only separator in VARS is a space.
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%array(ds = sashelp.class, vars = height#h weight weight|w age|)
|
||||
%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
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%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.)*;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
---
|
||||
|
||||
|
||||
## >>> `%concatArrays()` macro: <<< #############################################
|
||||
## >>> `%concatArrays()` macro: <<< <a name="concatarrays-macro"></a> #############################################
|
||||
|
||||
The `%concatArrays()` macro allows to concatenate
|
||||
two macroarrays created by the `%array()` macro.
|
||||
@@ -561,7 +582,7 @@ The `%concatArrays()` macro executes like a pure macro code.
|
||||
### SYNTAX: ###################################################################
|
||||
|
||||
The basic syntax is the following, the `<...>` means optional parameters:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%concatArrays(
|
||||
first
|
||||
,second
|
||||
@@ -579,11 +600,12 @@ The basic syntax is the following, the `<...>` means optional parameters:
|
||||
the second array is removed.
|
||||
|
||||
|
||||
|
||||
### EXAMPLES AND USECASES: ####################################################
|
||||
|
||||
**EXAMPLE 1.** Concatenate macroarrays LL and MM.
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%array(ll[2:4] $ 12,
|
||||
function = quote(put(today() + 10*_I_, yymmdd10.)),
|
||||
macarray=Y
|
||||
@@ -603,15 +625,16 @@ The basic syntax is the following, the `<...>` means optional parameters:
|
||||
|
||||
**EXAMPLE 2.** Error handling.
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%concatArrays(ll, )
|
||||
%concatArrays(, mm)
|
||||
|
||||
%concatArrays(noExistA, noExistB)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
---
|
||||
|
||||
|
||||
## >>> `%deleteMacArray()` macro: <<< ###########################################
|
||||
## >>> `%deleteMacArray()` macro: <<< <a name="deletemacarray-macro"></a> ###########################################
|
||||
|
||||
The `%deleteMacArray()` macro allows to delete
|
||||
macroarrays created by the `%array()` macro.
|
||||
@@ -621,7 +644,7 @@ The `%deleteMacArray()` macro executes like a pure macro code.
|
||||
### SYNTAX: ###################################################################
|
||||
|
||||
The basic syntax is the following, the `<...>` means optional parameters:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%deleteMacArray(
|
||||
arrs
|
||||
<,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
|
||||
*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: ###################################################################
|
||||
|
||||
The basic syntax is the following, the `<...>` means optional parameters:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%do_over(
|
||||
array
|
||||
<,phrase=%nrstr(%&array(&_I_.))>
|
||||
@@ -692,7 +715,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
|
||||
|
||||
**EXAMPLE 1.** Simple looping.
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%array(beta[*] j k l m (101 102 103 104), vnames=Y, macarray=Y)
|
||||
|
||||
%put #%do_over(beta)#;
|
||||
@@ -709,7 +732,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
|
||||
|
||||
**EXAMPLE 2.** Multiple arrays looping.
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%array(alpha[*] j k l m n, vnames=Y, macarray=Y)
|
||||
%array( beta[5] $ , function = "a", 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.
|
||||
Create multiple datasets.
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%do_over(beta
|
||||
, phrase = %nrstr(
|
||||
data %alpha(&_I_.)2;
|
||||
@@ -744,7 +767,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
|
||||
**EXAMPLE 4.** Multiple arrays looping, cont.
|
||||
Create multiple datasets using a macro.
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%macro doit(ds, var=a, val=1);
|
||||
data &ds.;
|
||||
call streaminit(123);
|
||||
@@ -763,7 +786,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
|
||||
|
||||
**EXAMPLE 5.** `%do_over()` inside `%array()`
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%array(test[*] x1-x12 (1:12), macarray=Y)
|
||||
|
||||
%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.
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%array(alpha[11] (5:15), macarray=Y)
|
||||
|
||||
%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
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%array(test[*] x01-x12, vnames= Y, macarray=Y)
|
||||
|
||||
%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(,))#;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
---
|
||||
|
||||
|
||||
## >>> `%do_over2()` macro: <<< ################################################
|
||||
## >>> `%do_over2()` macro: <<< <a name="do-over2-macro"></a>################################################
|
||||
|
||||
The code of the macro was inspired by
|
||||
*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: ###################################################################
|
||||
|
||||
The basic syntax is the following, the `<...>` means optional parameters:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%do_over2(
|
||||
arrayI
|
||||
,arrayJ
|
||||
@@ -862,11 +886,12 @@ The basic syntax is the following, the `<...>` means optional parameters:
|
||||
function is automatically applied.
|
||||
|
||||
|
||||
|
||||
### EXAMPLES AND USECASES: ####################################################
|
||||
|
||||
**EXAMPLE 1.** Looping over two arrays.
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%array(alpha[*] j k l m n, vnames=Y, 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.
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%array(alpha[11] (5:15), 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.
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%array(alpha[11] (5:15), 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 %sysevalf(&x.);
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
---
|
||||
|
||||
|
||||
## >>> `%do_over3()` macro: <<< ################################################
|
||||
## >>> `%do_over3()` macro: <<< <a name="do-over3-macro"></a>################################################
|
||||
|
||||
The code of the macro was inspired by
|
||||
*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: ###################################################################
|
||||
|
||||
The basic syntax is the following, the `<...>` means optional parameters:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%do_over2(
|
||||
arrayI
|
||||
,arrayJ
|
||||
@@ -960,7 +986,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
|
||||
|
||||
**EXAMPLE 1.** Looping over 3 macroarrays.
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%array(a1_[2] (0 1), macarray=Y)
|
||||
%array(a2_[2] (2 3), 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.
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%array(a[0:2] (0 1 2), macarray=Y)
|
||||
|
||||
%do_over3(a, a, a
|
||||
, 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
|
||||
*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: ###################################################################
|
||||
|
||||
The basic syntax is the following, the `<...>` means optional parameters:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%make_do_over(
|
||||
size
|
||||
)
|
||||
@@ -1011,7 +1038,7 @@ size - Required, indicates the number of dimensions
|
||||
|
||||
**EXAMPLE 1.** Code of created "4-loop" %DO_OVER4() macro
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%macro do_over4(
|
||||
arrayI1,
|
||||
arrayI2,
|
||||
@@ -1047,7 +1074,7 @@ size - Required, indicates the number of dimensions
|
||||
|
||||
**EXAMPLE 3.** Create a 4-loop `%DO_OVER4()` macro
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%make_do_over(4);
|
||||
|
||||
%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
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%make_do_over(5);
|
||||
|
||||
%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"
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.sas}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%array(loop[6:10] (6:10), macarray=Y)
|
||||
%do_over(loop
|
||||
, phrase = %nrstr(
|
||||
@@ -1098,8 +1125,10 @@ size - Required, indicates the number of dimensions
|
||||
)
|
||||
);
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
---
|
||||
|
||||
## License ####################################################################
|
||||
|
||||
Copyright (c) Bartosz Jablonski, since January 2019
|
||||
|
||||
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
|
||||
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.
|
||||
SOFTWARE.
|
||||
Reference in New Issue
Block a user