Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mp_createconstraints.test.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Testing mp_createconstraints macro
4
5 <h4> SAS Macros </h4>
6 @li mp_createconstraints.sas
7 @li mp_assert.sas
8
9**/
10
11data work.constraints;
12 length libref $8 table_name $32 constraint_name $32 constraint_type $12
13 column_name $32;
14 libref='WORK'; table_name='CLASSC'; constraint_name='PK_CLASSC';
15 constraint_type='PRIMARY'; column_name='id'; output;
16 libref='WORK'; table_name='CLASSC'; constraint_name='PK_CLASSC';
17 constraint_type='PRIMARY'; column_name='name'; output;
18run;
19
20%mp_createconstraints(inds=work.constraints,outds=work.cc_out,execute=NO)
21
22proc sql noprint;
23 select count(*) into: n_stmt from work.cc_out;
24 select count(*) into: n_pk from work.cc_out
25 where index(create_statement,'PRIMARY KEY')>0;
26 select count(*) into: n_cols from work.cc_out
27 where index(create_statement,'id')>0 or index(create_statement,'name')>0;
28quit;
29
30%mp_assert(
31 iftrue=(&n_stmt=2),
32 desc=Checking that one create statement is produced per column,
33 outds=work.test_results
34)
35
36%mp_assert(
37 iftrue=(&n_pk=1),
38 desc=Checking that a PRIMARY constraint becomes a PRIMARY KEY clause,
39 outds=work.test_results
40)
41
42%mp_assert(
43 iftrue=(&n_cols=2),
44 desc=Checking that the column name is carried into each statement,
45 outds=work.test_results
46)
47
48/* execute=YES must run the generated sql cleanly */
49data work.classt;
50 length id 8 name $10;
51 id=1; name='one'; output;
52 id=2; name='two'; output;
53run;
54
55data work.constraints2;
56 length libref $8 table_name $32 constraint_name $32 constraint_type $12
57 column_name $32;
58 libref='WORK'; table_name='CLASST'; constraint_name='PK_CLASST';
59 constraint_type='PRIMARY'; column_name='id';
60run;
61
62%mp_createconstraints(inds=work.constraints2,outds=work.cc_out2,execute=YES)
63%mp_assert(
64 iftrue=(&syscc=0),
65 desc=Checking that execute=YES runs the generated statements cleanly,
66 outds=work.test_results
67)