1
votes

I would like to write an error message to the SAS log if a variable in the input dataset does not exist. We are using a macro that differentially assigns a variable (datex) value based on another variable's value (var = site). If site is missing from the input dataset, a note will be added to the log (I think?) but I want to write a big red error message to let users know their input dataset is missing the 'site' variable. Any ideas? Thanks for the help!

ex:

data want;
 set have; 
 %macro_to_create_datex;
run;

if variable site is not in the dataset have, then print an error to the log. The macro 'macro_to_create_datex' uses the value of 'site' to assign datex.

1
Usually you wouldn't check this within a data step but within the macro. SASHELP.vcolumn contains the list of variables in all data sets and can be used to check the variables or proc contents can pipe the list to a data set for a slightly quicker check.Reeza

1 Answers

0
votes

By default, a put statement writes to the log.

Just start your message with ERROR: or WARNING: and it will be highlighted appropriately.

Assuming you identify your data by a variable named key:

data want;
    set have; 
    if missing(site) then put "ERROR: missing site for observation " _N_ key=;
    %macro_to_create_datex;
run;