Created
May 25, 2021 06:54
-
-
Save rudvfaden/4f38630ad2d149ab937891fc17afb7bb to your computer and use it in GitHub Desktop.
Cheks if a SAS variable exists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
***********************************************************************; | |
* Projekt : macropg | |
* | |
* Program name : VarExist.sas | |
* | |
* Path : /Y/nyfls/Statistikprogrammer/Macroprg/varExists.sas | |
* | |
* Author : Rud Faden | |
* | |
* Date created : 2018-05-14 12:50 | |
* | |
* Comments : Tjekker om en given variable findes | |
|**********************************************************************; | |
%macro varexist(ds, var); | |
%local rc dsid; | |
%let dsid = %sysfunc(open(&ds)); | |
%if &DSID = 0 %then %do; | |
%put %sysfunc(sysmsg()); | |
%let varexist = .; | |
%goto mexit; | |
%end; | |
%if %sysfunc(varnum(&dsid, &var)) > 0 %then %do; | |
%let varexist = 1; | |
%put NOTE: Var &var exists in &ds; | |
%end; | |
%else %do; | |
%let varexist = 0; | |
%put NOTE: Var &var not exists in &ds; | |
%end; | |
%let rc = %sysfunc(close(&dsid)); | |
%mexit: &varexist. | |
%mend varexist; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment