forked from Jiangtang/SAS_ListProcessing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwords.sas
38 lines (36 loc) · 1.64 KB
/
words.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
/*<pre><b>
/ Program : words.sas
/ Version : 3.2
/ Author : Roland Rashleigh-Berry (http://www.datasavantconsulting.com/roland/)
/ Date : 09-Jan-2013
/ Purpose : Function-style macro to return the number of words in a string
/ SubMacros : none
/ Notes : You can change the delimiter to other than a space if required.
/ Usage : %put %words(a b c d e);
/===============================================================================
/ PARAMETERS:
/-------name------- -------------------------description------------------------
/ str String (pos) UNQUOTED
/ delim=%str( ) Delimeter (defaults to a space)
/===============================================================================
/ AMENDMENT HISTORY:
/ init --date-- mod-id ----------------------description------------------------
/ rrb 13Feb07 "macro called" message added
/ rrb 30Jul07 Header tidy
/ rrb 26Sep08 "countw" used for sas version 9 onwards for v2.0
/ rrb 01Sep09 Use of countw() function discontinued (v3.0)
/ rrb 04May11 Code tidy
/ rrb 02Jan13 Use of %qscan dropped (v3.1)
/ rrb 09Jan13 Use of %qscan reinstated (v3.2)
/===============================================================================
/ 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 words(str,delim=%str( ));
%local i;
%let i=1;
%do %while(%length(%qscan(&str,&i,&delim)) GT 0);
%let i=%eval(&i + 1);
%end;
%eval(&i - 1)
%mend words;