Macros for SAS Application Developers
https://github.com/sasjs/core
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 
13 data work.class ;
14 attrib
15 Name length= $8
16 Sex length= $1
17 Age length= 8
18 Height length= 8
19 Weight length= 8
20 ;
21 infile cards dsd;
22 input
23  Name :$char.
24  Sex :$char.
25  Age
26  Height
27  Weight
28 ;
29 datalines4;
30 Alfred,M,14,69,112.5
31 Alice,F,13,56.5,84
32 Barbara,F,13,65.3,98
33 Carol,F,14,62.8,102.5
34 Henry,M,14,63.5,102.5
35 James,M,12,57.3,83
36 Jane,F,12,59.8,84.5
37 Janet,F,15,62.5,112.5
38 Jeffrey,M,13,62.5,84
39 John,M,12,59,99.5
40 Joyce,F,11,51.3,50.5
41 Judy,F,14,64.3,90
42 Louise,F,12,56.3,77
43 Mary,F,15,66.5,112
44 Philip,M,16,72,150
45 Robert,M,12,64.8,128
46 Ronald,M,15,67,133
47 Thomas,M,11,57.5,85
48 William,M,15,66.5,112
49 ;;;;
50 run;
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 )
64 data 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;
71 run;
72 data _null_;
73  set work.errs;
74  putlog (_all_)(=);
75 run;
76 
77 %mp_assertdsobs(work.errs,
78  desc=Err table has 0 records,
79  test=EQUALS 0
80 )
81 
82 /* test2 */
83 data 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;
92 run;
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 )
102 data 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;
109 run;
110 data _null_;
111  set work.errs2;
112  putlog (_all_)(=);
113 run;
114 
115 %mp_assertdsobs(work.errs2,
116  desc=Err table has 0 records,
117  test=EQUALS 0
118 )