-
Notifications
You must be signed in to change notification settings - Fork 2
/
_count.sas
83 lines (63 loc) · 2.5 KB
/
_count.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
%put NOTE: You have called the macro _COUNT, 2022-06-07.;
%put NOTE: Copyright (c) 2001-2022 Rodney Sparapani;
%put;
/*
Author: Rodney Sparapani <[email protected]>
Created: 2001-00-00
This file is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This file is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this file; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* _COUNT Documentation
Returns the count of individual items in a list.
POSITIONAL Parameters
ARG1 list to be counted
NAMED Parameters
NOTES= default is to not display the returned value in a NOTE,
if set to something, then do display
SPLIT= split character that separates items,
defaults to blank
TEXT=ARG1 alias
*/
%macro _count(arg1, text=&arg1, notes=, split=%str( ));
%local i;
%let i=0;
%*do %while(%length(%nrbquote(%scan(%nrbquote(&text), &i+1, &split))));
%do %while(%length(%qscan(&text, &i+1, &split)));
%let i=%eval(&i+1);
%end;
%if "%_substr(%superq(syswarningtext), 1, 27)"="Apparent symbolic reference"
%then %do;
%put ERROR: _COUNT() cannot recover from warning: ABEND;
%_abend();
%end;
%else &i;
%if %length(¬es) %then %put NOTE: _COUNT is returning the value: &i.;
%mend _count;
%*VALIDATION TEST STREAM.;
/* un-comment to re-validate
%put NOTE: RETURN CODE=%_count('1 2 3 4 5');
%put NOTE: RETURN CODE=%_count(1 2 3 4 5);
%put NOTE: RETURN CODE=%_count( 1 2 3 4 5 );
%put NOTE: RETURN CODE=%_count( 1 2 3 4 5 );
%put NOTE: RETURN CODE=%_count( (1 2 3 4 5) );
%put NOTE: RETURN CODE=%_count( (1 2 3 4 5) , split=());
%let test=1 2 3 4 5;
%put NOTE: RETURN CODE=%_count(&test);
%put NOTE: RETURN CODE=%_count(&test, notes=1);
%put NOTE: RETURN CODE=%_count(1%str(,)2%str(,)3%str(,)4%str(,)5, split=%str(,));
%put NOTE: RETURN CODE=%_count(=state='WI', split=''=);
%put NOTE: RETURN CODE=%_count(¬avar);
endsas;
Local Variables:
ess-sas-submit-command-options: "-noautoexec"
End:
*/