I'm trying to automatically create some integrity constraints based on this dataset:
ds_name | var_name | ic_clause | ic_msg
--------+----------+------------------------------------+-----------------------
tableA | var1 | primary key($var$) | $var$ is a primary key
tableB | var2 | check(where=($var$ in ('a', 'b'))) | invalid $var$ value
The idea is to create a generic program that loops through this dataset and creates the ICs accordingly. In this specific case, the equivalent hard coded program would be:
proc datasets nolist;
modify tableA;
ic create primary key(var1)
message = "var1 is a primary key";
quit;
proc datasets nolist;
modify tableB;
ic create check(where=(var2 in ('a', 'b')))
message = "invalid var2 value";
quit;
These are the steps I imagine in the program, but I need help to translate them into actual code:
- Fetch values for a row and put them in macro variables
- Replace $var$ substrings with the actual variable name in column var_name
Run a generic proc datasets, eg.:
proc datasets nolist; modify &my_ds; ic create &my_clause message = &my_msg; quit;
- Loop through all rows
Can anyone please help me with this code? I don't know whether the steps I've suggested are the best way to implement what I'm trying to do. Basically I'm trying to simulate a relational database within SAS, and to automate things the maximum possible.
Thank you!