SASUnit Examples  Version 1.5.0
getvars_test.sas
Go to the documentation of this file.
1 
24 /*-- simple example with sashelp.class ---------------------------------------*/
25 %initTestcase(i_object=getvars.sas, i_desc=simple example with sashelp.class)
26 %let vars=%getvars(sashelp.class);
27 /* %endTestcall() can be omitted, will called implicitly by the first assert */
28 %assertEquals(i_actual=&vars, i_expected=Name Sex Age Height Weight, i_desc=Variablen prüfen)
29 /* %endTestcase() can be omitted, will called implicitly by the next initTestcase */
30 
31 /*-- simple example with sashelp.class, different delimiter ------------------*/
32 %initTestcase(i_object=getvars.sas, i_desc=%str(simple example with sashelp.class, different delimiter))
33 %let vars=%getvars(sashelp.class,dlm=%str(,));
34 %assertEquals(i_actual=&vars, i_expected=%str(Name,Sex,Age,Height,Weight), i_desc=check variables)
35 
36 /*-- example with variable names containing special characters ---------------*/
37 %initTestcase(i_object=getvars.sas, i_desc=example with variable names containing special characters)
38 options validvarname=any;
39 data test;
40  'a b c'n=1;
41  '$6789'n=2;
42  ';6789'n=2;
43 run;
44 %let vars="%getvars(test,dlm=%str(","))";
45 %assertEquals(i_actual=&vars, i_expected=%str("a b c","$6789",";6789"), i_desc=check variables)
46 %macro al;
47 %if &sysver=9.1 %then %do;
48  %assertLog(i_warnings=1,i_desc=%str(check log, one warning due to validvarname))
49  %endTestcase(i_assertLog=0) /* no assertLog */
50 %end;
51 %mend al;
52 %al;
53 
54 /*-- example with empty dataset ----------------------------------------------*/
55 %initTestcase(i_object=getvars.sas, i_desc=example with empty dataset)
56 data test;
57  stop;
58 run;
59 %let vars=%getvars(test);
60 %assertEquals(i_actual=&vars, i_expected=, i_desc=no variables found)
61 
62 /*-- example without dataset specified ---------------------------------------*/
63 %initTestcase(i_object=getvars.sas, i_desc=example without dataset specified)
64 %let vars=%getvars();
65 %assertEquals(i_actual=&vars, i_expected=, i_desc=no variables found)
66 
67 /*-- example with invalid dataset --------------------------------------------*/
68 %initTestcase(i_object=getvars.sas, i_desc=example with invalid dataset)
69 %let vars=%getvars(xxx);
70 %assertEquals(i_actual=&vars, i_expected=, i_desc=example with invalid dataset)