Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mp_getmaxvarlengths.test.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Testing mp_getmaxvarlengths macro
4
5 <h4> SAS Macros </h4>
6 @li mp_getmaxvarlengths.sas
7 @li mp_assert.sas
8 @li mp_assertdsobs.sas
9 @li mp_assertscope.sas
10
11**/
12
13data work.class ;
14attrib
15Name length= $8
16Sex length= $1
17Age length= 8
18Height length= 8
19Weight length= 8
20;
21infile cards dsd;
22input
23 Name :$char.
24 Sex :$char.
25 Age
26 Height
27 Weight
28;
29datalines4;
30Alfred,M,14,69,112.5
31Alice,F,13,56.5,84
32Barbara,F,13,65.3,98
33Carol,F,14,62.8,102.5
34Henry,M,14,63.5,102.5
35James,M,12,57.3,83
36Jane,F,12,59.8,84.5
37Janet,F,15,62.5,112.5
38Jeffrey,M,13,62.5,84
39John,M,12,59,99.5
40Joyce,F,11,51.3,50.5
41Judy,F,14,64.3,90
42Louise,F,12,56.3,77
43Mary,F,15,66.5,112
44Philip,M,16,72,150
45Robert,M,12,64.8,128
46Ronald,M,15,67,133
47Thomas,M,11,57.5,85
48William,M,15,66.5,112
49;;;;
50run;
51
52/* regular usage */
53%mp_assertscope(SNAPSHOT)
54%mp_getmaxvarlengths(work.class,outds=work.myds)
55%mp_assertscope(COMPARE,desc=checking scope leakage on mp_getmaxvarlengths)
56%mp_assert(
57 iftrue=(&syscc=0),
58 desc=No errs
59)
60%mp_assertdsobs(work.myds,
61 desc=Has 5 records,
62 test=EQUALS 5
63)
64data work.errs;
65 set work.myds;
66 if name='Name' and maxlen ne 7 then output;
67 if name='Sex' and maxlen ne 1 then output;
68 if name='Age' and maxlen ne 3 then output;
69 if name='Height' and maxlen ne 8 then output;
70 if name='Weight' and maxlen ne 3 then output;
71run;
72data _null_;
73 set work.errs;
74 putlog (_all_)(=);
75run;
76
77%mp_assertdsobs(work.errs,
78 desc=Err table has 0 records,
79 test=EQUALS 0
80)
81
82/* test2 */
83data work.test2;
84 length a 3 b 5;
85 a=1/3;
86 b=1/3;
87 c=1/3;
88 d=._;
89 e=.;
90 output;
91 output;
92run;
93%mp_getmaxvarlengths(work.test2,outds=work.myds2)
94%mp_assert(
95 iftrue=(&syscc=0),
96 desc=No errs in second test (with nulls)
97)
98%mp_assertdsobs(work.myds2,
99 desc=Has 5 records,
100 test=EQUALS 5
101)
102data work.errs2;
103 set work.myds2;
104 if name='a' and maxlen ne 3 then output;
105 if name='b' and maxlen ne 5 then output;
106 if name='c' and maxlen ne 8 then output;
107 if name='d' and maxlen ne 3 then output;
108 if name='e' and maxlen ne 0 then output;
109run;
110data _null_;
111 set work.errs2;
112 putlog (_all_)(=);
113run;
114
115%mp_assertdsobs(work.errs2,
116 desc=Err table has 0 records,
117 test=EQUALS 0
118)