mirror of
https://github.com/SASPAC/baseplus.git
synced 2025-12-24 11:51:19 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
696bceb913 | ||
|
|
0c1e5c7d3a | ||
|
|
8b4b5e721d | ||
|
|
b37f716731 | ||
|
|
e81063f308 | ||
|
|
86c8c164d1 | ||
|
|
ba6870777f | ||
|
|
779aa6d8e2 | ||
|
|
23b9d1530d |
@@ -48,7 +48,7 @@ libname NEW "%workPath()/new";
|
||||
```
|
||||
and more.
|
||||
|
||||
SHA256 digest for the latest version of `BasePlus`: F*B3CACDA32A5E70940E667DCA859483BD76DB082D19BAF326F28A580226DDD962
|
||||
SHA256 digest for the latest version of `BasePlus`: F*B91771D45C781B6806DBB44A3B491A0784D7698B9F3BBBE1A86EE5594834315F
|
||||
|
||||
[**Documentation for BasePlus**](./baseplus.md "Documentation for BasePlus")
|
||||
|
||||
|
||||
635
baseplus.md
635
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)
|
||||
@@ -62,15 +63,17 @@
|
||||
* [`%translate()` macro](#translate-macro)
|
||||
* [`%tranwrd()` macro](#tranwrd-macro)
|
||||
* [`%findDSwithVarVal()` macro](#finddswithvarval-macro)
|
||||
* [`%getTitle()` macro](#gettitle-macro)
|
||||
|
||||
* [`%getTitle()` macro](#gettitle-macro)
|
||||
* [`%mInclude()` macro](#minclude-macro)
|
||||
* [`%fmt()` macro](#fmt-macro)
|
||||
* [`%infmt()` macro](#infmt-macro)
|
||||
|
||||
|
||||
* [License](#license)
|
||||
|
||||
---
|
||||
|
||||
# The BasePlus package [ver. 1.26.0] <a name="baseplus-package"></a> ###############################################
|
||||
# The BasePlus package [ver. 1.30.0] <a name="baseplus-package"></a> ###############################################
|
||||
|
||||
The **BasePlus** package implements useful
|
||||
functions and functionalities I miss in the BASE SAS.
|
||||
@@ -90,7 +93,8 @@ Kudos to all who inspired me to generate this package:
|
||||
*Anamaria Calai*,
|
||||
*Michal Ludwicki*,
|
||||
*Quentin McMullen*,
|
||||
*Kurt Bremser*.
|
||||
*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).
|
||||
|
||||
@@ -281,82 +285,140 @@ run;
|
||||
%put %GetTitle(1 2 3 5, dlm=s, qt='') ;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
**EXAMPLE 20** Format and informat macro variables values:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%put %fmt(12345, date9.) %fmt(12345, yymmdd10.);
|
||||
|
||||
%put %infmt($111234, dollar10.2);
|
||||
%put %infmt($111.234, dollar10.2);
|
||||
|
||||
%let text = ##%fmt(ABC, $char9., -C)##;
|
||||
%put &text.;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
**EXAMPLE 21** "Macro including" a text file:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
filename f "%workpath()/testFile1.txt";
|
||||
data _null_;
|
||||
file f;
|
||||
put "13 14 15";
|
||||
run;
|
||||
|
||||
data testDataset;
|
||||
set sashelp.class;
|
||||
where age in ( %mInclude(f) );
|
||||
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;
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
---
|
||||
|
||||
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 gettitle
|
||||
59. macro letters
|
||||
60. macro libpath
|
||||
61. macro translate
|
||||
62. macro tranwrd
|
||||
63. 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. 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 replist
|
||||
65. macro translate
|
||||
66. macro tranwrd
|
||||
67. macro workpath
|
||||
|
||||
|
||||
|
||||
|
||||
Package contains additional content, run: %loadPackageAddCnt(BasePlus) to load it
|
||||
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 20230520 *
|
||||
* SAS package generated by generatePackage, version 20230905 *
|
||||
|
||||
The SHA256 hash digest for package BasePlus:
|
||||
`F*B3CACDA32A5E70940E667DCA859483BD76DB082D19BAF326F28A580226DDD962`
|
||||
`F*B91771D45C781B6806DBB44A3B491A0784D7698B9F3BBBE1A86EE5594834315F`
|
||||
|
||||
---
|
||||
# Content description ############################################################################################
|
||||
@@ -3135,6 +3197,7 @@ The basic syntax is the following, the `<...>` means optional parameters:
|
||||
<,y2axis=>
|
||||
<,y2axisLevels=>
|
||||
<,y2axisValueAttrs=>
|
||||
<,catAxisValueAttrs=>
|
||||
<,xaxisValueAttrs=>
|
||||
<,xaxisTickstyle=>
|
||||
<,sganno=>
|
||||
@@ -3245,6 +3308,9 @@ The basic syntax is the following, the `<...>` means optional parameters:
|
||||
* `y2axisValueAttrs` - *Optional*, default value `Color=Grey`.
|
||||
Allows to modify Y2 axis values attributes.
|
||||
|
||||
* `catAxisValueAttrs` - *Optional*, default value `Color=Black`.
|
||||
Allows to modify category (Y) axis values attributes.
|
||||
|
||||
* `xaxisValueAttrs` - *Optional*, default value `Color=Grey`.
|
||||
Allows to modify X axis values attributes.
|
||||
|
||||
@@ -3447,6 +3513,7 @@ The output:
|
||||
, sgPlotOptions=noborder
|
||||
, WidthPX=1000
|
||||
, HeightPX=320
|
||||
, catAxisValueAttrs=Color=Green weight=bold
|
||||
)
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
@@ -4362,6 +4429,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
|
||||
@@ -5110,6 +5289,324 @@ The basic syntax is the following, the `<...>` means optional parameters:
|
||||
|
||||
---
|
||||
|
||||
## >>> `%mInclude()` macro: <<< <a name="minclude-macro"></a> #######################
|
||||
|
||||
The mInclude() macro is a macrolanguage version of the SAS `%include` statement.
|
||||
But it allows for "embedding any code anywhere into SAS programs".
|
||||
|
||||
Macro was inspired by *Leonid Batkhan* and his blog post:
|
||||
|
||||
"Embedding any code anywhere into SAS programs" from May 30, 2023.
|
||||
|
||||
Link: `https://blogs.sas.com/content/sgf/2023/05/30/embedding-any-code-anywhere-into-sas-programs/`
|
||||
|
||||
The implementation presented, in contrary to inspiration source, is
|
||||
based on the `doSubL()` function and a list of global
|
||||
macrovariables of the form `______<N>` (six underscores and a number).
|
||||
|
||||
See examples below for the details.
|
||||
|
||||
The `%mInclude()` macro executes like a pure macro code.
|
||||
|
||||
### SYNTAX: ###################################################################
|
||||
|
||||
The basic syntax is the following, the `<...>` means optional parameters:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%mInclude(
|
||||
< f>
|
||||
<,source=>
|
||||
<,lrecl=>
|
||||
<,symdel=>
|
||||
)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
**Arguments description**:
|
||||
|
||||
1. `f` - *Required*, a SAS `fileref` or a **quoted** path
|
||||
to the included file.
|
||||
|
||||
*. `source=0` - *Optional*, default value is `0`.
|
||||
Set to `1` if the source should be printed in the log.
|
||||
|
||||
*. `lrecl=32767` - *Optional*, default value is `32767`.
|
||||
Sets the `lrecl` value for the file width.
|
||||
|
||||
*. `symdel=1` - *Optional*, default value is `1`.
|
||||
Indicates if the global macrovariables
|
||||
`______1` to `______N` should be deleted
|
||||
when the macro ends.
|
||||
|
||||
---
|
||||
|
||||
### EXAMPLES AND USECASES: ####################################################
|
||||
|
||||
**EXAMPLE 1.** Embedding text in statements (the `%include` won't work here):
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
resetline;
|
||||
filename f "%workpath()/testFile1.txt";
|
||||
filename f list;
|
||||
|
||||
data _null_;
|
||||
file f;
|
||||
put "13 14 15";
|
||||
run;
|
||||
|
||||
resetline;
|
||||
data testDataset;
|
||||
set sashelp.class;
|
||||
where age in ( %mInclude(f) );
|
||||
run;
|
||||
|
||||
data testDataset2;
|
||||
set sashelp.class;
|
||||
where age in ( %mInclude(f,source=1) );
|
||||
run;
|
||||
|
||||
filename f clear;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
**EXAMPLE 2.** Embedding with direct path (mind those quotes!):
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
resetline;
|
||||
filename f "%workpath()/testFile2.txt";
|
||||
filename f list;
|
||||
|
||||
%let someGlobalMacroVariable=17;
|
||||
|
||||
data _null_;
|
||||
file f;
|
||||
put "options mprint;";
|
||||
do i=1 to 3;
|
||||
put "data y; x = " i "; run;";
|
||||
put '%macro A' i +(-1) '(); %put ' i ' ** &someGlobalMacroVariable.; %mend; %A' i +(-1) '()';
|
||||
end;
|
||||
put "options nomprint;";
|
||||
run;
|
||||
|
||||
resetline;
|
||||
%mInclude("%workpath()/testFile2.txt")
|
||||
|
||||
%mInclude("%workpath()/testFile2.txt",source=1)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
**EXAMPLE 3.** Embedding SQL code inside the pass through execution:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
resetline;
|
||||
filename f2 "%workpath()/testSql.txt";
|
||||
|
||||
data _null_;
|
||||
file f2;
|
||||
input;
|
||||
put _infile_;
|
||||
cards4;
|
||||
select
|
||||
c2.make
|
||||
, c2.model
|
||||
, c2.type
|
||||
, c2.invoice
|
||||
, c2.date
|
||||
|
||||
from
|
||||
public.CARS_EU c2
|
||||
|
||||
where
|
||||
c2.cylinders > 4
|
||||
and
|
||||
c2.date > '2023-04-02'
|
||||
;;;;
|
||||
run;
|
||||
|
||||
|
||||
title 'the %include fails';
|
||||
proc sql;
|
||||
connect to POSTGRES as PSGDB (
|
||||
server="127.0.0.1"
|
||||
port=5432
|
||||
user="user"
|
||||
password="password"
|
||||
database="DB"
|
||||
);
|
||||
|
||||
select * from connection to PSGDB
|
||||
(
|
||||
%Include f2 / source2;
|
||||
)
|
||||
;
|
||||
|
||||
disconnect from PSGDB;
|
||||
quit;
|
||||
|
||||
title 'the %mInclude works';
|
||||
proc sql;
|
||||
connect to POSTGRES as PSGDB (
|
||||
server="127.0.0.1"
|
||||
port=5432
|
||||
user="user"
|
||||
password="password"
|
||||
database="DB"
|
||||
);
|
||||
|
||||
|
||||
select * from connection to PSGDB
|
||||
(
|
||||
%mInclude(f2, source=1)
|
||||
)
|
||||
;
|
||||
|
||||
disconnect from PSGDB;
|
||||
quit;
|
||||
|
||||
title;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
**EXAMPLE 4.** In a limited way and with help of the `resolve()` function,
|
||||
it even works with IML's interface to R:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
|
||||
resetline;
|
||||
filename f3 TEMP;
|
||||
|
||||
data _null_;
|
||||
file f3;
|
||||
infile cards4;
|
||||
input;
|
||||
put _infile_ ';'; %* a "semicolon" trick for R statements separation *;
|
||||
cards4;
|
||||
rModel <- lm(Weight ~ Height, data=Class, na.action="na.exclude")
|
||||
print (rModel$call)
|
||||
print (rModel)
|
||||
;;;;
|
||||
run;
|
||||
|
||||
|
||||
proc iml;
|
||||
codeText = resolve(' %mInclude(f3, source=1) ');
|
||||
print codeText;
|
||||
|
||||
call ExportDataSetToR("Sashelp.Class", "Class" );
|
||||
submit codeText / R;
|
||||
&codeText
|
||||
endsubmit;
|
||||
quit;
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
---
|
||||
|
||||
## >>> `%fmt()` macro: <<< <a name="fmt-macro"></a> #######################
|
||||
|
||||
The fmt() macro function returns a `value` formatted by a `format`,
|
||||
it is a wrapper to `putN()` and `putC()` functions.
|
||||
|
||||
See examples below for the details.
|
||||
|
||||
The `%fmt()` macro executes like a pure macro code.
|
||||
|
||||
### SYNTAX: ###################################################################
|
||||
|
||||
The basic syntax is the following, the `<...>` means optional parameters:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%fmt(
|
||||
value
|
||||
,format
|
||||
,align
|
||||
<,type=>
|
||||
)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
**Arguments description**:
|
||||
|
||||
1. `value` - *Required*, a value to be formatted.
|
||||
|
||||
2. `format` - *Required*, a name of a format to be used,
|
||||
character format should be preceded by the `$`.
|
||||
|
||||
3. `align` - *Optional*, allows to use the `-L`, `-R` and `-C` modifiers.
|
||||
|
||||
* `type=n` - *Optional*, defines type of the format. If the format
|
||||
name is preceded by the `$` then C is set automatically.
|
||||
If the character format name is without `$` then set
|
||||
value to `C` yourself.
|
||||
|
||||
---
|
||||
|
||||
### EXAMPLES AND USECASES: ####################################################
|
||||
|
||||
**EXAMPLE 1.** Formatting values:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%put %fmt(111, 7.2);
|
||||
|
||||
%put %fmt(111, dollar10.2);
|
||||
|
||||
%put %fmt(abc, $upcase.);
|
||||
|
||||
%put %fmt(12345, date9.);
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
**EXAMPLE 2.** Align values (compare different results!):
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%put *%fmt(ABC, $char9., -L)*;
|
||||
%put *%fmt(ABC, $char9., -R)*;
|
||||
%put *%fmt(ABC, $char9., -C)*;
|
||||
|
||||
%put %fmt(ABC, $char9., -L);
|
||||
%put %fmt(ABC, $char9., -R);
|
||||
%put %fmt(ABC, $char9., -C);
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
---
|
||||
|
||||
## >>> `%infmt()` macro: <<< <a name="infmt-macro"></a> #######################
|
||||
|
||||
The infmt() macro function returns a `value` read in by an `informat`,
|
||||
it is a wrapper to `inputN()` and `inputC()` functions.
|
||||
|
||||
See examples below for the details.
|
||||
|
||||
The `%infmt()` macro executes like a pure macro code.
|
||||
|
||||
### SYNTAX: ###################################################################
|
||||
|
||||
The basic syntax is the following, the `<...>` means optional parameters:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%infmt(
|
||||
value
|
||||
,informat
|
||||
<,type=>
|
||||
)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
**Arguments description**:
|
||||
|
||||
1. `value` - *Required*, a value to be formatted.
|
||||
|
||||
2. `informat` - *Required*, a name of a format to be used,
|
||||
character format should be preceded by the `$`.
|
||||
|
||||
* `type=n` - *Optional*, defines type of the informat. If the informat
|
||||
name is preceded by the `$` then C is set automatically.
|
||||
If the character format name is without `$` then set
|
||||
value to `C` yourself.
|
||||
|
||||
---
|
||||
|
||||
### EXAMPLES AND USECASES: ####################################################
|
||||
|
||||
**EXAMPLE 1.** Informatting values:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas
|
||||
%put %infmt(111, 7.2);
|
||||
%put %infmt(111.234, 7.2);
|
||||
|
||||
%put %infmt($111, dollar10.2);
|
||||
%put %infmt($111.234, dollar10.2);
|
||||
|
||||
%put %infmt(abc, $upcase.);
|
||||
|
||||
%put %infmt(12mar45, date9.);
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
---
|
||||
|
||||
BIN
baseplus.zip
BIN
baseplus.zip
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 65 KiB After Width: | Height: | Size: 66 KiB |
5148
hist/1.26.1/baseplus.md
Normal file
5148
hist/1.26.1/baseplus.md
Normal file
File diff suppressed because it is too large
Load Diff
BIN
hist/1.26.1/baseplus.zip
Normal file
BIN
hist/1.26.1/baseplus.zip
Normal file
Binary file not shown.
5498
hist/1.29.0/baseplus.md
Normal file
5498
hist/1.29.0/baseplus.md
Normal file
File diff suppressed because it is too large
Load Diff
BIN
hist/1.29.0/baseplus.zip
Normal file
BIN
hist/1.29.0/baseplus.zip
Normal file
Binary file not shown.
5498
hist/1.29.1/baseplus.md
Normal file
5498
hist/1.29.1/baseplus.md
Normal file
File diff suppressed because it is too large
Load Diff
BIN
hist/1.29.1/baseplus.zip
Normal file
BIN
hist/1.29.1/baseplus.zip
Normal file
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.
Reference in New Issue
Block a user