Production Ready 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> Dependencies </h4>
11  @li mf_getattrn.sas
12 
13  @param libds dataset to query
14  @param variable the variable which contains the value to return.
15  @param filter contents of where clause
16 
17  @version 9.2
18  @author Allan Bowe
19 **/
20 
21 %macro mf_getvalue(libds,variable,filter=1
22 )/*/STORE SOURCE*/;
23  %if %mf_getattrn(&libds,NLOBS)>0 %then %do;
24  %local dsid rc &variable;
25  %let dsid=%sysfunc(open(&libds(where=(&filter))));
26  %syscall set(dsid);
27  %let rc = %sysfunc(fetch(&dsid));
28  %let rc = %sysfunc(close(&dsid));
29 
30  %trim(&&&variable)
31 
32  %end;
33 %mend;