Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mp_ds2fmtds.test.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Testing mp_ds2fmtds.sas macro
4
5 <h4> SAS Macros </h4>
6 @li mp_ds2fmtds.sas
7 @li mp_assert.sas
8 @li mp_assertdsobs.sas
9 @li mp_assertmodel.sas
10 @li mp_assertscope.sas
11
12 @sasjslint {"noUnusedMacros": false}
13**/
14
15proc sql;
16create table test as select * from dictionary.tables where libname='SASHELP';
17
18filename inc temp;
19data _null_;
20 set work.test;
21 file inc;
22 libds=cats('sashelp.',memname);
23 if exist(libds) then line=cats('%mp_ds2fmtds(',libds,',',memname,')');
24 put line;
25run;
26
27/* A known fixture exercises formatted character, numeric and date values. */
28data work.fmt_input;
29 length id $6 label $6 amount when 8;
30 format label $char12. amount comma12.2 when yymmdd10.;
31 id='A'; label='First'; amount=12.5; when='02JAN2024'd; output;
32 id='B'; label='Second'; amount=-3.25; when='31DEC2023'd; output;
33run;
34
35%mp_assertscope(SNAPSHOT)
36%mp_ds2fmtds(work.fmt_input,work.fmt_output)
37%mp_assertscope(COMPARE,
38 desc=Formatted dataset conversion does not leak macro variables,
39 outds=work.test_results
40)
41
42data work.fmt_model;
43 length id $6 label $12 amount when $24;
44 call missing(id,label,amount,when);
45 stop;
46run;
47
48%mp_assertmodel(work.fmt_output,base=work.fmt_model,key=id,
49 desc=Formatted dataset model and key,
50 outds=work.test_results
51)
52
53%mp_assertdsobs(work.fmt_output,
54 test=EQUALS 2,
55 desc=Formatted dataset has both rows,
56 outds=work.test_results
57)
58
59data work.fmt_bad;
60 set work.fmt_output;
61 if not ((id='A' and label='First' and amount='12.50'
62 and when='2024-01-02')
63 or (id='B' and label='Second' and amount='-3.25'
64 and when='2023-12-31'));
65run;
66
67%mp_assertdsobs(work.fmt_bad,
68 test=EQUALS 0,
69 desc=Formatted values match the input rows,
70 outds=work.test_results
71)
72
73options obs=50;
74%inc inc;
75
76%mp_assert(
77 iftrue=(&syscc=0),
78 desc=Checking tables were created successfully,
79 outds=work.test_results
80)