Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mp_zip.test.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Testing mp_zip macro
4
5 <h4> SAS Macros </h4>
6 @li mf_mkdir.sas
7 @li mp_assert.sas
8 @li mp_zip.sas
9 @li mp_unzip.sas
10
11**/
12
13%let work=%sysfunc(pathname(work));
14%let root=&work/zipme;
15
16/* TEST 1 - zip a file */
17%mf_mkdir(&root)
18
19data _null_;
20 file "&root/test.txt";
21 put "houston, this is a test";
22run;
23
24%mp_zip(in=&root/test.txt
25 ,type=FILE
26 ,outpath=&work
27 ,outname=myFile
28)
29
30%mp_unzip(ziploc="&work/myFile.zip",outdir=&work)
31
32data _null_;
33 infile "&work/test.txt";
34 input;
35 call symputx('content1',_infile_);
36 putlog _infile_;
37run;
38
39%mp_assert(
40 iftrue=(
41 %str(&content1)=%str(houston, this is a test)
42 ),
43 desc=Checking if file zip / unzip works,
44 outds=work.test_results
45)
46
47/* TEST 2 - zip a dataset of files */
48data _null_;
49 file "&root/test2.txt";
50 put "houston, this is test2";
51run;
52libname tmp "&root";
53data tmp.test;
54 filepath="&root/test2.txt";
55run;
56
57%mp_zip(in=tmp.test
58 ,incol=filepath
59 ,type=DATASET
60 ,outpath=&work
61 ,outname=myFile2
62)
63
64%mp_unzip(ziploc="&work/myFile2.zip",outdir=&work)
65
66data _null_;
67 infile "&work/test2.txt";
68 input;
69 call symputx('content2',_infile_);
70 putlog _infile_;
71run;
72
73%mp_assert(
74 iftrue=(
75 %str(&content2)=%str(houston, this is test2)
76 ),
77 desc=Checking if file zip / unzip from a dataset works,
78 outds=work.test_results
79)
80
81/* TEST 3 - zip a dataset of files */
82%mf_mkdir(&work/out3)
83
84%mp_zip(in=&root
85 ,type=DIRECTORY
86 ,outpath=&work
87 ,outname=myFile3
88)
89
90%mp_unzip(ziploc="&work/myFile3.zip",outdir=&work/out3)
91
92data _null_;
93 infile "&work/out3/test.txt";
94 input;
95 call symputx('content3a',_infile_);
96 putlog _infile_;
97run;
98data _null_;
99 infile "&work/out3/test2.txt";
100 input;
101 call symputx('content3b',_infile_);
102 putlog _infile_;
103run;
104
105%mp_assert(
106 iftrue=(
107 %str(&content3a)=%str(houston, this is a test)
108 and
109 %str(&content3b)=%str(houston, this is test2)
110 ),
111 desc=Checking if file zip / unzip from a directory works,
112 outds=work.test_results
113)
114
115