-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathSPFinit.sas
6881 lines (6128 loc) · 326 KB
/
SPFinit.sas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**############################################################################**/
/* */
/* Copyright Bartosz Jablonski, since July 2019. */
/* */
/* Code is free and open source. If you want - you can use it. */
/* I tested it the best I could */
/* but it comes with absolutely no warranty whatsoever. */
/* If you cause any damage or something - it will be your own fault. */
/* You have been warned! You are using it on your own risk. */
/* However, if you decide to use it do not forget to mention author: */
/* Bartosz Jablonski ([email protected]) */
/* */
/* Here is the official version: */
/*
Copyright (c) 2019 - 2024 Bartosz Jablonski ([email protected])
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
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.
*/
/**#############################################################################**/
/*** HELP START ***/
/* SPF (SAS Packages Framework) is a set of macros:
- to install,
- to load,
- to get help,
- to unload, or
- to generate SAS packages.
Version 20241207.
See examples below.
A SAS package is a zip file containing a group of files
with SAS code (macros, functions, data steps generating
data, etc.) wrapped up together and %INCLUDEed by
a single load.sas file (also embedded inside the zip).
*/
/*** HELP END ***/
/*+loadPackage+*/
/*** HELP START ***/
%macro loadPackage(
packageName /* name of a package,
e.g. myPackage,
required and not null */
, path = %sysfunc(pathname(packages)) /* location of a package,
by default it looks for
location of "packages" fileref */
, options = %str(LOWCASE_MEMNAME) /* possible options for ZIP filename */
, source2 = /*source2*/ /* option to print out details,
null by default */
, requiredVersion = . /* option to test if loaded package
is provided in required version */
, lazyData = /* a list of names of lazy datasets
to be loaded, if not null then
datasets from the list are loaded
instead of a package, asterisk
means "load all datasets" */
, zip = zip /* standard package is zip (lowcase),
e.g. %loadPackage(PiPackage)
if the zip is not available use a folder
unpack data to "pipackage.disk" folder
and use loadPackage in the form:
%loadPackage(PiPackage, zip=disk, options=) */
, cherryPick=* /* space separated list of selected elements of the package
to be loaded into the session, default value "*" means
"load all elements of the package" */
, loadAddCnt=0 /* should the additional content be loaded?
default is 0 - means No, 1 means Yes */
, suppressExec=0 /* indicates if loading of exec files
should be suppressed, 1=suppress */
, DS2force=0 /* indicates if PROC DS2 packages and threads
should be loaded if a data set exists, 0=do not load
*/
)/secure
/*** HELP END ***/
des = 'Macro to load SAS package, version 20241207. Run %loadPackage() for help info.'
minoperator
;
%if (%superq(packageName) = ) OR (%qupcase(&packageName.) = HELP) %then
%do;
%local options_tmp ;
%let options_tmp = ls=%sysfunc(getoption(ls))ps=%sysfunc(getoption(ps))
%sysfunc(getoption(notes)) %sysfunc(getoption(source))
msglevel=%sysfunc(getoption(msglevel))
;
options NOnotes NOsource ls=MAX ps=MAX msglevel=N;
%put ;
%put #################################################################################;
%put ### This is short help information for the `loadPackage` macro #;
%put #-------------------------------------------------------------------------------#;
%put # #;
%put # Macro to *load* SAS packages, version `20241207` #;
%put # #;
%put # A SAS package is a zip file containing a group #;
%put # of SAS codes (macros, functions, data steps generating #;
%put # data, etc.) wrapped up together and included by #;
%put # a single `load.sas` file (also embedded inside the zip). #;
%put # #;
%put # The `%nrstr(%%loadPackage())` macro loads package content, i.e. macros, #;
%put # functions, formats, etc., from the zip into the SAS session. #;
%put # #;
%put #-------------------------------------------------------------------------------#;
%put #### Parameters: #;
%put # #;
%put # 1. `packageName` *Required.* Name of a package, e.g. myPackage, #;
%put # Required and not null, default use case: #;
%put # `%nrstr(%%loadPackage(myPackage)).` #;
%put # If empty displays this help information. #;
%put # #;
%put # - `path=` *Optional.* Location of a package. By default it #;
%put # looks for location of the **packages** fileref, i.e. #;
%put # `%nrstr(%%sysfunc(pathname(packages)))` #;
%put # #;
%put # - `options=` *Optional.* Possible options for ZIP filename, #;
%put # default value: `LOWCASE_MEMNAME` #;
%put # #;
%put # - `source2=` *Optional.* Option to print out details about #;
%put # what is loaded, null by default. #;
%put # #;
%put # - `requiredVersion=` *Optional.* Option to test if the loaded #;
%put # package is provided in required version, #;
%put # default value: `.` #;
%put # #;
%put # - `lazyData=` *Optional.* A space separated list of names of lazy #;
%put # datasets to be loaded. If not null datasets from the #;
%put # list are loaded instead of the package. #;
%put # An asterisk (*) means *load all lazy datasets*. #;
%put # #;
%put # - `zip=` *Optional.* Standard package is zip (lowcase), #;
%put # e.g. `%nrstr(%%loadPackage(PiPackage))`. #;
%put # If the zip is not available use a folder. #;
%put # Unpack data to "pipackage.disk" folder #;
%put # and use loadPackage in the following form: #;
%put # `%nrstr(%%loadPackage(PiPackage, zip=disk, options=))` #;
%put # #;
%put # - `cherryPick=` *Optional.* A space separated list of selected elements #;
%put # of the package to be loaded into the SAS session. #;
%put # Default value of an asterisk (*) means: #;
%put # "load all elements of the package". #;
%put # #;
%put # - `loadAddCnt=` *Optional.* A package zip may contain additional #;
%put # content. The option indicates if it should be loaded #;
%put # Default value of zero (`0`) means "No", one (`1`) #;
%put # means "Yes". Content is extracted into the **Work** #;
%put # directory in `<packageName>_AdditionalContent` folder. #;
%put # For other locations use `%nrstr(%%loadPackageAddCnt())` macro. #;
%put # #;
%put # - `suppressExec=` *Optional.* Indicates if loading of `exec` type files #;
%put # should be suppressed, default value is `0`, #;
%put # when set to `1` `exec` files are *not* loaded #;
%put # #;
%put # - `DS2force=` *Optional.* Indicates if loading of `PROC DS2` packages #;
%put # or threads should overwrite existing SAS data sets. #;
%put # Default value of `0` means "do not overwrite". #;
%put # #;
%put #-------------------------------------------------------------------------------#;
%put # #;
%put # Visit: `https://github.com/yabwon/SAS_PACKAGES/tree/main/SPF/Documentation` #;
%put # to learn more. #;
%put # #;
%put ### Example 1 ###################################################################;
%put # #;
%put # Enabling the SAS Package Framework #;
%put # from the local directory and installing & loading #;
%put # the SQLinDS package from the Internet. #;
%put # #;
%put # Assume that the `SPFinit.sas` file #;
%put # is located in the "C:/SAS_PACKAGES/" folder. #;
%put # #;
%put # Run the following code in your SAS session: #;
%put ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas;
%put %nrstr( filename packages "C:/SAS_PACKAGES"; %%* setup a directory for packages; );
%put %nrstr( %%include packages(SPFinit.sas); %%* enable the framework; );
%put ;
%put %nrstr( %%installPackage(SQLinDS) %%* install the package from the Internet; );
%put %nrstr( %%helpPackage(SQLinDS) %%* get help about the package; );
%put %nrstr( %%loadPackage(SQLinDS) %%* load the package content into the SAS session; );
%put %nrstr( %%unloadPackage(SQLinDS) %%* unload the package content from the SAS session; );
%put ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
%put # #;
%put ### Example 2 ###################################################################;
%put # #;
%put # Enabling the SAS Package Framework #;
%put # from the local directory and installing & cherry picking #;
%put # elements of the BasePlus package. #;
%put # #;
%put # Assume that the `SPFinit.sas` file #;
%put # is located in the "C:/SAS_PACKAGES/" folder. #;
%put # #;
%put # Run the following code in your SAS session: #;
%put ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas;
%put %nrstr( filename packages "C:/SAS_PACKAGES"; %%* setup a directory for packages; );
%put %nrstr( %%include packages(SPFinit.sas); %%* enable the framework; );
%put ;
%put %nrstr( %%installPackage(BasePlus) %%* install the package from the Internet; );
%put %nrstr( %%loadPackage(BasePlus, cherryPick=getVars) %%* cherry pick the content; );
%put ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
%put # #;
%put #################################################################################;
%put ;
options &options_tmp.;
%GOTO ENDofloadPackage;
%end;
/* local variables for options */
%local ls_tmp ps_tmp notes_tmp source_tmp stimer_tmp fullstimer_tmp msglevel_tmp mautocomploc_tmp;
%let ls_tmp = %sysfunc(getoption(ls));
%let ps_tmp = %sysfunc(getoption(ps));
%let notes_tmp = %sysfunc(getoption(notes));
%let source_tmp = %sysfunc(getoption(source));
%let stimer_tmp = %sysfunc(getoption(stimer));
%let fullstimer_tmp = %sysfunc(getoption(fullstimer));
%let msglevel_tmp = %sysfunc(getoption(msglevel));
%let mautocomploc_tmp = %sysfunc(getoption(mautocomploc));
options NOnotes NOsource ls=MAX ps=MAX NOfullstimer NOstimer msglevel=N NOmautocomploc;
%local _PackageFileref_;
/* %let _PackageFileref_ = P%sysfunc(MD5(%lowcase(&packageName.)),hex7.); */
data _null_; call symputX("_PackageFileref_", "P" !! put(MD5("%lowcase(&packageName.)"), hex7. -L), "L"); run;
/* when the packages reference is multi-directory search for the first one containing the package */
data _null_;
exists = 0;
length packages $ 32767 p $ 4096;
packages = resolve(symget("path"));
if char(packages,1) ^= "(" then packages = quote(strip(packages)); /* for paths with spaces */
do i = 1 to kcountw(packages, "()", "QS");
p = dequote(kscanx(packages, i, "()", "QS"));
exists + fileexist(catx("/", p, "%lowcase(&packageName.).&zip."));
if exists then leave;
end;
if exists then call symputx("path", p, "L");
run;
/* convert cherryPick to lower case if needed */
%if NOT (%str(*) = %superq(cherryPick)) %then
%do;
data _null_;
call symputX("cherryPick",lowcase(compbl(compress(symget("cherryPick"),". _","KDA"))),"L");
run;
%end;
/* empty list is equivalent to "*" */
%if %superq(cherryPick)= %then
%do;
%let cherryPick=*;
%end;
%if %superq(loadAddCnt) NE 1 %then
%do;
%let loadAddCnt = 0;
%end;
%if %superq(suppressExec) NE 1 %then
%do;
%let suppressExec = 0;
%end;
%if %superq(DS2force) NE 1 %then
%do;
%let DS2force = 0;
%end;
filename &_PackageFileref_. &ZIP.
/* put location of package myPackageFile.zip here */
"&path./%lowcase(&packageName.).&zip." %unquote(&options.)
;
%if %sysfunc(fexist(&_PackageFileref_.)) %then
%do;
%include &_PackageFileref_.(packagemetadata.sas) / &source2.;
filename &_PackageFileref_. clear;
/* test if required version of package is "good enough" */
%local rV pV rV0 pV0 rVsign;
%let pV0 = %sysfunc(compress(&packageVersion.,.,kd));
%let pV = %sysevalf((%scan(&pV0.,1,.,M)+0)*1e8
+ (%scan(&pV0.,2,.,M)+0)*1e4
+ (%scan(&pV0.,3,.,M)+0)*1e0);
%let rV0 = %sysfunc(compress(&requiredVersion.,.,kd));
%let rVsign = %sysfunc(compress(&requiredVersion.,<=>,k));
%if %superq(rVsign)= %then %let rVsign=<=;
%else %if NOT (%superq(rVsign) IN (%str(=) %str(<=) %str(=<) %str(=>) %str(>=) %str(<) %str(>))) %then
%do;
%put WARNING: Illegal operatopr "%superq(rVsign)"! Default(<=) will be used.;
%put WARNING- Supported operators are: %str(= <= =< => >= < >);
%let rVsign=<=;
%end;
%let rV = %sysevalf((%scan(&rV0.,1,.,M)+0)*1e8
+ (%scan(&rV0.,2,.,M)+0)*1e4
+ (%scan(&rV0.,3,.,M)+0)*1e0);
%if NOT %sysevalf(&rV. &rVsign. &pV.) %then
%do;
%put ERROR: Package &packageName. will not be loaded!;
%put ERROR- Required version is &rV0.;
%put ERROR- Provided version is &pV0.;
%put ERROR- Condition %bquote((&rV0. &rVsign. &pV0.)) evaluates to %sysevalf(&rV. &rVsign. &pV.);
%put ERROR- Verify installed version of the package.;
%put ERROR- ;
%GOTO WrongVersionOFPackage; /*%RETURN;*/
%end;
options ls = &ls_tmp. ps = &ps_tmp. ¬es_tmp. &source_tmp.;
filename &_PackageFileref_. &ZIP.
"&path./%lowcase(&packageName.).&zip." %unquote(&options.)
ENCODING =
%if %bquote(&packageEncoding.) NE %then &packageEncoding. ;
%else utf8 ;
;
%if %superq(lazyData) = %then
%do;
%local tempLoad_minoperator temp_noNotes_etc /* for hiding notes */ ;
%let tempLoad_minoperator = %sysfunc(getoption(minoperator));
options minoperator; /* MinOperator option is required for cherryPicking to work */
%include &_PackageFileref_.(load.sas) / &source2.;
options &tempLoad_minoperator.;
%if 1 = &loadAddCnt. %then
%do;
%put; %put - Additional content loading - Start -;
%loadPackageAddCnt(&packageName.,
path=&path.)
%put - Additional content loading - End -;
%end;
%end;
%else
%do;
%include &_PackageFileref_.(lazydata.sas) / &source2.;
%end;
%end;
%else %put ERROR:[&sysmacroname] File "&path./&packageName..&zip." does not exist!;
filename &_PackageFileref_. clear;
%WrongVersionOFPackage:
/* restore optionos */
options ls = &ls_tmp. ps = &ps_tmp.
¬es_tmp. &source_tmp.
&stimer_tmp. &fullstimer_tmp.
msglevel=&msglevel_tmp. &mautocomploc_tmp.;
%ENDofloadPackage:
%mend loadPackage;
/*+unloadPackage+*/
/*** HELP START ***/
%macro unloadPackage(
packageName /* name of a package,
e.g. myPackage,
required and not null */
, path = %sysfunc(pathname(packages)) /* location of a package,
by default it looks for
location of "packages" fileref */
, options = %str(LOWCASE_MEMNAME) /* possible options for ZIP filename */
, source2 = /*source2*/ /* option to print out details,
null by default */
, zip = zip /* standard package is zip (lowcase),
e.g. %unloadPackage(PiPackage)
if the zip is not available use a folder
unpack data to "pipackage.disk" folder
and use unloadPackage in the form:
%unloadPackage(PiPackage, zip=disk, options=)
*/
)/secure
/*** HELP END ***/
des = 'Macro to unload SAS package, version 20241207. Run %unloadPackage() for help info.'
;
%if (%superq(packageName) = ) OR (%qupcase(&packageName.) = HELP) %then
%do;
%local options_tmp ;
%let options_tmp = ls=%sysfunc(getoption(ls))ps=%sysfunc(getoption(ps))
%sysfunc(getoption(notes)) %sysfunc(getoption(source))
msglevel=%sysfunc(getoption(msglevel))
;
options NOnotes NOsource ls=MAX ps=MAX msglevel=N;
%put ;
%put #################################################################################;
%put ### This is short help information for the `unloadPackage` macro #;
%put #-------------------------------------------------------------------------------#;
%put # #;
%put # Macro to unload SAS packages, version `20241207` #;
%put # #;
%put # A SAS package is a zip file containing a group #;
%put # of SAS codes (macros, functions, data steps generating #;
%put # data, etc.) wrapped up together and provided with #;
%put # a single `unload.sas` file (also embedded inside the zip). #;
%put # #;
%put # The `%nrstr(%%unloadPackage())` macro clears the package content #;
%put # from the SAS session. #;
%put # #;
%put #-------------------------------------------------------------------------------#;
%put # #;
%put #### Parameters: #;
%put # #;
%put # 1. `packageName` *Required.* Name of a package, e.g. myPackage, #;
%put # Required and not null, default use case: #;
%put # `%nrstr(%%unloadPackage(myPackage)).` #;
%put # If empty displays this help information. #;
%put # #;
%put # - `path=` *Optional.* Location of a package. By default it #;
%put # looks for location of the **packages** fileref, i.e. #;
%put # `%nrstr(%%sysfunc(pathname(packages)))` #;
%put # #;
%put # - `options=` *Optional.* Possible options for ZIP filename, #;
%put # default value: `LOWCASE_MEMNAME` #;
%put # #;
%put # - `source2=` *Optional.* Option to print out details about #;
%put # what is loaded, null by default. #;
%put # #;
%put # - `zip=` Standard package is zip (lowcase), #;
%put # e.g. `%nrstr(%%unloadPackage(PiPackage))`. #;
%put # If the zip is not available use a folder. #;
%put # Unpack data to "pipackage.disk" folder #;
%put # and use unloadPackage in the following form: #;
%put # `%nrstr(%%unloadPackage(PiPackage, zip=disk, options=))` #;
%put # #;
%put #-------------------------------------------------------------------------------#;
%put # #;
%put # Visit: `https://github.com/yabwon/SAS_PACKAGES/tree/main/SPF/Documentation` #;
%put # to learn more. #;
%put # #;
%put ### Example #####################################################################;
%put # #;
%put # Enabling the SAS Package Framework #;
%put # from the local directory and installing & loading #;
%put # the SQLinDS package from the Internet. #;
%put # #;
%put # Assume that the `SPFinit.sas` file #;
%put # is located in the "C:/SAS_PACKAGES/" folder. #;
%put # #;
%put # Run the following code in your SAS session: #;
%put ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas;
%put %nrstr( filename packages "C:/SAS_PACKAGES"; %%* setup a directory for packages; );
%put %nrstr( %%include packages(SPFinit.sas); %%* enable the framework; );
%put ;
%put %nrstr( %%installPackage(SQLinDS) %%* install the package from the Internet; );
%put %nrstr( %%helpPackage(SQLinDS) %%* get help about the package; );
%put %nrstr( %%loadPackage(SQLinDS) %%* load the package content into the SAS session; );
%put %nrstr( %%unloadPackage(SQLinDS) %%* unload the package content from the SAS session; );
%put ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
%put #################################################################################;
%put ;
options &options_tmp.;
%GOTO ENDofunloadPackage;
%end;
/* local variables for options */
%local ls_tmp ps_tmp notes_tmp source_tmp msglevel_tmp mautocomploc_tmp;
%let ls_tmp = %sysfunc(getoption(ls));
%let ps_tmp = %sysfunc(getoption(ps));
%let notes_tmp = %sysfunc(getoption(notes));
%let source_tmp = %sysfunc(getoption(source));
%let msglevel_tmp = %sysfunc(getoption(msglevel));
%let mautocomploc_tmp = %sysfunc(getoption(mautocomploc));
options NOnotes NOsource ls=MAX ps=MAX msglevel=N NOmautocomploc;
%local _PackageFileref_;
/* %let _PackageFileref_ = P%sysfunc(MD5(%lowcase(&packageName.)),hex7.); */
data _null_; call symputX("_PackageFileref_", "P" !! put(MD5("%lowcase(&packageName.)"), hex7. -L), "L"); run;
/* when the packages reference is multi-directory search for the first one containing the package */
data _null_;
exists = 0;
length packages $ 32767 p $ 4096;
packages = resolve(symget("path"));
if char(packages,1) ^= "(" then packages = quote(strip(packages)); /* for paths with spaces */
do i = 1 to kcountw(packages, "()", "QS");
p = dequote(kscanx(packages, i, "()", "QS"));
exists + fileexist(catx("/", p, "%lowcase(&packageName.).&zip."));
if exists then leave;
end;
if exists then call symputx("path", p, "L");
run;
filename &_PackageFileref_. &ZIP.
/* put location of package myPackageFile.zip here */
"&path./%lowcase(&packageName.).&zip." %unquote(&options.)
;
%if %sysfunc(fexist(&_PackageFileref_.)) %then
%do;
%include &_PackageFileref_.(packagemetadata.sas) / &source2.;
filename &_PackageFileref_. clear;
options ls = &ls_tmp. ps = &ps_tmp. ¬es_tmp. &source_tmp.;
filename &_PackageFileref_. &ZIP.
"&path./%lowcase(&packageName.).&zip." %unquote(&options.)
ENCODING =
%if %bquote(&packageEncoding.) NE %then &packageEncoding. ;
%else utf8 ;
;
%include &_PackageFileref_.(unload.sas) / &source2.;
%end;
%else %put ERROR:[&sysmacroname] File "&path./&packageName..&zip." does not exist!;
filename &_PackageFileref_. clear;
options ls = &ls_tmp. ps = &ps_tmp. ¬es_tmp. &source_tmp.
msglevel = &msglevel_tmp. &mautocomploc_tmp.;
%ENDofunloadPackage:
%mend unloadPackage;
/*+helpPackage+*/
/*** HELP START ***/
%macro helpPackage(
packageName /* name of a package,
e.g. myPackageFile.zip,
required and not null */
, helpKeyword /* phrase to search in help,
when empty prints description
"*" means print all help
"license" prints license */
, path = %sysfunc(pathname(packages)) /* location of a package,
by default it looks for
location of "packages" fileref */
, options = %str(LOWCASE_MEMNAME) /* possible options for ZIP filename */
, source2 = /*source2*/ /* option to print out details,
null by default */
, zip = zip /* standard package is zip (lowcase),
e.g. %helpPackage(PiPackage,*)
if the zip is not available use a folder
unpack data to "pipackage.disk" folder
and use helpPackage in the form:
%helpPackage(PiPackage, *, zip=disk, options=) */
, packageContentDS = 0 /* indicates if a data set with package
content should be generated in WORK,
if set to 1 then WORK.packageName_content
dataset is created
*/
)/secure
/*** HELP END ***/
des = 'Macro to get help about SAS package, version 20241207. Run %helpPackage() for help info.'
;
%if (%superq(packageName) = ) OR (%qupcase(&packageName.) = HELP) %then
%do;
%local options_tmp ;
%let options_tmp = ls=%sysfunc(getoption(ls))ps=%sysfunc(getoption(ps))
%sysfunc(getoption(notes)) %sysfunc(getoption(source))
msglevel=%sysfunc(getoption(msglevel))
;
options NOnotes NOsource ls=MAX ps=MAX msglevel=N;
%put ;
%put #################################################################################;
%put ### This is short help information for the `helpPackage` macro #;
%put #-------------------------------------------------------------------------------#;
%put # #;
%put # Macro to get help about SAS packages, version `20241207` #;
%put # #;
%put # A SAS package is a zip file containing a group #;
%put # of SAS codes (macros, functions, data steps generating #;
%put # data, etc.) wrapped up together and provided with #;
%put # a single `help.sas` file (also embedded inside the zip). #;
%put # #;
%put # The `%nrstr(%%helpPackage())` macro prints in the SAS log help #;
%put # information about the package provided by the developer. #;
%put # #;
%put #-------------------------------------------------------------------------------#;
%put # #;
%put #### Parameters: #;
%put # #;
%put # 1. `packageName` *Required.* Name of a package, e.g. myPackage, #;
%put # Required and not null, default use case: #;
%put # `%nrstr(%%helpPackage(myPackage)).` #;
%put # If empty displays this help information. #;
%put # #;
%put # 2. `helpKeyword` *Optional.* A phrase to search in help, #;
%put # - when empty prints description, #;
%put # - "*" means: print all help, #;
%put # - "license" prints the license. #;
%put # #;
%put # - `path=` *Optional.* Location of a package. By default it #;
%put # looks for location of the **packages** fileref, i.e. #;
%put # `%nrstr(%%sysfunc(pathname(packages)))` #;
%put # #;
%put # - `options=` *Optional.* Possible options for ZIP filename, #;
%put # default value: `LOWCASE_MEMNAME` #;
%put # #;
%put # - `source2=` *Optional.* Option to print out details about #;
%put # what is loaded, null by default. #;
%put # #;
%put # - `zip=` Standard package is zip (lowcase), #;
%put # e.g. `%nrstr(%%helpPackage(PiPackage))`. #;
%put # If the zip is not available use a folder. #;
%put # Unpack data to "pipackage.disk" folder #;
%put # and use helpPackage in the following form: #;
%put # `%nrstr(%%helpPackage(PiPackage, ,zip=disk, options=))` #;
%put # #;
%put # - `packageContentDS=` *Optional.* Indicates if a data set with package #;
%put # content should be generated in `WORK`, #;
%put # with default value (`0`) the dataset is not produced, #;
%put # if set to `1` then `WORK.packageName_content`. #;
%put # #;
%put #-------------------------------------------------------------------------------#;
%put # #;
%put # Visit: `https://github.com/yabwon/SAS_PACKAGES/tree/main/SPF/Documentation` #;
%put # to learn more. #;
%put # #;
%put #### Example ####################################################################;
%put # #;
%put # Enabling the SAS Package Framework #;
%put # from the local directory and installing & loading #;
%put # the SQLinDS package from the Internet. #;
%put # #;
%put # Assume that the `SPFinit.sas` file #;
%put # is located in the "C:/SAS_PACKAGES/" folder. #;
%put # #;
%put # Run the following code in your SAS session: #;
%put ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas;
%put %nrstr( filename packages "C:/SAS_PACKAGES"; %%* setup a directory for packages; );
%put %nrstr( %%include packages(SPFinit.sas); %%* enable the framework; );
%put ;
%put %nrstr( %%installPackage(SQLinDS) %%* install the package from the Internet; );
%put %nrstr( %%helpPackage(SQLinDS) %%* get help about the package; );
%put %nrstr( %%loadPackage(SQLinDS) %%* load the package content into the SAS session; );
%put %nrstr( %%unloadPackage(SQLinDS) %%* unload the package content from the SAS session; );
%put ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
%put #################################################################################;
%put ;
options &options_tmp.;
%GOTO ENDofhelpPackage;
%end;
/* local variables for options */
%local ls_tmp ps_tmp notes_tmp source_tmp msglevel_tmp mautocomploc_tmp;
%let ls_tmp = %sysfunc(getoption(ls));
%let ps_tmp = %sysfunc(getoption(ps));
%let notes_tmp = %sysfunc(getoption(notes));
%let source_tmp = %sysfunc(getoption(source));
%let msglevel_tmp = %sysfunc(getoption(msglevel));
%let mautocomploc_tmp = %sysfunc(getoption(mautocomploc));
options NOnotes NOsource ls=MAX ps=MAX msglevel=N NOmautocomploc;
%local _PackageFileref_;
/* %let _PackageFileref_ = P%sysfunc(MD5(%lowcase(&packageName.)),hex7.); */
data _null_; call symputX("_PackageFileref_", "P" !! put(MD5("%lowcase(&packageName.)"), hex7. -L), "L"); run;
/* when the packages reference is multi-directory search for the first one containing the package */
data _null_;
exists = 0;
length packages $ 32767 p $ 4096;
packages = resolve(symget("path"));
if char(packages,1) ^= "(" then packages = quote(strip(packages)); /* for paths with spaces */
do i = 1 to kcountw(packages, "()", "QS");
p = dequote(kscanx(packages, i, "()", "QS"));
exists + fileexist(catx("/", p, "%lowcase(&packageName.).&zip."));
if exists then leave;
end;
if exists then call symputx("path", p, "L");
run;
filename &_PackageFileref_. &ZIP.
/* put location of package myPackageFile.zip here */
"&path./%lowcase(&packageName.).&zip." %unquote(&options.)
;
%if %sysfunc(fexist(&_PackageFileref_.)) %then
%do;
%include &_PackageFileref_.(packagemetadata.sas) / &source2.;
filename &_PackageFileref_. clear;
options ls = &ls_tmp. ps = &ps_tmp. ¬es_tmp. &source_tmp.;
filename &_PackageFileref_. &ZIP.
"&path./%lowcase(&packageName.).&zip." %unquote(&options.)
ENCODING =
%if %bquote(&packageEncoding.) NE %then &packageEncoding. ;
%else utf8 ;
;
%if 1=%superq(packageContentDS) %then %let packageContentDS=work.&packageName._content;
%else %let packageContentDS=;
%include &_PackageFileref_.(help.sas) / &source2.;
%end;
%else %put ERROR:[&sysmacroname] File "&path./&packageName..&zip." does not exist!;
filename &_PackageFileref_. clear;
options ls = &ls_tmp. ps = &ps_tmp. ¬es_tmp. &source_tmp.
msglevel = &msglevel_tmp. &mautocomploc_tmp.;
%ENDofhelpPackage:
%mend helpPackage;
/*
TODO:
- macro for testing available packages in the packages folder [DONE] checkout: %listPackages()
- add MD5(&packageName.) value hash instead "package" word in filenames [DONE]
*/
/*+installPackage+*/
/* Macros to install SAS packages, version 20241207 */
/* A SAS package is a zip file containing a group of files
with SAS code (macros, functions, data steps generating
data, etc.) wrapped up together and %INCLUDEed by
a single load.sas file (also embedded inside the zip).
*/
/*** HELP START ***/
%macro installPackage(
packagesNames /* space separated list of packages names, without the zip extension */
, sourcePath = /* location of the package, e.g. "www.some.page/", mind the "/" at the end */
, mirror = 0 /* indicates which location for package source should be used */
, version = /* indicates which version of a package to install */
, replace = 1 /* 1 = replace if the package already exist, 0 = otherwise */
, URLuser = /* user name for the password protected URLs */
, URLpass = /* password for the password protected URLs */
, URLoptions = /* options for the `sourcePath` URLs */
, loadAddCnt=0 /* should the additional content be loaded?
default is 0 - means No, 1 means Yes */
, instDoc=0 /* should the markdown file with documentation be installed?
default is 0 - means No, 1 means Yes */
, SFRCVN = /* name of a macro variable to store success-failure return code value */
)
/secure
minoperator
/*** HELP END ***/
des = 'Macro to install SAS package, version 20241207. Run %%installPackage() for help info.'
;
%if (%superq(packagesNames) = ) OR (%qupcase(&packagesNames.) = HELP) %then
%do;
%local options_tmp ;
%let options_tmp = ls=%sysfunc(getoption(ls))ps=%sysfunc(getoption(ps))
%sysfunc(getoption(notes)) %sysfunc(getoption(source))
msglevel=%sysfunc(getoption(msglevel))
;
options NOnotes NOsource ls=MAX ps=MAX msglevel=N;
%put ;
%put ##############################################################################################;
%put ### This is short help information for the `installPackage` macro #;
%put #--------------------------------------------------------------------------------------------#;;
%put # #;
%put # Macro to install SAS packages, version `20241207` #;
%put # #;
%put # A SAS package is a zip file containing a group #;
%put # of SAS codes (macros, functions, data steps generating #;
%put # data, etc.) wrapped up together and embedded inside the zip. #;
%put # #;
%put # The `%nrstr(%%installPackage())` macro installs the package zip #;
%put # in the packages folder. The process of installation is equivalent with #;
%put # manual downloading the package zip file into the packages folder. #;
%put # #;
%put # In case the packages fileref is a multi-directory one the first directory #;
%put # will be selected as a destination. #;
%put # #;
%put #--------------------------------------------------------------------------------------------#;
%put # #;
%put #### Parameters: #;
%put # #;
%put # 1. `packagesNames` Space separated list of packages names _without_ #;
%put # the zip extension, e.g. myPackage1 myPackage2, #;
%put # Required and not null, default use case: #;
%put # `%nrstr(%%installPackage(myPackage1 myPackage2))`. #;
%put # If empty displays this help information. #;
%put # If the package name is *SPFinit* or *SASPackagesFramework* #;
%put # then the framework itself is downloaded. #;
%put # #;
%put # - `sourcePath=` Location of the package, e.g. "www.some.web.page/" #;
%put # Mind the "/" at the end of the path! #;
%put # Current default location for packages is: #;
%put # `https://github.com/SASPAC/` #;
%put # Current default location for the framework is: #;
%put # `https://raw.githubusercontent.com/yabwon/SAS_PACKAGES/main/SPF/` #;
%put # #;
%put # - `mirror=` Indicates which web location for packages installation is used. #;
%put # Value `0` indicates: #;
%put # `https://github.com/SASPAC/` #;
%put # Value `1` indicates: #;
%put # `https://raw.githubusercontent.com/yabwon/SAS_PACKAGES/main` #;
%put # Value `2` indicates: #;
%put # `https://pages.mini.pw.edu.pl/~jablonskib/SASpublic/SAS_PACKAGES` #;
%put # Default value is `0`. #;
%put # #;
%put # - `version=` Indicates which historical version of a package to install. #;
%put # Historical version are available only if `mirror=0` is set. #;
%put # Default value is null which means "install the latest". #;
%put # When there are multiple packages to install version variable #;
%put # is scan sequentially. #;
%put # #;
%put # - `replace=` With default value of `1` it causes existing package file #;
%put # to be replaced by new downloaded file. #;
%put # #;
%put # - `URLuser=` A user name for the password protected URLs, no quotes needed. #;
%put # #;
%put # - `URLpass=` A password for the password protected URLs, no quotes needed. #;
%put # #;
%put # - `URLoptions=` Options for the `sourcePath` URLs filename. Consult the SAS #;
%put # documentation for the further details. #;
%put # #;
%put # - `loadAddCnt=` *Optional.* A package zip may contain additional #;
%put # content. The option indicates if it should be loaded #;
%put # Default value of zero (`0`) means "No", one (`1`) #;
%put # means "Yes". Content is extracted into the **packages** fileref #;
%put # directory in `<packageName>_AdditionalContent` folder. #;
%put # For other locations use `%nrstr(%%loadPackageAddCnt())` macro. #;
%put # #;
%put # - `instDoc=` *Optional.* A package may be provided with a markdown file #;
%put # containing combined documentation of the package. The option #;
%put # indicates if the `.md` file should be also downloaded. #;
%put # Default value of zero (`0`) means "No", one (`1`) means "Yes". #;
%put # #;
%put # - `SFRCVN=` *Optional.* Provides a NAME for a macro variable to store value of the #;
%put # *success-failure return code* of the installation process. Return value #;
%put # has the following form: `<number of successes>.<number of failures>` #;
%put # The macro variable is created as a *global* macro variable. #;
%put # #;
%put #--------------------------------------------------------------------------------------------#;
%put # #;
%put # Visit: `https://github.com/yabwon/SAS_PACKAGES/tree/main/SPF/Documentation` #;
%put # to learn more. #;
%put # #;
%put #### Example #################################################################################;
%put # #;
%put # Enabling the SAS Package Framework #;
%put # from the local directory and installing & loading #;
%put # the SQLinDS package from the Internet. #;
%put # #;
%put # Assume that the `SPFinit.sas` file #;
%put # is located in the "C:/SAS_PACKAGES/" folder. #;
%put # #;
%put # Run the following code in your SAS session: #;
%put ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas;
%put %nrstr( filename packages "C:/SAS_PACKAGES"; %%* setup a directory for packages; );
%put %nrstr( %%include packages(SPFinit.sas); %%* enable the framework; );
%put ;
%put %nrstr( %%installPackage(SQLinDS) %%* install the package from the Internet; );
%put %nrstr( %%helpPackage(SQLinDS) %%* get help about the package; );
%put %nrstr( %%loadPackage(SQLinDS) %%* load the package content into the SAS session; );
%put %nrstr( %%unloadPackage(SQLinDS) %%* unload the package content from the SAS session; );
%put ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
%put #### Example #################################################################################;
%put # #;
%put # Enabling the SAS Package Framework #;
%put # from the local directory and installing & loading #;
%put # the multiple packages from the Internet. #;
%put # #;
%put # Assume that the `SPFinit.sas` file #;
%put # is located in the "C:/SAS_PACKAGES/" folder. #;
%put # #;
%put # Run the following code in your SAS session: #;
%put ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~sas;
%put %nrstr( filename packages "C:/SAS_PACKAGES"; );
%put %nrstr( %%include packages(SPFinit.sas); );
%put ;
%put %nrstr( %%installPackage(baseplus(1.17) macroarray(1.0) dfa(0.5) GSM) );
%put %nrstr( %%loadPackageS(GSM, baseplus(1.17), macroarray(1.0), dfa(0.5)) );
%put ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
%put ##############################################################################################;
%put ;
options &options_tmp.;
%GOTO ENDofinstallPackage;
%end;
/* local variables for options */
%local ls_tmp ps_tmp notes_tmp source_tmp stimer_tmp fullstimer_tmp msglevel_tmp mautocomploc_tmp;
%let ls_tmp = %sysfunc(getoption(ls));
%let ps_tmp = %sysfunc(getoption(ps));
%let notes_tmp = %sysfunc(getoption(notes));
%let source_tmp = %sysfunc(getoption(source));
%let stimer_tmp = %sysfunc(getoption(stimer));
%let fullstimer_tmp = %sysfunc(getoption(fullstimer));
%let msglevel_tmp = %sysfunc(getoption(msglevel));
%let mautocomploc_tmp = %sysfunc(getoption(mautocomploc));
options NOnotes NOsource ls=MAX ps=MAX NOfullstimer NOstimer msglevel=N NOmautocomploc;
/*
Reference:
https://blogs.sas.com/content/sasdummy/2011/06/17/how-to-use-sas-data-step-to-copy-a-file-from-anywhere/
*/
/* in case the 'packages' fileref is multi-directory the first directory will be selected as a destination */
data _null_;
if "(" =: pathname("packages") then
/* get the firstPackagesPath */
call symputX("firstPackagesPath", dequote(kscanx(pathname("packages"), 1, "()", "QS")), "L");
else
call symputX("firstPackagesPath", pathname("packages"), "L");
run;
%let loadAddCnt = %sysevalf(NOT(0=%superq(loadAddCnt)));
%let instDoc = %sysevalf(NOT(0=%superq(instDoc)));
%let replace = %sysevalf(1=%superq(replace));
%if %superq(sourcePath)= %then
%do;
%local SPFinitMirror SPFinitMirrorMD;
/* the defaults are: */
%let SPFinitMirror = https://raw.githubusercontent.com/yabwon/SAS_PACKAGES/main/SPF/SPFinit.sas;
%let SPFinitMirrorMD = https://raw.githubusercontent.com/yabwon/SAS_PACKAGES/main/SPF/SPFinit.md;
%let sourcePath = https://raw.githubusercontent.com/yabwon/SAS_PACKAGES/main/packages/;
%if 0 = %superq(mirror) %then
%do;
%let SPFinitMirror = https://raw.githubusercontent.com/yabwon/SAS_PACKAGES/main/SPF/SPFinit.sas;
%let SPFinitMirrorMD = https://raw.githubusercontent.com/yabwon/SAS_PACKAGES/main/SPF/SPFinit.md;
%let sourcePath = https://github.com/SASPAC/; /*usercontent*/
%goto mirrorEnd;
%end;
%if 1 = %superq(mirror) %then
%do;
%let SPFinitMirror = https://raw.githubusercontent.com/yabwon/SAS_PACKAGES/main/SPF/SPFinit.sas;
%let SPFinitMirrorMD = https://raw.githubusercontent.com/yabwon/SAS_PACKAGES/main/SPF/SPFinit.md;
%let sourcePath = https://raw.githubusercontent.com/yabwon/SAS_PACKAGES/main/packages/;
%goto mirrorEnd;
%end;
%if 2 = %superq(mirror) %then
%do;
%let SPFinitMirror = https://pages.mini.pw.edu.pl/~jablonskib/SASpublic/SAS_PACKAGES/SPF/SPFinit.sas;
%let SPFinitMirrorMD = https://pages.mini.pw.edu.pl/~jablonskib/SASpublic/SAS_PACKAGES/SPF/SPFinit.md;
%let sourcePath = https://pages.mini.pw.edu.pl/~jablonskib/SASpublic/SAS_PACKAGES/packages/;
%goto mirrorEnd;
%end;
%mirrorEnd:
%put INFO: Source path is &sourcePath.;
%end;
%else
%do;
%let mirror=-1;
%let SPFinitMirror = &sourcePath.SPFinit.sas;
%let SPFinitMirrorMD = &sourcePath.SPFinit.md;
%end;
%local i str;
/* standardise list of packages */
%let str = %qsysfunc(compress(%superq(packagesNames),[{(. _)}],kad));
%let str = %qsysfunc(translate(%superq(str),[[]],{()}));
%let str = %qsysfunc(transtrn(%superq(str),],%str(] )));
%let str = %qsysfunc(compbl(%superq(str)));
%let str = %qsysfunc(transtrn(%superq(str),%str([ ),[));
%let str = %qsysfunc(transtrn(%superq(str),%str( [),[));
%let str = %qsysfunc(transtrn(%superq(str),%str( ]),]));
%let str = %unquote(&str.);
%let packagesNames = %qsysfunc(translate(%superq(str),(),[]));
%if %length("%sysfunc(compress(%superq(str),[,k))") NE %length("%sysfunc(compress(%superq(str),],k))") %then
%do;
%put ERROR: Syntax error in list of packages!;
%put ERROR- %superq(packagesNames);
%goto packagesListError;
%end;
%put ;
%put INFO: Calling: &packagesNames.;
%Local PackagesInstalledSussess PackagesInstalledFail;
%Let PackagesInstalledSussess=;
%let PackagesInstalledFail=;
%do i = 1 %to %sysfunc(countw(&packagesNames., , S));
/*-++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-*/
%local packageName packageSubDir vers versA versB;
%put ;
/*%put ### %scan(&packagesNames., &i., , S) ###;*/
%let packageName = %scan(%scan(&packagesNames., &i., , S),1,{[()]});
%let versA = %scan(%scan(&packagesNames., &i., , S),2,{[()]});
%let versB = %scan(&version., &i., , S);
%let vers=;
%if %superq(versB) ne %then %let vers = &versB.;
%if %superq(versA) ne %then %let vers = &versA.;
%if -1 = &mirror %then /* ignore version when direct path is provided */
%do;
%let vers=;
%end;
%put ### &packageName.(&vers.) ###;
%put *** %lowcase(&packageName.) start *****************************************;
%local in out inMD outMD _IOFileref_;
data _null_; call symputX("_IOFileref_", put(MD5("%lowcase(&packageName.)"), hex7. -L), "L"); run;
%let in = i&_IOFileref_.;
%let out = o&_IOFileref_.;
%let inMD = j&_IOFileref_.;
%let outMD = u&_IOFileref_.;
/* %let in = i%sysfunc(md5(&packageName.),hex7.); */
/* %let out = o%sysfunc(md5(&packageName.),hex7.); */
/*options MSGLEVEL=i;*/
%if %upcase(&packageName.) in (SPFINIT SASPACKAGEFRAMEWORK SASPACKAGESFRAMEWORK) %then
%do;
/* allows to install/download the framework file like any other package */