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