Production Ready Macros for SAS Application Developers
https://github.com/sasjs/core
mp_setkeyvalue.sas
Go to the documentation of this file.
1 /**
2  @file
3  @brief Logs a key value pair a control dataset
4  @details If the dataset does not exist, it is created. Usage:
5 
6  %mp_setkeyvalue(someindex,22,type=N)
7  %mp_setkeyvalue(somenewindex,somevalue)
8 
9  <h4> Dependencies </h4>
10  @li mf_existds.sas
11 
12  @param key Provide a key on which to perform the lookup
13  @param value Provide a value
14  @param type= either C or N will populate valc and valn respectively. C is
15  default.
16  @param libds= define the target table to hold the parameters
17 
18  @version 9.2
19  @author Allan Bowe
20  @source https://github.com/sasjs/core
21 
22 **/
23 
24 %macro mp_setkeyvalue(key,value,type=C,libds=work.mp_setkeyvalue
25 )/*/STORE SOURCE*/;
26 
27  %if not (%mf_existds(&libds)) %then %do;
28  data &libds (index=(key/unique));
29  length key $32 valc $256 valn 8 type $1;
30  call missing(of _all_);
31  stop;
32  run;
33  %end;
34 
35  proc sql;
36  delete from &libds
37  where key=symget('key');
38  insert into &libds
39  set key=symget('key')
40  %if &type=C %then %do;
41  ,valc=symget('value')
42  ,type='C'
43  %end;
44  %else %do;
45  ,valn=symgetn('value')
46  ,type='N'
47  %end;
48  ;
49 
50  quit;
51 
52 %mend;