Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
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> SAS Macros </h4>
10 @li mf_existds.sas
11
12 <h4> Related Macros </h4>
13 @li mf_getvalue.sas
14
15 @param [in] key Provide a key on which to perform the lookup
16 @param [in] value Provide a value
17 @param [in] type= either C or N will populate valc and valn respectively.
18 C is default.
19 @param [out] libds= define the target table to hold the parameters
20
21 @version 9.2
22 @author Allan Bowe
23 @source https://github.com/sasjs/core
24
25**/
26
27%macro mp_setkeyvalue(key,value,type=C,libds=work.mp_setkeyvalue
28)/*/STORE SOURCE*/;
29
30 %if not (%mf_existds(&libds)) %then %do;
31 data &libds (index=(key/unique));
32 length key $64 valc $2048 valn 8 type $1;
33 call missing(of _all_);
34 stop;
35 run;
36 %end;
37
38 proc sql;
39 delete from &libds
40 where key=symget('key');
41 insert into &libds
42 set key=symget('key')
43 %if &type=C %then %do;
44 ,valc=symget('value')
45 ,type='C'
46 %end;
47 %else %do;
48 ,valn=symgetn('value')
49 ,type='N'
50 %end;
51 ;
52
53 quit;
54
55%mend mp_setkeyvalue;