forked from Jiangtang/SAS_ListProcessing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindex.sas
41 lines (39 loc) · 1.53 KB
/
windex.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
/*<pre><b>
/ Program : windex.sas
/ Version : 1.1
/ Author : Roland Rashleigh-Berry (http://www.datasavantconsulting.com/roland/)
/ Date : 04-May-2011
/ Purpose : Function-style macro to return the word count position in a string
/ SubMacros : %words
/ Notes : none
/ Usage : %let windex=%windex(string,target);
/ %put %windex(Word worde,worde);
/
/===============================================================================
/ PARAMETERS:
/-------name------- -------------------------description------------------------
/ str String (pos) UNQUOTED
/ target Target string (pos) UNQUOTED
/===============================================================================
/ AMENDMENT HISTORY:
/ init --date-- mod-id ----------------------description------------------------
/ rrb 13Feb07 "macro called" message added
/ rrb 10May07 Break loop if match is found (v1.1)
/ 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 windex(str,target);
%local i res words;
%let res=0;
%let words=%words(&str);
%do i=1 %to &words;
%if "%scan(&str,&i,%str( ))" EQ "&target" %then %do;
%let res=&i;
%let i=&words;
%end;
%end;
&res
%mend windex;