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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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