forked from Jiangtang/SAS_ListProcessing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnodup.sas
66 lines (56 loc) · 2.2 KB
/
nodup.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
/*<pre><b>
/ Program : nodup.sas
/ Version : 1.0
/ Author : Roland Rashleigh-Berry (http://www.datasavantconsulting.com/roland/)
/ Date : 04-May-2011
/ Purpose : Function-style macro to drop duplicates in a space-delimited list
/ SubMacros : %words
/ Notes :
/ Usage : %let str=%nodup(aaa bbb aaa);
/ %put %nodup(aaa bbb aaa);
/
/===============================================================================
/ PARAMETERS:
/-------name------- -------------------------description------------------------
/ list (pos) space-delimited list of items
/ casesens=no Case sensitive. no by default.
/===============================================================================
/ AMENDMENT HISTORY:
/ init --date-- mod-id ----------------------description------------------------
/ rrb 29Mar07 Put out "macro called" message plus header tidy
/ rrb 31Jul07 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 nodup(list,casesens=no);
%local i j match item errflag err;
%let err=ERR%str(OR);
%let errflag=0;
%if not %length(&casesens) %then %let casesens=no;
%let casesens=%upcase(%substr(&casesens,1,1));
%if not %index(YN,&casesens) %then %do;
%put &err: (nodup) casesens must be set to yes or no;
%let errflag=1;
%end;
%if &errflag %then %goto exit;
%do i=1 %to %words(&list);
%let item=%scan(&list,&i,%str( ));
%let match=NO;
%if &i LT %words(&list) %then %do;
%do j=%eval(&i+1) %to %words(&list);
%if &casesens EQ Y %then %do;
%if "&item" EQ "%scan(&list,&j,%str( ))" %then %let match=YES;
%end;
%else %do;
%if "%upcase(&item)" EQ "%upcase(%scan(&list,&j,%str( )))" %then %let match=YES;
%end;
%end;
%end;
%if &match EQ NO %then &item;
%end;
%goto skip;
%exit: %put &err: (nodup) Leaving macro due to problem(s) listed;
%skip:
%mend nodup;