BookmarkSubscribeRSS Feed
Sami1234
Fluorite | Level 6

 

Hi All,

 

Would you please let me know the way to write out an error or warning message along with the name given in the varlist which is not in the input dataset. For example, %varlist= a b c d; and variable d is not in the input 'CLASS' dataset

I would like to the display in the log the following message after running names1 datasets.

'Variable 'D'  is not in the CLASS dataset.'

or if variable D and C are not in the class dataset then the message 'Variable C and D are not in the CLASS dataset.'

And after that system should abort or go to the end instead running next data step.

 

 

 

 

 

%let varlist= a b c d;

%let varlist_quotesAndcomma="%sysfunc(prxchange(s/\s+/%nrbquote(",")/i,-1,&varlist))";  %put &=varlist_quotesAndcomma;

DATA checkdata;

%DO _t = 1 %TO %sysfunc(countw("&varlist",' '));

name = strip(scan("&&varlist",&_t," "));

OUTPUT;

%END;

RUN;

data names (keep=name);

set dictionary.columns( where =( libname='SASHELP' and memname='CLASS' and upcase(name) in (%upcase(&varlist_quotesAndcomma))));

run;

data names1;

merge names(in=names) checkdata(in=checkdata);

if checkdata and not names;

run;

 

Thank you!

2 REPLIES 2
Patrick
Opal | Level 21

Here a coding option which should give you the idea.

%let varlist=name a sex c;

proc sql;
  create view v_columns as
  select upcase(name) as name
  from dictionary.columns
  where libname='SASHELP' and memname='CLASS'
  ;
quit;

data _null_;
  if 0 then set v_columns;
  dcl hash h1(dataset:'v_columns');
  h1.defineKey('name');
  h1.defineDone();
  do i=1 by 1;
    name=upcase(scan("&varlist",i,,'kn'));
    if missing(name) then leave;
    if h1.check() ne 0 then
      do;
        putlog 'WARNING: Variable ' name 'not in sashelp.class';
        MissVarFlg=1;
      end;
  end;
  if MissVarFlg=1 then
    do;
/*      some additional exception handling */
    end;
  stop;
run;

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 704 views
  • 1 like
  • 3 in conversation