Loading...
Searching...
No Matches
mf_getvalue.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Retrieves a value from a dataset. Returned value is fetched from the
4 'fetchobs=' record (row 1 by default), after applying the optional filter.
5
6 @details Be sure to <code>%quote()</code> your where clause. Example usage:
7
8 %put %mf_getvalue(sashelp.class,name,filter=%quote(age=15));
9 %put %mf_getvalue(sashelp.class,name);
10
11 <h4> SAS Macros </h4>
12 @li mf_getattrn.sas
13
14 <h4> Related Macros </h4>
15 @li mp_setkeyvalue.sas
16
17 @param [in] libds dataset to query
18 @param [in] variable the variable which contains the value to return.
19 @param [in] filter= (1) contents of where clause
20 @param [in] fetchobs= (1) observation to fetch. NB: Filter applies first.
21
22 @version 9.2
23 @author Allan Bowe
24**/
25
26%macro mf_getvalue(libds,variable,filter=1,fetchobs=1
27)/*/STORE SOURCE*/;
28 %local dsid;
29
30 %let dsid=%sysfunc(open(&libds(where=(&filter))));
31 %if (&dsid) %then %do;
32 %local rc &variable;
33 %syscall set(dsid);
34 %let rc = %sysfunc(fetchobs(&dsid,&fetchobs));
35 %if (&rc ne 0) %then %do;
36 %put NOTE: Problem reading obs &fetchobs from &libds..;
37 %put %sysfunc(sysmsg());
38 /* Coerce an rc value of -1 (read past end of data) to a 4
39 that, in SAS condition code terms, represents the sysmsg
40 w@rning it generates. */
41 %if &rc eq -1 %then %let rc = 4;
42 /* And update SYSCC if the &rc value is higher */
43 %let syscc = %sysfunc(max(&syscc,&rc));
44 %end;
45 %let rc = %sysfunc(close(&dsid));
46
47 %trim(&&&variable)
48
49 %end;
50 %else %do;
51 %put %sysfunc(sysmsg());
52 %let syscc = %sysfunc(max(&syscc,%sysfunc(sysrc())));
53 %end;
54
55%mend mf_getvalue;