forked from Jiangtang/SAS_ListProcessing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove.sas
More file actions
90 lines (83 loc) · 3.05 KB
/
remove.sas
File metadata and controls
90 lines (83 loc) · 3.05 KB
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
/*<pre><b>
/ Program : remove.sas
/ Version : 1.0
/ Author : Roland Rashleigh-Berry (http://www.datasavantconsulting.com/roland/)
/ Date : 04-May-2011
/ Purpose : Function-style macro to remove all occurrences of the target
/ string(s) from another string.
/ SubMacros : none
/ Notes : none
/ Usage : %let string2=%remove(&string1,XXX,yyy,YYY);
/ %put %remove(aaa xxx yyy yyee,XXX,yyy,YYY);
/
/===============================================================================
/ PARAMETERS:
/-------name------- -------------------------description------------------------
/ string (pos - unquoted) String to remove target from
/ target1-30 (pos - unquoted) Target string(s) to remove
/ casesens=no Whether the search for the target(s) is case sensitive
/===============================================================================
/ AMENDMENT HISTORY:
/ init --date-- mod-id ----------------------description------------------------
/ rrb 13Feb07 "macro called" message added
/ rrb 30Jul07 Header tidy
/ rrb 04May11 Code tidy
/===============================================================================
/ This is public domain software. No guarantee as to suitability or accuracy is
/ given or implied. User uses this code entirely at their own risk.
/=============================================================================*/
%macro remove(string,
target1,
target2,
target3,
target4,
target5,
target6,
target7,
target8,
target9,
target10,
target11,
target12,
target13,
target14,
target15,
target16,
target17,
target18,
target19,
target20,
target21,
target22,
target23,
target24,
target25,
target26,
target27,
target28,
target29,
target30,
casesens=no
);
%local i result index targlen beyond newstr;
%if not %length(&casesens) %then %let casesens=no;
%let casesens=%upcase(%substr(&casesens,1,1));
%let result=&string;
%do i=1 %to 30;
%let targlen=%length(&&target&i);
%if &targlen %then %do;
%if "&casesens" EQ "Y" %then %let index=%index(&result,&&target&i);
%else %let index=%index(%qupcase(&result),%qupcase(&&target&i));
%do %while(&index GT 0);
%if &index GT 1 %then %let newstr=%qsubstr(&result,1,%eval(&index-1));
%else %let newstr=;
%let beyond=%eval(&index+&targlen);
%if &beyond LE %length(&result) %then %let newstr=&newstr%qsubstr(&result,&beyond);
%let result=&newstr;
%if "&casesens" EQ "Y" %then %let index=%index(&result,&&target&i);
%else %let index=%index(%qupcase(&result),%qupcase(&&target&i));
%end;
%end;
%end;
&result
%mend remove;