Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mv_castabload.test.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Testing mv_castabload macro
4
5 <h4> SAS Macros </h4>
6 @li mf_uid.sas
7 @li mp_assert.sas
8 @li mp_assertscope.sas
9 @li mv_castabload.sas
10
11**/
12
13options mprint;
14
15/* -------------------------------------------------------------------- */
16/* Setup: start a CAS session and stage a source file in the caslib */
17/* -------------------------------------------------------------------- */
18cas mysess;
19caslib _all_ assign;
20
21%let testcaslib=Public;
22
23proc cas;
24 table.caslibInfo result=r / ;
25 found=0;
26 do row over r.CASLibInfo;
27 if upcase(row.Name)=upcase("&testcaslib") then found=1;
28 end;
29 if found=0 then do;
30 print "ERROR: caslib &testcaslib not available";
31 exit;
32 end;
33quit;
34%put NOTE: Using testcaslib=&testcaslib;
35
36%let tab1=T%mf_uid();
37
38/* Save a sashdat source file then drop the in-memory copy so the first
39 mv_castabload call has something to load */
40proc casutil;
41 load data=sashelp.baseball
42 outcaslib="&testcaslib" casout="&tab1" replace;
43 save casdata="&tab1" incaslib="&testcaslib"
44 casout="&tab1..sashdat" outcaslib="&testcaslib" replace;
45 droptable casdata="&tab1" incaslib="&testcaslib" quiet;
46quit;
47
48libname mylib cas caslib="&testcaslib";
49
50
51/* -------------------------------------------------------------------- */
52%put TEST 1 - load a table that is not in memory;
53/* -------------------------------------------------------------------- */
54
55/* Confirm table is absent before the call */
56%let _tabexists=0;
57proc cas;
58 table.tableExists result=r /
59 caslib="&testcaslib" name="&tab1";
60 if r.exists > 0 then call symputx('_tabexists','1');
61quit;
62
63%mp_assert(
64 iftrue=(&_tabexists=0),
65 desc=Check table is not in memory before mv_castabload
66)
67
68%mv_castabload(lib=mylib, table=&tab1, mdebug=1)
69
70%let _tabexists=0;
71proc cas;
72 table.tableExists result=r /
73 caslib="&testcaslib" name="&tab1";
74 if r.exists > 0 then call symputx('_tabexists','1');
75quit;
76
77%mp_assert(
78 iftrue=(&_tabexists=1),
79 desc=Check table is in memory after mv_castabload
80)
81
82
83/* -------------------------------------------------------------------- */
84%put TEST 2 - reload fetches a fresh copy and discards in-memory changes;
85/* -------------------------------------------------------------------- */
86
87/* Append a sentinel row to the in-memory table */
88data work.extra;
89 set mylib.&tab1;
90 name='TESTROW';
91 output;
92 stop;
93run;
94proc casutil;
95 load data=work.extra casout="&tab1"
96 outcaslib="&testcaslib" append;
97quit;
98
99%let _modified=0;
100proc sql noprint;
101 select count(*) into :_modified
102 from mylib.&tab1
103 where name='TESTROW';
104quit;
105
106%mp_assert(
107 iftrue=(&_modified=1),
108 desc=Check sentinel row is present in memory before reload
109)
110
111/* Drop the table and reload - source file does not have the sentinel */
112proc casutil;
113 droptable casdata="&tab1" incaslib="&testcaslib" quiet;
114 droptable casdata="&tab1" incaslib="&testcaslib" quiet;
115quit;
116
117%mp_assertscope(SNAPSHOT)
118
119%mv_castabload(lib=mylib, table=&tab1, mdebug=1)
120
121%mp_assertscope(COMPARE,
122 desc=Check mv_castabload does not leak macro variables into GLOBAL scope
123)
124
125%let _after=0;
126proc sql noprint;
127 select count(*) into :_after
128 from mylib.&tab1
129 where name='TESTROW';
130quit;
131
132%mp_assert(
133 iftrue=(&_after=0),
134 desc=Check sentinel row is absent after reload from source
135)
136
137
138/* -------------------------------------------------------------------- */
139/* Teardown */
140/* -------------------------------------------------------------------- */
141libname mylib clear;
142
143proc casutil;
144 droptable casdata="&tab1" incaslib="&testcaslib" quiet;
145 droptable casdata="&tab1" incaslib="&testcaslib" quiet;
146 deletesource casdata="&tab1..sashdat"
147 incaslib="&testcaslib" quiet;
148quit;
149
150cas mysess terminate;
151
152%let syscc=0;