forked from Jiangtang/SAS_ListProcessing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslice.sas
More file actions
29 lines (23 loc) · 768 Bytes
/
slice.sas
File metadata and controls
29 lines (23 loc) · 768 Bytes
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
%macro slice(
L, /*list*/
i, /*index*/
sep_L=%str( ),/*separator for list*/
sep_i=%str( ) /*separator for index*/
);
/*
return a sub-list sliced by an index
examples(all produce a c d):
%put %slice(a b c d,1 3 4);
%put %slice(%str(a, b, c, d),1 3 4,sep_L=%str(,));
%put %slice(%str(a, b, c, d),%str(1, 3, 4),sep_L=%str(,),sep_i=%str(,));
Credit:
Jiangtang Hu (2013-03-31, http://www.jiangtanghu.com):
*/
%let VarList = ;
%let count=%sysfunc(countw(&i,&sep_i));
%do j = 1 %to &count;
%let index=%qscan(&i,&j,&sep_i);
%let VarList = &VarList.%str( )%qscan(&L,&index,&sep_L);
%end;
&VarList
%mend slice;