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)
198
199/**
200 * Test 5 - ISPATH
201 *
202 * Shape only: /tmp passes on Unix whether or not it is mounted, and a
203 * relative path never passes. Both platform shapes are in the fixture so the
204 * branch that runs is always the one being asserted - four of these are
205 * Windows-only (drive, forward-slash drive, UNC, and a second drive), and on
206 * Windows none of the Unix absolutes pass.
207 */
208data test5;
209 infile datalines4 truncover;
210 length pathval $1000;
211 input pathval $char1000.;
212 %mp_validatecol(pathval,ISPATH,is_path)
213 if is_path=1;
214datalines4;
215/tmp
216/
217/tmp/a b/c-d_e.txt
218tmp
219./tmp
220a/b
221C:\folder
222C:/folder
223\\server\share
224D:\data\2024
225C:folder
226\folder
227C:\a?b
228C:\a"b
229;;;;
230run;
231
232data _null_;
233 if "%upcase(&sysscp)" in ('WIN','DNTHOST') then call symputx('pathexp',4,'g');
234 else call symputx('pathexp',3,'g');
235run;
236
237%mp_assertdsobs(work.test5,
238 desc=Test5 - ISPATH keeps only absolute paths,
239 test=EQUALS &pathexp,
240 outds=work.test_results
241)
242
243/**
244 * Test 6 - ISNAME
245 */
246data test6;
247 infile datalines4 dsd;
248 input;
249 inf=_infile_;
250 %mp_validatecol(inf,ISNAME,isname)
251 if isname=1;
252datalines4;
253somename
254_underscore_start
255name_with_32_characters_exactly_
256UPPERCASE
257MixedCase99
258above are ok - below are not ok
259name_with_33_characters_exactly_x
260!name
261%abort
2622fail
263.fail
264has spaces
265has-hyphen
266has.dot
267&badness
268;;;;
269run;
270%mp_assertdsobs(work.test6,
271 desc=Testing ISNAME,
272 test=EQUALS 5,
273 outds=work.test_results
274)
275
276/**
277 * Test 5 - ISPATH
278 *
279 * Shape only: /tmp passes on Unix whether or not it is mounted, and a
280 * relative path never passes. The fixture is the same everywhere; the count
281 * differs by platform (a leading / is not absolute on Windows).
282 */
283data test5;
284 infile datalines4 dsd truncover;
285 length pathval $1000;
286 input pathval $char1000.;
287 %mp_validatecol(pathval,ISPATH,is_path)
288 if is_path=1;
289datalines4;
290/tmp
291/
292/tmp/a b/c-d_e.txt
293tmp
294./tmp
295a/b
296;;;;
297run;
298
299data _null_;
300 if "%upcase(&sysscp)" in ('WIN','DNTHOST') then call symputx('pathexp',0,'g');
301 else call symputx('pathexp',3,'g');
302run;
303
304%mp_assertdsobs(work.test5,
305 desc=Test5 - ISPATH keeps only absolute paths,
306 test=EQUALS &pathexp,
307 outds=work.test_results
308)