Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mp_validatecol.test.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Testing mp_validatecol.sas macro
4
5 <h4> SAS Macros </h4>
6 @li mp_assertdsobs.sas
7 @li mp_validatecol.sas
8
9**/
10
11
12/**
13 * Test 1 - LIBDS
14 */
15data test1;
16 infile datalines4 dsd;
17 input;
18 libds=_infile_;
19 %mp_validatecol(libds,LIBDS,is_libds)
20 if is_libds=1;
21datalines4;
22some.libname
23!lib.blah
24%abort
25definite.ok
26not.ok!
27nineletrs._
28;;;;
29run;
30%mp_assertdsobs(work.test1,
31 desc=Testing LIBDS,
32 test=EQUALS 2,
33 outds=work.test_results
34)
35
36/**
37 * Test 2 - ISNUM
38 */
39data test2;
40 infile datalines4 dsd;
41 input;
42 infile=_infile_;
43 %mp_validatecol(infile,ISNUM,is_numeric)
44 if is_numeric=1;
45datalines4;
461
470001
481e6
49-44
50above are good
51the rest are bad
52%abort
531&somethingverybad.
54&
55+-1
56;;;;
57run;
58%mp_assertdsobs(work.test2,
59 desc=Test2 - ISNUM,
60 test=EQUALS 4,
61 outds=work.test_results
62)
63
64/**
65 * Test 3 - FORMAT
66 */
67data test3;
68 infile datalines4 dsd;
69 input;
70 infile=_infile_;
71 %mp_validatecol(infile,FORMAT,is_format)
72 if is_format=1;
73datalines4;
74$.
75$format.
76$format12.2
77somenum.
78somenum12.4
794.
808.2
8112.
82above are good
83the rest are bad
84%abort
851&somethingverybad.
86&
87+-1
88.
89a.A
90$format12.1b
91$format12.1b1
921
9312
940
95;;;;
96run;
97%mp_assertdsobs(work.test3,
98 desc=Test3 - ISFORMAT,
99 test=EQUALS 8,
100 outds=work.test_results
101)
102
103/**
104 * Test 4 - ISINT
105 */
106data test4;
107 infile datalines4 dsd;
108 input;
109 infile=_infile_;
110 %mp_validatecol(infile,ISINT,is_integer)
111 if is_integer=1;
112datalines4;
1131
1141234
115-134
116-1.0
1171.0
1180
119above are good
120the rest are bad
1210.1
1221.1
123-0.001
124%abort
1251&somethingverybad.
126&
127+-1
128.
129a.A
130$format12.1b
131$format12.1b1
132;;;;
133run;
134%mp_assertdsobs(work.test4,
135 desc=Test4 - ISFORMAT,
136 test=EQUALS 6,
137 outds=work.test_results
138)
139
140/**
141 * Test 5 - ISLIB
142 */
143data test5;
144 infile datalines4 dsd;
145 input;
146 inf=_infile_;
147 %mp_validatecol(inf,ISLIB,islib)
148 if islib=1;
149datalines4;
150some
151!lib
152%abort
153definite
1542fail
155nineletrs
156.failalso
157_valid
158;;;;
159run;
160%mp_assertdsobs(work.test5,
161 desc=Testing ISLIB,
162 test=EQUALS 3,
163 outds=work.test_results
164)
165
166/**
167 * Test 6 - ISNAME
168 */
169data test6;
170 infile datalines4 dsd;
171 input;
172 inf=_infile_;
173 %mp_validatecol(inf,ISNAME,isname)
174 if isname=1;
175datalines4;
176somename
177_underscore_start
178name_with_32_characters_exactly_
179UPPERCASE
180MixedCase99
181above are ok - below are not ok
182name_with_33_characters_exactly_x
183!name
184%abort
1852fail
186.fail
187has spaces
188has-hyphen
189has.dot
190&badness
191;;;;
192run;
193%mp_assertdsobs(work.test6,
194 desc=Testing ISNAME,
195 test=EQUALS 5,
196 outds=work.test_results
197)