Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mp_ds2csv.test.1.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Testing mp_ds2csv.sas macro
4
5 <h4> SAS Macros </h4>
6 @li mp_ds2csv.sas
7 @li mp_assert.sas
8 @li mp_assertscope.sas
9
10**/
11
12data work.somedata;
13 x=1;
14 y=' t"w"o';
15 z=.z;
16 label x='x factor';
17run;
18
19/**
20 * Test 1 - default CSV
21 */
22%mp_assertscope(SNAPSHOT)
23%mp_ds2csv(work.somedata,outfile="&sasjswork/test1.csv")
24%mp_assertscope(COMPARE)
25
26%let test1b=FAIL;
27data _null_;
28 infile "&sasjswork/test1.csv";
29 input;
30 list;
31 if _n_=1 then call symputx('test1a',_infile_);
32 else if _infile_=:'1," t""w""o",.Z' then call symputx('test1b','PASS');
33run;
34
35%mp_assert(
36 iftrue=("&test1a"="x factor, Y, Z"),
37 desc=Checking header row Test 1,
38 outds=work.test_results
39)
40%mp_assert(
41 iftrue=("&test1b"="PASS"),
42 desc=Checking data row Test 1,
43 outds=work.test_results
44)
45
46/**
47 * Test 2 - NAME header with fileref and semicolons
48 */
49filename test2 "&sasjswork/test2.csv";
50%mp_ds2csv(work.somedata,outref=test2,dlm=SEMICOLON,headerformat=NAME)
51
52%let test2b=FAIL;
53data _null_;
54 infile test2;
55 input;
56 list;
57 if _n_=1 then call symputx('test2a',_infile_);
58 else if _infile_=:'1;" t""w""o";.Z' then call symputx('test2b','PASS');
59run;
60
61%mp_assert(
62 iftrue=("&test2a"="X; Y; Z"),
63 desc=Checking header row Test 2,
64 outds=work.test_results
65)
66%mp_assert(
67 iftrue=("&test2b"="PASS"),
68 desc=Checking data row Test 2,
69 outds=work.test_results
70)
71
72/**
73 * Test 3 - SASjs format
74 */
75filename test3 "&sasjswork/test3.csv";
76%mp_ds2csv(work.somedata,outref=test3,headerformat=SASJS)
77
78%let test3b=FAIL;
79data _null_;
80 infile test3;
81 input;
82 list;
83 if _n_=1 then call symputx('test3a',_infile_);
84 else if _infile_=:'1," t""w""o",.Z' then call symputx('test3b','PASS');
85run;
86
87%mp_assert(
88 iftrue=("&test3a"="X:best. Y:$char7. Z:best."),
89 desc=Checking header row Test 3,
90 outds=work.test_results
91)
92%mp_assert(
93 iftrue=("&test3b"="PASS"),
94 desc=Checking data row Test 3,
95 outds=work.test_results
96)
97
98/* test 4 - sasjs with compare */
99filename example temp;
100%mp_ds2csv(sashelp.air,outref=example,headerformat=SASJS)
101data _null_; infile example; input;put _infile_; if _n_>5 then stop;run;
102
103data _null_;
104 infile example;
105 input;
106 call symputx('stmnt',_infile_);
107 stop;
108run;
109data work.want;
110 infile example dsd firstobs=2;
111 input &stmnt;
112run;
113
114%mp_assert(
115 iftrue=(&syscc =0),
116 desc=Checking syscc prior to compare of sashelp.air,
117 outds=work.test_results
118)
119
120proc compare base=want compare=sashelp.air;
121run;
122%mp_assert(
123 iftrue=(&sysinfo le 41),
124 desc=Checking compare of sashelp.air,
125 outds=work.test_results
126)
127
128/* test 5 - sasjs with time/datetime/date */
129filename f2 temp;
130data work.test5;
131 do x=1 to 5;
132 y=x;
133 z=x;
134 end;
135 format x date9. y datetime19. z time.;
136run;
137%mp_ds2csv(work.test5,outref=f2,headerformat=SASJS)
138data _null_; infile example; input;put _infile_; if _n_>5 then stop;run;
139
140data _null_;
141 infile f2;
142 input;
143 putlog _infile_;
144 call symputx('stmnt2',_infile_);
145 stop;
146run;
147data work.want5;
148 infile f2 dsd firstobs=2;
149 input &stmnt2;
150 putlog _infile_;
151run;
152
153%mp_assert(
154 iftrue=(&syscc=0),
155 desc=Checking syscc prior to compare of test5,
156 outds=work.test_results
157)
158
159proc compare base=want5 compare=work.test5;
160run;
161%mp_assert(
162 iftrue=(&sysinfo le 41),
163 desc=Checking compare of work.test5,
164 outds=work.test_results
165)
166