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