Production Ready Macros for SAS Application Developers
mf_getkeyvalue.sas
Go to the documentation of this file.
1 /**
2  @file
3  @brief retrieves a key value pair from a control dataset
4  @details By default, control dataset is work.mp_setkeyvalue. Usage:
5 
6  %mp_setkeyvalue(someindex,22,type=N)
7  %put %mf_getkeyvalue(someindex)
8 
9 
10  @param key Provide a key on which to perform the lookup
11  @param libds= define the target table which holds the parameters
12 
13  @version 9.2
14  @author Allan Bowe
15 **/
16 
17 %macro mf_getkeyvalue(key,libds=work.mp_setkeyvalue
18 )/*/STORE SOURCE*/;
19  %local ds dsid key valc valn type rc;
20 %let dsid=%sysfunc(open(&libds(where=(key="&key"))));
21 %syscall set(dsid);
22 %let rc = %sysfunc(fetch(&dsid));
23 %let rc = %sysfunc(close(&dsid));
24 
25 %if &type=N %then %do;
26  &valn
27 %end;
28 %else %if &type=C %then %do;
29  &valc
30 %end;
31 %else %put ERROR: Unable to find key &key in ds &libds;
32 %mend;