Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mp_ds2pdf.test.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Testing mp_ds2pdf.sas macro
4
5 <h4> SAS Macros </h4>
6 @li mp_assert.sas
7 @li mp_ds2pdf.sas
8
9**/
10
11filename pdf1 temp;
12filename pdf2 temp;
13filename pdf3 temp;
14filename pdf4 temp;
15filename pdf5 temp;
16filename pdf6 temp;
17
18%mp_ds2pdf(sashelp.class, outref=pdf1
19 ,title=Class listing
20 ,footnote=Core test)
21
22%mp_ds2pdf(sashelp.class, outref=pdf2, maxobs=3
23 ,title=Class listing
24 ,footnote=Core test)
25
26/* PROC PRINT requires the input sorted by the BY variables */
27proc sort data=sashelp.class out=work.classsex;
28 by SEX;
29run;
30
31%mp_ds2pdf(work.classsex, outref=pdf3, by=SEX
32 ,title=By group listing)
33
34/* the total form of the page number */
35%mp_ds2pdf(sashelp.class, outref=pdf4, pagenum=PAGEOF)
36
37/* and the same report with no numbering, so the two can be compared */
38%mp_ds2pdf(sashelp.class, outref=pdf5, pagenum=NO)
39
40/* the report must not depend on the caller's ODS escape character: with one
41 set, the same call has to produce the same file as pdf1 */
42ods escapechar='^';
43
44%mp_ds2pdf(sashelp.class, outref=pdf6
45 ,title=Class listing
46 ,footnote=Core test)
47
48data _null_;
49 infile pdf1 recfm=f lrecl=8 obs=1;
50 length sig $8;
51 input sig $8.;
52 call symputx('sigfull',substr(sig,1,5),'l');
53run;
54
55data _null_;
56 infile pdf3 recfm=f lrecl=8 obs=1;
57 length sig $8;
58 input sig $8.;
59 call symputx('sigby',substr(sig,1,5),'l');
60run;
61
62/* the byte size is read with finfo() rather than by counting records, so a
63 padded record length cannot stand in for the file size */
64data _null_;
65 fid=fopen('pdf1');
66 s1=finfo(fid,'File Size (bytes)');
67 rc=fclose(fid);
68 fid=fopen('pdf2');
69 s2=finfo(fid,'File Size (bytes)');
70 rc=fclose(fid);
71 fid=fopen('pdf4');
72 s4=finfo(fid,'File Size (bytes)');
73 rc=fclose(fid);
74 fid=fopen('pdf5');
75 s5=finfo(fid,'File Size (bytes)');
76 rc=fclose(fid);
77 fid=fopen('pdf6');
78 s6=finfo(fid,'File Size (bytes)');
79 rc=fclose(fid);
80 call symputx('size1',s1,'l');
81 call symputx('size2',s2,'l');
82 call symputx('size4',s4,'l');
83 call symputx('size5',s5,'l');
84 call symputx('size6',s6,'l');
85run;
86
87/* the signature is checked in a data step so the percent sign in the PDF
88 magic number is not read as a macro call by the linter */
89data _null_;
90 length sigfull sigby $5;
91 sigfull=symget('sigfull');
92 sigby=symget('sigby');
93 call symputx('issigfull'
94 ,ifc(sigfull='%PDF-','Y','N'),'l');
95 call symputx('issigby'
96 ,ifc(sigby='%PDF-','Y','N'),'l');
97run;
98
99%mp_assert(
100 iftrue=("&issigfull"="Y"),
101 desc=Checking the file starts with a PDF signature,
102 outds=work.test_results
103)
104%mp_assert(
105 iftrue=("&issigby"="Y"),
106 desc=Checking a by group report is also a PDF,
107 outds=work.test_results
108)
109%mp_assert(
110 iftrue=(&size2 < &size1),
111 desc=Checking maxobs reduces the report,
112 outds=work.test_results
113)
114%mp_assert(
115 iftrue=(&size4 > &size5),
116 desc=Checking the page total is written to the page,
117 outds=work.test_results
118)
119%mp_assert(
120 iftrue=(&size6 = &size1),
121 desc=Checking a caller escape character does not change the report,
122 outds=work.test_results
123)