Production Ready Macros for SAS Application Developers
mf_existvar.sas
Go to the documentation of this file.
1
/**
2
@file
3
@brief Checks if a variable exists in a data set.
4
@details Returns 0 if the variable does NOT exist, and return the position of
5
the var if it does.
6
Usage:
7
8
%put %mf_existVar(work.someds, somevar)
9
10
@param libds (positional) - 2 part dataset or view reference
11
@param var (positional) - variable name
12
@version 9.2
13
@author Allan Bowe
14
**/
15
16
%macro mf_existvar(libds
/* 2 part dataset name */
17
, var
/* variable name */
18
)
/*/STORE SOURCE*/
;
19
20
%local dsid rc;
21
%let dsid=%sysfunc(open(&libds,is));
22
23
%
if
&dsid=0 or %length(&var)=0 %then %
do
;
24
%put %sysfunc(sysmsg());
25
0
26
%end;
27
%
else
%
do
;
28
%sysfunc(varnum(&dsid,&var))
29
%let rc=%sysfunc(
close
(&dsid));
30
%end;
31
32
%mend;
Generated by
For more information visit the
Boemska MacroCore library
.