Macros for SAS Application Developers
https://github.com/sasjs/core
mf_getvalue.sas
Go to the documentation of this file.
1 /**
2  @file
3  @brief Retrieves a value from a dataset. If no filter supplied, then first
4  record is used.
5  @details Be sure to <code>%quote()</code> your where clause. Example usage:
6 
7  %put %mf_getvalue(sashelp.class,name,filter=%quote(age=15));
8  %put %mf_getvalue(sashelp.class,name);
9 
10  <h4> SAS Macros </h4>
11  @li mf_getattrn.sas
12 
13  <h4> Related Macros </h4>
14  @li mp_setkeyvalue.sas
15 
16  @param [in] libds dataset to query
17  @param [in] variable the variable which contains the value to return.
18  @param [in] filter= (1) contents of where clause
19 
20  @version 9.2
21  @author Allan Bowe
22 **/
23 
24 %macro mf_getvalue(libds,variable,filter=1
25 )/*/STORE SOURCE*/;
26  %if %mf_getattrn(&libds,NLOBS)>0 %then %do;
27  %local dsid rc &variable;
28  %let dsid=%sysfunc(open(&libds(where=(&filter))));
29  %syscall set(dsid);
30  %let rc = %sysfunc(fetch(&dsid));
31  %let rc = %sysfunc(close(&dsid));
32 
33  %trim(&&&variable)
34 
35  %end;
36 %mend mf_getvalue;