mirror of
https://github.com/SASPAC/baseplus.git
synced 2025-12-25 04:11:19 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2cad099652 | ||
|
|
bfd3a9d0d9 | ||
|
|
ab7feaa15a | ||
|
|
01b1300a55 | ||
|
|
ce6f6b56ee | ||
|
|
2e1d9df0c3 | ||
|
|
696bceb913 | ||
|
|
0c1e5c7d3a |
@@ -45,10 +45,14 @@ libname NEW "%workPath()/new";
|
||||
%put %translate(%str("A", "B", "C"),%str(%",),%str(%' ));
|
||||
|
||||
%put %tranwrd(Miss Joan Smith,Miss,Ms.);
|
||||
|
||||
%put %date() %time() %datetime();
|
||||
|
||||
%put %monthShift(2023,1,-5);
|
||||
```
|
||||
and more.
|
||||
|
||||
SHA256 digest for the latest version of `BasePlus`: F*2FE68DD9B3692B9D46EF85B82F63C7E65010BF9E89D670FD1779F4670FA03F31
|
||||
SHA256 digest for the latest version of `BasePlus`: F*3407AD8068C7528E129034144F9A44CFDF14B7DC34334C64C2F1D67351D1E01E
|
||||
|
||||
[**Documentation for BasePlus**](./baseplus.md "Documentation for BasePlus")
|
||||
|
||||
|
||||
576
baseplus.md
576
baseplus.md
@@ -52,6 +52,7 @@
|
||||
* [`%bpPIPE()` macro](#bppipe-macro)
|
||||
* [`%dirsAndFiles()` macro](#dirsandfiles-macro)
|
||||
* [`%repeatTxt()` macro](#repeattxt-macro)
|
||||
* [`%repList()` macro](#replist-macro)
|
||||
* [`%intsList()` macro](#intslist-macro)
|
||||
* [`%letters()` macro](#letters-macro)
|
||||
* [`%splitDSIntoBlocks()` macro](#splitdsintoblocks-macro)
|
||||
@@ -59,6 +60,11 @@
|
||||
* [`%filePath()` macro](#filepath-macro)
|
||||
* [`%libPath()` macro](#libpath-macro)
|
||||
* [`%workPath()` macro](#workpath-macro)
|
||||
* [`%date()` macro](#date-macro)
|
||||
* [`%today()` macro](#today-macro)
|
||||
* [`%time()` macro](#time-macro)
|
||||
* [`%datetime()` macro](#datetime-macro)
|
||||
* [`%monthShift()` macro](#monthshift-macro)
|
||||
* [`%translate()` macro](#translate-macro)
|
||||
* [`%tranwrd()` macro](#tranwrd-macro)
|
||||
* [`%findDSwithVarVal()` macro](#finddswithvarval-macro)
|
||||
@@ -72,7 +78,7 @@
|
||||
|
||||
---
|
||||
|
||||
# The BasePlus package [ver. 1.29.1] <a name="baseplus-package"></a> ###############################################
|
||||
# The BasePlus package [ver. 1.32.0] <a name="baseplus-package"></a> ###############################################
|
||||
|
||||
The **BasePlus** package implements useful
|
||||
functions and functionalities I miss in the BASE SAS.
|
||||
@@ -80,6 +86,7 @@ functions and functionalities I miss in the BASE SAS.
|
||||
It is inspired by various people, e.g.
|
||||
- at the SAS-L discussion list
|
||||
- at the communities.sas.com (SASware Ballot Ideas)
|
||||
- at StackOverflow
|
||||
- at the Office...
|
||||
- etc.
|
||||
|
||||
@@ -95,8 +102,6 @@ Kudos to all who inspired me to generate this package:
|
||||
*Kurt Bremser*,
|
||||
*Leonid Batkhan*.
|
||||
|
||||
Recording from the SAS Explore 2022 conference: [A BasePlus Package for SAS](https://communities.sas.com/t5/SAS-Explore-Presentations/A-BasePlus-Package-for-SAS/ta-p/838246 "A BasePlus Package for SAS") (September 27th-29th, 2022).
|
||||
|
||||
---
|
||||
|
||||
### BASIC EXAMPLES AND USECASES: ####################################################
|
||||
@@ -309,75 +314,121 @@ run;
|
||||
run;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
**EXAMPLE 22** Repeating texts and lists:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
options mprint;
|
||||
|
||||
data work.A;
|
||||
x=17;
|
||||
data work.B;
|
||||
x=42;
|
||||
data work.C;
|
||||
x=303;
|
||||
run;
|
||||
|
||||
data work.test5;
|
||||
set
|
||||
%repeatTxt(work.A work.B work.C, 5)
|
||||
;
|
||||
run;
|
||||
|
||||
|
||||
data Times2_A3B4C5;
|
||||
set
|
||||
%repList(work.A work.B work.C, times = 2, each = 3 4 5)
|
||||
;
|
||||
run;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
**EXAMPLE 23** Date and time one-liners:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%put %today() %date() %time() %datetime();
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
**EXAMPLE 24** Months shifting:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%put
|
||||
Past: %monthShift(2023, 1, -1)
|
||||
Current: %monthShift(2023, 1 )
|
||||
Future: %monthShift(2023, 1, +1)
|
||||
;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
---
|
||||
|
||||
Package contains:
|
||||
1. macro bppipe
|
||||
2. macro deduplistc
|
||||
3. macro deduplistp
|
||||
4. macro deduplists
|
||||
5. macro deduplistx
|
||||
6. macro dirsandfiles
|
||||
7. macro functionexists
|
||||
8. macro getvars
|
||||
9. macro intslist
|
||||
10. macro ldsn
|
||||
11. macro ldsnm
|
||||
12. macro lvarnm
|
||||
13. macro lvarnmlab
|
||||
14. macro qdeduplistx
|
||||
15. macro qgetvars
|
||||
16. macro qzipevalf
|
||||
17. macro raincloudplot
|
||||
18. macro repeattxt
|
||||
19. macro splitdsintoblocks
|
||||
20. macro splitdsintoparts
|
||||
21. macro symdelglobal
|
||||
22. macro unziplibrary
|
||||
23. macro zipevalf
|
||||
24. macro ziplibrary
|
||||
25. format bool
|
||||
26. format boolz
|
||||
27. format ceil
|
||||
28. format floor
|
||||
29. format int
|
||||
30. functions arrfill
|
||||
31. functions arrfillc
|
||||
32. functions arrmissfill
|
||||
33. functions arrmissfillc
|
||||
34. functions arrmisstoleft
|
||||
35. functions arrmisstoleftc
|
||||
36. functions arrmisstoright
|
||||
37. functions arrmisstorightc
|
||||
38. functions bracketsc
|
||||
39. functions bracketsn
|
||||
40. functions catxfc
|
||||
41. functions catxfi
|
||||
42. functions catxfj
|
||||
43. functions catxfn
|
||||
44. functions deldataset
|
||||
45. functions semicolonc
|
||||
46. functions semicolonn
|
||||
47. format brackets
|
||||
48. format semicolon
|
||||
49. proto qsortincbyprocproto
|
||||
50. functions frommissingtonumberbs
|
||||
51. functions fromnumbertomissing
|
||||
52. functions quicksort4notmiss
|
||||
53. functions quicksorthash
|
||||
54. functions quicksorthashsddv
|
||||
55. functions quicksortlight
|
||||
56. macro filepath
|
||||
57. macro finddswithvarval
|
||||
58. macro fmt
|
||||
59. macro gettitle
|
||||
60. macro infmt
|
||||
61. macro letters
|
||||
62. macro libpath
|
||||
63. macro minclude
|
||||
64. macro translate
|
||||
65. macro tranwrd
|
||||
66. macro workpath
|
||||
1. macro bppipe
|
||||
2. macro deduplistc
|
||||
3. macro deduplistp
|
||||
4. macro deduplists
|
||||
5. macro deduplistx
|
||||
6. macro dirsandfiles
|
||||
7. macro functionexists
|
||||
8. macro getvars
|
||||
9. macro intslist
|
||||
10. macro ldsn
|
||||
11. macro ldsnm
|
||||
12. macro lvarnm
|
||||
13. macro lvarnmlab
|
||||
14. macro qdeduplistx
|
||||
15. macro qgetvars
|
||||
16. macro qzipevalf
|
||||
17. macro raincloudplot
|
||||
18. macro repeattxt
|
||||
19. macro splitdsintoblocks
|
||||
20. macro splitdsintoparts
|
||||
21. macro symdelglobal
|
||||
22. macro unziplibrary
|
||||
23. macro zipevalf
|
||||
24. macro ziplibrary
|
||||
25. format bool
|
||||
26. format boolz
|
||||
27. format ceil
|
||||
28. format floor
|
||||
29. format int
|
||||
30. function arrfill
|
||||
31. function arrfillc
|
||||
32. function arrmissfill
|
||||
33. function arrmissfillc
|
||||
34. function arrmisstoleft
|
||||
35. function arrmisstoleftc
|
||||
36. function arrmisstoright
|
||||
37. function arrmisstorightc
|
||||
38. function bracketsc
|
||||
39. function bracketsn
|
||||
40. function catxfc
|
||||
41. function catxfi
|
||||
42. function catxfj
|
||||
43. function catxfn
|
||||
44. function deldataset
|
||||
45. function semicolonc
|
||||
46. function semicolonn
|
||||
47. format brackets
|
||||
48. format semicolon
|
||||
49. proto qsortincbyprocproto
|
||||
50. function frommissingtonumberbs
|
||||
51. function fromnumbertomissing
|
||||
52. function quicksort4notmiss
|
||||
53. function quicksorthash
|
||||
54. function quicksorthashsddv
|
||||
55. function quicksortlight
|
||||
56. macro date
|
||||
57. macro datetime
|
||||
58. macro filepath
|
||||
59. macro finddswithvarval
|
||||
60. macro fmt
|
||||
61. macro gettitle
|
||||
62. macro infmt
|
||||
63. macro letters
|
||||
64. macro libpath
|
||||
65. macro minclude
|
||||
66. macro monthshift
|
||||
67. macro replist
|
||||
68. macro time
|
||||
69. macro today
|
||||
70. macro translate
|
||||
71. macro tranwrd
|
||||
72. macro workpath
|
||||
|
||||
|
||||
|
||||
@@ -385,10 +436,10 @@ Package contains additional content, run: %loadPackageAddCnt(BasePlus) to load
|
||||
or look for the baseplus_AdditionalContent directory in the Packages fileref
|
||||
localization (only if additional content was deployed during the installation process).
|
||||
|
||||
* SAS package generated by generatePackage, version 20230905 *
|
||||
* SAS package generated by generatePackage, version 20231024 *
|
||||
|
||||
The SHA256 hash digest for package BasePlus:
|
||||
`F*2FE68DD9B3692B9D46EF85B82F63C7E65010BF9E89D670FD1779F4670FA03F31`
|
||||
`F*3407AD8068C7528E129034144F9A44CFDF14B7DC34334C64C2F1D67351D1E01E`
|
||||
|
||||
---
|
||||
# Content description ############################################################################################
|
||||
@@ -4399,6 +4450,118 @@ run;
|
||||
|
||||
---
|
||||
|
||||
## >>> `%repList()` macro: <<< <a name="replist-macro"></a> #######################
|
||||
|
||||
The repList() macro function allows to repeat `T`
|
||||
times elements of a `L` list, possibly `E` times each element,
|
||||
separated by string `S`.
|
||||
|
||||
See examples below for the details.
|
||||
|
||||
The `%repList()` macro executes like a pure macro code.
|
||||
|
||||
### SYNTAX: ###################################################################
|
||||
|
||||
The basic syntax is the following, the `<...>` means optional parameters:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%repList(
|
||||
list
|
||||
<,times=>
|
||||
<,each=>
|
||||
<,lenghtOut=>
|
||||
<,sep=>
|
||||
)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
**Arguments description**:
|
||||
|
||||
1. `list` - *Required*, a list of elements to be repeated.
|
||||
List can be space or comma separated.
|
||||
Elements can be in quotes.
|
||||
For comma separated list add brackets
|
||||
e.g., `%repList((A,B,C,D),times=5)`.
|
||||
The list separators are: `<{[( ,;)]}>`.
|
||||
|
||||
* `times=` - *Optional*, An integer indicating
|
||||
the number of repetitions.
|
||||
By default set to `1`.
|
||||
|
||||
|
||||
* `each=` - *Optional*, A list of integers indicating
|
||||
the number of repetitions of each element of the list
|
||||
e.g., for a list `A B C` and the `each=2 4` the result
|
||||
is `A A B B B B C C`. If the number of integers is less
|
||||
then the length of the list values are recycled from
|
||||
the beginning.
|
||||
By default set to `1`.
|
||||
|
||||
* `lenghtOut=` - *Optional*, An integer indicating
|
||||
after what the number of repetitions process will stop.
|
||||
By default set to `0` which means "do not stop".
|
||||
|
||||
* `sep=` - *Optional*, it is a separator printed between
|
||||
repeated elements. Mnemonics for *space* is `s`,
|
||||
for *comma* is `c`, and for semicolon in `q`.
|
||||
Default value is a single space.
|
||||
|
||||
|
||||
### EXAMPLES AND USECASES: ####################################################
|
||||
|
||||
**EXAMPLE 1.** Simple repetition of all elements:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%put %repList((A,B,C,D), times=3);
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
**EXAMPLE 2.** Simple repetition of each element:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%put %repList(("A",'B',"C",'D'), each=3);
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
**EXAMPLE 3.** Simple repetition with a separator:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%put %repList(A10;B20;C30, times=3, each=2, sep=Q);
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
**EXAMPLE 4.** Recycle elements up to 8 with a comma as a separator:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%put %repList(1 2 3, lenghtOut=8, sep=c);
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
**EXAMPLE 5.** Separate number of repetitions for each element:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%put [%repList([D][C][B][A], each = 2 3 5 7, sep=] [)];
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
**EXAMPLE 6.** "ASCII art" butterflies:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%put {>%repList(! $ |, times = 2, each =2 1, sep=<} ... {>)<};
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
**EXAMPLE 7.** Data repeating:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
data A;
|
||||
x=17;
|
||||
data B;
|
||||
x=42;
|
||||
data C;
|
||||
x=303;
|
||||
run;
|
||||
|
||||
data Times2_A10B11C12;
|
||||
set
|
||||
%repList(A B C, times = 2, each =10 11 12)
|
||||
;
|
||||
run;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
---
|
||||
|
||||
|
||||
## >>> `%intsList()` macro: <<< <a name="intslist-macro"></a> #######################
|
||||
|
||||
The intsList() macro function allows to print a list of
|
||||
@@ -4828,6 +4991,277 @@ The basic syntax is the following, the `<...>` means optional parameters:
|
||||
|
||||
---
|
||||
|
||||
## >>> `%date()` macro: <<< <a name="date-macro"></a> #######################
|
||||
|
||||
The date() macro function is a "lazy typer" wrapping up `%sysfunc(date())`.
|
||||
|
||||
See examples below for the details.
|
||||
|
||||
The `%date()` macro executes like a pure macro code.
|
||||
|
||||
### SYNTAX: ###################################################################
|
||||
|
||||
The basic syntax is the following, the `<...>` means optional parameters:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%date()
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
**Arguments description**:
|
||||
|
||||
No arguments.
|
||||
|
||||
---
|
||||
|
||||
|
||||
### EXAMPLES AND USECASES: ####################################################
|
||||
|
||||
**EXAMPLE 1.** Get value of `date()`:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%put %date();
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
---
|
||||
|
||||
|
||||
## >>> `%today()` macro: <<< <a name="today-macro"></a> #######################
|
||||
|
||||
The today() macro function is a "lazy typer" wrapping up `%sysfunc(today())`.
|
||||
|
||||
See examples below for the details.
|
||||
|
||||
The `%today()` macro executes like a pure macro code.
|
||||
|
||||
### SYNTAX: ###################################################################
|
||||
|
||||
The basic syntax is the following, the `<...>` means optional parameters:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%today()
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
**Arguments description**:
|
||||
|
||||
No arguments.
|
||||
|
||||
---
|
||||
|
||||
|
||||
### EXAMPLES AND USECASES: ####################################################
|
||||
|
||||
**EXAMPLE 1.** Get value of `today()`:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%put %today();
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
---
|
||||
|
||||
|
||||
## >>> `%time()` macro: <<< <a name="time-macro"></a> #######################
|
||||
|
||||
The time() macro function is a "lazy typer" wrapping up `%sysfunc(time())`.
|
||||
|
||||
See examples below for the details.
|
||||
|
||||
The `%time()` macro executes like a pure macro code.
|
||||
|
||||
### SYNTAX: ###################################################################
|
||||
|
||||
The basic syntax is the following, the `<...>` means optional parameters:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%time()
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
**Arguments description**:
|
||||
|
||||
No arguments.
|
||||
|
||||
---
|
||||
|
||||
|
||||
### EXAMPLES AND USECASES: ####################################################
|
||||
|
||||
**EXAMPLE 1.** Get value of `time()`:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%put %time();
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
---
|
||||
|
||||
|
||||
## >>> `%datetime()` macro: <<< <a name="datetime-macro"></a> #######################
|
||||
|
||||
The datetime() macro function is a "lazy typer" wrapping up `%sysfunc(datetime())`.
|
||||
|
||||
See examples below for the details.
|
||||
|
||||
The `%datetime()` macro executes like a pure macro code.
|
||||
|
||||
### SYNTAX: ###################################################################
|
||||
|
||||
The basic syntax is the following, the `<...>` means optional parameters:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%datetime()
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
**Arguments description**:
|
||||
|
||||
No arguments.
|
||||
|
||||
---
|
||||
|
||||
|
||||
### EXAMPLES AND USECASES: ####################################################
|
||||
|
||||
**EXAMPLE 1.** Get value of `datetime()`:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%put %datetime();
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
---
|
||||
|
||||
## >>> `%monthShift()` macro: <<< <a name="monthshift-macro"></a> #######################
|
||||
|
||||
The monthShift() macro is a utility macro
|
||||
which allows to shift "year-month" period by
|
||||
a given number of "periods" (months).
|
||||
|
||||
The result is in the `YYYYMM` format but can be altered.
|
||||
|
||||
See examples below for the details.
|
||||
|
||||
The `%monthShift()` macro executes like a pure macro code.
|
||||
|
||||
### SYNTAX: ###################################################################
|
||||
|
||||
The basic syntax is the following, the `<...>` means optional parameters:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%monthShift(
|
||||
< Y>
|
||||
<,M>
|
||||
<,shift>
|
||||
<,ofmt=>
|
||||
)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
**Arguments description**:
|
||||
|
||||
1. `Y` - *Optional*, a year from which counting starts.
|
||||
If null the value is set to *system year*.
|
||||
|
||||
2. `M` - *Optional*, a month from which counting starts.
|
||||
If null the value is set to `1`. Can be a number
|
||||
(`1` to `12`) or a name (`June`, `OCTOBER`) or
|
||||
a three letters short (`JAN`, `apr`).
|
||||
|
||||
3. `shift` - *Optional*, number of periods to shift.
|
||||
If null the value is set to `0`.
|
||||
Positive value shifts to the "future",
|
||||
negative value shifts to the "past",
|
||||
Can be an expression (e.g. `1+2*3`, see examples).
|
||||
|
||||
* `ofmt=YYMMn6.` - *Optional*, it is a format name used to
|
||||
display the result. Default value is `YYMMn6.`
|
||||
See examples.
|
||||
|
||||
---
|
||||
|
||||
### EXAMPLES AND USECASES: ####################################################
|
||||
|
||||
**EXAMPLE 1.** Shift one up and one down:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%put
|
||||
Past: %monthShift(2023, 1, -1)
|
||||
Current: %monthShift(2023, 1 )
|
||||
Future: %monthShift(2023, 1, +1)
|
||||
;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
**EXAMPLE 2.** Shift by expression:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%let n = 2;
|
||||
%put
|
||||
%monthShift(2023, 1, +1 + &n.*3)
|
||||
;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
**EXAMPLE 3.** Shift with default values:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%put %monthShift();
|
||||
%put %monthShift(2023);
|
||||
%put %monthShift(2023,Jan);
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
**EXAMPLE 4.** Shift with months names:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%put
|
||||
%monthShift(2023,Jan,-1)
|
||||
%monthShift(2023,Feb,-2)
|
||||
%monthShift(2023,Mar,-3)
|
||||
%monthShift(2023,Apr,-4)
|
||||
%monthShift(2023,May,-5)
|
||||
%monthShift(2023,Jun,-6)
|
||||
%monthShift(2023,Jul,-7)
|
||||
%monthShift(2023,Aug,-8)
|
||||
%monthShift(2023,Sep,-9)
|
||||
%monthShift(2023,Oct,-10)
|
||||
%monthShift(2023,Nov,-11)
|
||||
%monthShift(2023,Dec,-12)
|
||||
;
|
||||
|
||||
%put
|
||||
%monthShift(2023,January,12)
|
||||
%monthShift(2023,February,11)
|
||||
%monthShift(2023,March,10)
|
||||
%monthShift(2023,April,9)
|
||||
%monthShift(2023,May,8)
|
||||
%monthShift(2023,June,7)
|
||||
%monthShift(2023,July,6)
|
||||
%monthShift(2023,August,5)
|
||||
%monthShift(2023,September,4)
|
||||
%monthShift(2023,October,3)
|
||||
%monthShift(2023,November,2)
|
||||
%monthShift(2023,December,1)
|
||||
;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
**EXAMPLE 5.** Play with formatting:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%put
|
||||
%monthShift(2023, 1, +1 )
|
||||
%monthShift(2023, 1, +1, ofmt=yymm7. )
|
||||
%monthShift(2023, 1, +1, ofmt=yymmd7.)
|
||||
%monthShift(2023, 1, +1, ofmt=yymms7.)
|
||||
;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
**EXAMPLE 6.** Read monthly data with `noDSNFERR` option:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
data
|
||||
A202210 A202211 A202212
|
||||
A202301 A202302 A202303
|
||||
A202304 A202305 A202306
|
||||
A202307 A202308 A202309
|
||||
;
|
||||
set sashelp.class;
|
||||
run;
|
||||
|
||||
|
||||
options noDSNFERR;
|
||||
data ALL;
|
||||
set
|
||||
A%monthShift(2023, 9, -12) - A%monthShift(2023, 9)
|
||||
;
|
||||
run;
|
||||
options DSNFERR;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
---
|
||||
|
||||
|
||||
## >>> `%translate()` macro: <<< <a name="translate-macro"></a> #######################
|
||||
|
||||
The translate() macro function allows to replace bytes with bytes in text string.
|
||||
|
||||
BIN
baseplus.zip
BIN
baseplus.zip
Binary file not shown.
5640
hist/1.30.0/baseplus.md
Normal file
5640
hist/1.30.0/baseplus.md
Normal file
File diff suppressed because it is too large
Load Diff
BIN
hist/1.30.0/baseplus.zip
Normal file
BIN
hist/1.30.0/baseplus.zip
Normal file
Binary file not shown.
5778
hist/1.31.0/baseplus.md
Normal file
5778
hist/1.31.0/baseplus.md
Normal file
File diff suppressed because it is too large
Load Diff
BIN
hist/1.31.0/baseplus.zip
Normal file
BIN
hist/1.31.0/baseplus.zip
Normal file
Binary file not shown.
5932
hist/1.32.0/baseplus.md
Normal file
5932
hist/1.32.0/baseplus.md
Normal file
File diff suppressed because it is too large
Load Diff
BIN
hist/1.32.0/baseplus.zip
Normal file
BIN
hist/1.32.0/baseplus.zip
Normal file
Binary file not shown.
Reference in New Issue
Block a user