-
Notifications
You must be signed in to change notification settings - Fork 8
/
addformatlib.sas
65 lines (45 loc) · 2.35 KB
/
addformatlib.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
%macro AddFormatLib(libs) / des="Add a library to the fmtsearch option";
/********************************************************************************
BEGIN MACRO HEADER
********************************************************************************
Name: AddFormatLib
Author: Chris Swenson
Created: 2010-09-29
Purpose: Add a library to the format search system option (fmtsearch)
Arguments: libs - one or more libraries to add to the format search option
Revisions
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Date Author Comments
¯¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯
2011-08-19 CAS Revised to scan through argument to match the order
specified by the user.
YYYY-MM-DD III Please use this format and insert new entries above
********************************************************************************
END MACRO HEADER
********************************************************************************/
%let libs=%upcase(&libs);
%if "&libs"="" %then %do;
%put %str(E)RROR: No arguments specified.;
%return;
%end;
%local count fmtsearch addlibs i current changed;
%let count=%sysfunc(countw(&libs, %str( )));
%put NOTE: &COUNT references specified.;
%let fmtsearch=%upcase(%sysfunc(getoption(fmtsearch)));
%if "%substr(&FMTSEARCH, 1, 1)"="("
%then %let fmtsearch=%substr(&FMTSEARCH, 2, %length(%sysfunc(getoption(fmtsearch)))-2);
/* REVISION 2011-08-19 CAS: Revised to go backwords through list */
%do i=&COUNT %to 1 %by -1;
%let current=%scan(&libs, &i, %str( ));
%if %sysfunc(libref(¤t)) ne 0 %then %do;
%put %str(E)RROR: Specified library ¤t does not exist.;
%return;
%end;
%let changed=%sysfunc(tranwrd(&fmtsearch, %str( ), %str(*)));
%if %index(*&CHANGED*,*&CURRENT*)>0
%then %put NOTE: Specified library ¤t is already specified on the FMTSEARCH option.;
%else %let addlibs=&CURRENT &ADDLIBS;
%end;
option fmtsearch=(&fmtsearch &addlibs);
%put NOTE: Format Search Option (fmtsearch) = %sysfunc(getoption(fmtsearch));
%mend AddFormatLib;