forked from Jiangtang/SAS_ListProcessing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquotelst.sas
51 lines (49 loc) · 2.57 KB
/
quotelst.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
/*<pre><b>
/ Program : quotelst.sas
/ Version : 1.1
/ Author : Roland Rashleigh-Berry (http://www.datasavantconsulting.com/roland/)
/ Date : 04-May-2011
/ Purpose : Function-style macro to quote the elements of a list
/ SubMacros : none
/ Notes : DO NOT COPY AND PASTE THIS FROM THIS BROWSER WINDOW. YOU MUST USE
/ THE "VIEW" PULL-DOWN WINDOW AND USE "SOURCE". This is because the
/ browser will change some of the characters in this file to quotes.
/
/ This is useful to turn a list into a quoted list so that you can
/ use the in() function on it in a data step. Also, if you search for
/ a quoted string among a list of quoted strings then you can avoid
/ matching on a subset of a single element. Note that you can change
/ not only the quote mark but the delimiter as well so you can use
/ this macro for other purposes like putting commas between variable
/ names etc. It is assumed that the elements of the list are
/ delimited by spaces.
/ Usage : %put %quotelst(a b c d);
/
/===============================================================================
/ PARAMETERS:
/-------name------- -------------------------description------------------------
/ str String to quote elements of (pos)
/ quote=%str(%") Quote character to use (defaults to double quotation mark)
/ delim=%str( ) Delimiter character to use (defaults to a space)
/===============================================================================
/ AMENDMENT HISTORY:
/ init --date-- mod-id ----------------------description------------------------
/ rrb 13Feb07 "macro called" message added
/ rrb 30Jul07 Header tidy
/ rrb 21May08 Use of %scan replaced by %qscan
/ 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 quotelst(str,quote=%str(%"),delim=%str( ));
%local i quotelst;
%let i=1;
%do %while(%length(%qscan(&str,&i,%str( ))) GT 0);
%if %length("elst) EQ 0 %then %let quotelst="e.%qscan(&str,&i,%str( ))"e;
%else %let quotelst="elst."e.%qscan(&str,&i,%str( ))"e;
%let i=%eval(&i + 1);
%if %length(%qscan(&str,&i,%str( ))) GT 0 %then %let quotelst="elst.&delim;
%end;
%unquote("elst)
%mend quotelst;