Saturday, November 8, 2008

CheckVar - Existence of a variable in a dataset

This code is used to check for the existence of a variable in a dataset.
Just you need to provide library,dataset and variable name which you want to check.
For more details, see the comments in code.
Here just you need to provide the library.dataset name and the variable name which you want to search.

SAS Code:

/* Printing variable position in a dataset (>=1) and Existence of a variable (=0) */
%let dsid=%sysfunc(open(data1));
%let num=%sysfunc(varnum(&dsid,var1));
%let rc=%sysfunc(close(&dsid));
%put Variable is located in column:&num..;

------------------- END of the Code ----------------------------------------------

No comments: