forked from Jiangtang/SAS_ListProcessing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoquotes.sas
68 lines (58 loc) · 2.35 KB
/
noquotes.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
/*<pre><b>
/ Program : noquotes.sas
/ Version : 1.0
/ Author : Roland Rashleigh-Berry (http://www.datasavantconsulting.com/roland/)
/ Date : 04-May-2011
/ Purpose : Function-style macro to remove all quoted strings from a macro
/ expression.
/ SubMacros : none
/ Notes : This gets rid of all quoted strings and returns what is left.
/ Usage : %let noquotes=%noquotes(&str);
/ %put %noquotes(%str(a e "c" e));
/
/===============================================================================
/ PARAMETERS:
/-------name------- -------------------------description------------------------
/ str (pos) String
/===============================================================================
/ AMENDMENT HISTORY:
/ init --date-- mod-id ----------------------description------------------------
/ rrb 29Mar07 Put out "macro called" message plus header tidy
/ 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 noquotes(str);
%local i pos1 pos2 qtype tempstr;
%let tempstr=&str;
%redo:
%let pos1=0;
%let pos2=0;
%let qtype=;
%do i=1 %to %length(&tempstr);
%if &pos1 EQ 0 %then %do;
%if %qsubstr(&tempstr,&i,1) EQ %str(%')
or %qsubstr(&tempstr,&i,1) EQ %str(%") %then %do;
%let pos1=&i;
%let qtype=%qsubstr(&tempstr,&i,1);
%end;
%end;
%else %if (&pos1 GT 0) and (&pos2 EQ 0) %then %do;
%if %qsubstr(&tempstr,&i,1) EQ %str(&qtype) %then %let pos2=&i;
%end;
%end;
%if (&pos1 GT 0) and (&pos2 GT 0) %then %do;
%if (&pos1 GT 1) and (&pos2 LT %length(&tempstr)) %then
%let tempstr=%qsubstr(&tempstr,1,&pos1-1)%qsubstr(&tempstr,&pos2+1);
%else %if (&pos1 EQ 1) and (&pos2 LT %length(&tempstr)) %then
%let tempstr=%qsubstr(&tempstr,&pos2+1);
%if (&pos1 GT 1) and (&pos2 EQ %length(&tempstr)) %then
%let tempstr=%qsubstr(&tempstr,1,&pos1-1);
%else %if (&pos1 EQ 1) and (&pos2 EQ %length(&tempstr)) %then
%let tempstr=;
%if %length(&tempstr) %then %goto redo;
%end;
&tempstr
%mend noquotes;