Skip to content

Commit ae1a40f

Browse files
committed
update readme
1 parent e364395 commit ae1a40f

File tree

6 files changed

+122
-101
lines changed

6 files changed

+122
-101
lines changed

README.md

Lines changed: 76 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,76 @@
1-
SAS_ListProcessing
2-
==================
3-
/*===================================================================================
4-
| SAS List Processing Utility Macros
5-
|
6-
| Author: see individual snippets
7-
| Collector: Jiangtang Hu (Jiangtanghu.com)
8-
| Archived: https://github.com/Jiangtang/Programming-SAS/tree/master/ListProcessing
9-
|
10-
+-------List Creating---------------------------------------------------------------
11-
|
12-
| %range: produces a sequence like 1 2 3 or f1 f2 f3 or 1a 2a 3a
13-
| %range_non_int: increment a macro do loop by a non-integer value
14-
| %suffix_counter: Create a list of variable names formed by adding a numeric counter suffix to a base name.
15-
|
16-
| %getVar: get all variables (N, C or all) from a dataset
17-
|
18-
| %qreadpipe: read the output of a system command
19-
| %dir: return a list of members of a directory
20-
| %dirfpq: return a list of full-path quoted members of a directory
21-
|
22-
|
23-
+-------List Formating---------------------------------------------------------------
24-
|
25-
| %changesep: change the separator for a list
26-
| %seplist: Emit a list of items separated by some delimiter
27-
|
28-
| %splitmac: insert split characters in a macro string
29-
|
30-
| %capmac: capitalise the first letter of each word in a macro string
31-
|
32-
+-------quoting---------------------------------------------------------------
33-
|
34-
| %qt: add quotes to each element in a list
35-
| %quotelst: quote the elements of a list
36-
|
37-
| %upt: remove quotes from each element of a list
38-
| %qdequote: remove front and end matching quotes from a macro string
39-
| %dequote: remove front and end matching quotes from a macro string
40-
|
41-
| %noquotes: remove all quoted strings from a macro expression
42-
|
43-
| %quotecnt: count quoted strings in a macro expression
44-
|
45-
| %quotescan: scan for a quoted string in a macro expression
46-
|
47-
|
48-
+-------List Properties-----------------------------------------------------------
49-
|
50-
| %num_tokens: Count the number of “tokens” (variables) in a list.
51-
| %countW: Retrieve the number of words in a macro variable
52-
| %words: return the number of words in a string
53-
| %windex: return the word count position in a string
54-
|
55-
|
56-
|
57-
|
58-
+-------List Manipulation-----------------------------------------------------------
59-
|
60-
| %slice: return a sub-list sliced by a index
61-
|
62-
|
63-
| %zip: zips two lists together by joining correponding elements, see, a b and c d ==> ac bd
64-
| %parallel_join: Join two variable lists by connecting each variable in the first list to its correspondingvariable in the second list
65-
| %add_string: Add a text string to each variable in a list as either a prefix or suffix
66-
| %xprod: take cross product of two lists, see, a b and c d ==> ac ad bc bd
67-
|
68-
| %appmvar: append a string onto an existing macro variable
69-
| %prefix: return a list with a prefix added
70-
| %suffix: return a list with a suffix added
71-
|
72-
|
73-
|
74-
|
75-
| %replace: replace symbolic variable in block of code with each element of a list, see, a b and code = #=__# ==> a=__a b=__b
76-
| %rename_string: Create a list suitable for the rename statement
77-
| %editlist: edit a list of space delimited items
78-
|
79-
| %nodup: drop duplicates in a space-delimited list
80-
|
81-
| %match: return elements of a list that match those in a reference list
82-
|
83-
| %remove: remove all occurrences of the target string(s) from another string
84-
| %removew: remove all occurrences of the target word(s) from a source list of words.
85-
|
86-
| %reverse: Reverse a macro variable's value (use %sysfunc(reverse) since v6.12)
87-
|
88-
|
89-
|
90-
+==================================================================================*/
1+
ho# SAS List Processing Utility Macros
2+
3+
##### Author: see individual macros
4+
##### Collector: Jiangtang Hu ([www.Jiangtanghu.com](http://www.Jiangtanghu.com))
5+
##### Archived: https://github.com/Jiangtang/Programming-SAS/tree/master/ListProcessing
6+
7+
## List Creating
8+
9+
* %range: produces a sequence like 1 2 3 or f1 f2 f3 or 1a 2a 3a
10+
* %range\_non\_int: increment a macro do loop by a non-integer value
11+
* %suffix_counter: Create a list of variable names formed by adding a numeric counter suffix to a base name.
12+
13+
* %getVar: get all variables (N, C or all) from a dataset
14+
15+
* %qreadpipe: read the output of a system command
16+
* %dir: return a list of members of a directory
17+
* %dirfpq: return a list of full-path quoted members of a directory
18+
19+
## List Formating
20+
21+
* %changesep: change the separator for a list
22+
* %seplist: Emit a list of items separated by some delimiter
23+
24+
* %splitmac: insert split characters in a macro string
25+
26+
* %capmac: capitalise the first letter of each word in a macro string
27+
28+
## quoting
29+
30+
* %qt: add quotes to each element in a list
31+
* %quotelst: quote the elements of a list
32+
33+
* %upt: remove quotes from each element of a list
34+
* %qdequote: remove front and end matching quotes from a macro string
35+
* %dequote: remove front and end matching quotes from a macro string
36+
37+
* %noquotes: remove all quoted strings from a macro expression
38+
39+
* %quotecnt: count quoted strings in a macro expression
40+
41+
* %quotescan: scan for a quoted string in a macro expression
42+
43+
## List Properties
44+
45+
* %num_tokens: Count the number of “tokens” (variables) in a list.
46+
* %countW: Retrieve the number of words in a macro variable
47+
* %words: return the number of words in a string
48+
* %windex: return the word count position in a string
49+
50+
51+
##List Manipulation
52+
53+
* %slice: return a sub-list sliced by a index
54+
55+
* %zip: zips two lists together by joining correponding elements, see, a b and c d ==> ac bd
56+
* %parallel_join: Join two variable lists by connecting each variable in the first list to its correspondingvariable in the second list
57+
* %add_string: Add a text string to each variable in a list as either a prefix or suffix
58+
* %xprod: take cross product of two lists, see, a b and c d ==> ac ad bc bd
59+
60+
* %appmvar: append a string onto an existing macro variable
61+
* %prefix: return a list with a prefix added
62+
* %suffix: return a list with a suffix added
63+
64+
* %replace: replace symbolic variable in block of code with each element of a list, see, a b and code = #=__# ==> a=__a b=__b
65+
* %rename_string: Create a list suitable for the rename statement
66+
* %editlist: edit a list of space delimited items
67+
68+
* %nodup: drop duplicates in a space-delimited list
69+
70+
* %match: return elements of a list that match those in a reference list
71+
72+
* %remove: remove all occurrences of the target string(s) from another string
73+
* %removew: remove all occurrences of the target word(s) from a source list of words.
74+
75+
* %reverse: Reverse a macro variable's value (use %sysfunc(reverse) since v6.12)
76+

dir.sas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
/ which will correctly handle file names containing spaces.
1414
/ Usage : %let dirlist=%dir(C:\utilmacros);
1515
/ %let dirlist=%dir(C:\utilmacros\*.sas);
16-
/ %put dirlist=%dir(a:\test);
16+
/ %put dirlist=%dir(d:\test);
1717
/===============================================================================
1818
/ PARAMETERS:
1919
/-------name------- -------------------------description------------------------

dirfpq.sas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
/ Usage : %let dirlist=%dirfpq(C:\utilmacros); %*- NO GOOD -;
1616
/ %let dirlist=%dirfpq(C:\utilmacros\*); %*- GOOD -;
1717
/ %let dirlist=%dirfpq(C:\utilmacros\*.sas); %*- GOOD -;
18-
/ %put %dirfpq(a:\test\*.gif);
18+
/ %put %dirfpq(d:\test\*.gif);
1919
/===============================================================================
2020
/ PARAMETERS:
2121
/-------name------- -------------------------description------------------------

range.sas

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,52 @@ examples:
1818
%put %range(from=2,to=10,step=3,osep=%str(,));
1919
%put %range(from=2,to=10,step=3,osep=%str(,),osuf=%str(a));
2020
21+
data a1;
22+
a1=1;
23+
run;
24+
25+
data a2;
26+
a2=2;
27+
run;
28+
29+
data a3;
30+
a3=3;
31+
run;
32+
33+
%macro doit;
34+
%let n=3;
35+
data combine1;
36+
set %do i=1 %to &n; a&i %end; ;
37+
run;
38+
%mend;
39+
%doit
40+
41+
%macro doit;
42+
data combine2;
43+
set %range(to=3,opre=%str(a));
44+
run;
45+
%mend;
46+
%doit
47+
48+
%macro doit;
49+
proc sql;
50+
create table combine3 as
51+
select *
52+
from %range(to=3,osep=%str(,),opre=%str(a));
53+
quit;
54+
%mend;
55+
%doit
56+
2157
Credit:
2258
source code from Ian Whitlock, Names, Names, Names - Make Me a List
2359
(SGF 2007) http://www2.sas.com/proceedings/forum2007/052-2007.pdf
2460
(SESUG 2008) http://analytics.ncsu.edu/sesug/2008/SBC-128.pdf
2561
This snippet used a more efficient style from Chang Chung(http://changchung.com)
2662
Jiangtang Hu (2013, http://www.jiangtanghu.com):
27-
1)used %let rg_i = ; to initiate the macro variable rather than %local rg_i;
28-
2)added two parameters (prefix/suffix) so it works more than generating sequence of integers
29-
3)archived in https://github.com/Jiangtang/Programming-SAS/tree/master/ListProcessing
63+
1)added two parameters (prefix/suffix) so it works more than generating sequence of integers
3064
*/
3165

32-
%let rg_i = ;
66+
%local rg_i ;
3367
%do rg_i = &from %to &to %by &step ;
3468
%if &rg_i = &from %then
3569
%do;&opre.&rg_i.&osuf%end ;

range_non_int.sas

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11

22
/*
3+
examples:
34
%put %range_non_int(start = 1 , end = 5 , by = .25 ) ;
45
5-
http://support.sas.com/kb/37/536.html
6-
modified by Jiangtang Hu (jiangtanghu.com)
6+
Source: http://support.sas.com/kb/37/536.html
7+
Modified by Jiangtang Hu (2013, http://www.jiangtanghu.com)
78
89
*/
910

suffix_counter.sas

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
1212
Examples:
1313
%put %suffix_counter(v, 4);
14-
produces the text v1 v2 v3 v4
14+
*produces the text v1 v2 v3 v4;
1515
%put %suffix_counter(v, 14, start=10);
16-
produces the text v10 v11 v12 v13 v14
16+
*produces the text v10 v11 v12 v13 v14;
1717
%put %suffix_counter(v, 4, zpad=2);
18-
produces the text v01 v02 v03 v04
18+
*produces the text v01 v02 v03 v04;
1919
2020
Credit:
2121
source code from Robert J. Morris, Text Utility Macros for Manipulating Lists of Variable Names

0 commit comments

Comments
 (0)