BookmarkSubscribeRSS Feed
RichardDeVen
Barite | Level 11

Consider this step that keeps one unknown variable

 

data _null_;
  dsid = open ('SASHELP.CLASS(keep=ANAME)');
  msg = sysmsg();
  put msg '(msg)';
run;
----- LOG -----
ERROR: The variable ANAME in the DROP, KEEP, or RENAME list has never been referenced. (msg)

 

The SYSMSG() function retrieves the final message that would have been logged by the function.

If there are two unknown variables in the keep= there is some log messiness because the first error message (also the 'not last' error messages) is logged by SAS and repeated, and the last message is not logged and can be retrieved with SYSMSG().  Example:

 

data _null_;
  dsid = open ('SASHELP.CLASS(keep=ANAME SCHOOL)');
  msg = sysmsg();
  put msg '(msg)';
run;
----- LOG -----
ERROR: The variable ANAME in the DROP, KEEP, or RENAME list has never been referenced.
ERROR: The variable ANAME in the DROP, KEEP, or RENAME list has never been referenced.
ERROR: The variable SCHOOL in the DROP, KEEP, or RENAME list has never been referenced. (msg)

It gets worse as the number of unknown variables increases, because all the not-last error messages get logged twice.

 

data _null_;
  dsid = open ('SASHELP.CLASS(keep=ANAME SCHOOL NAME AHEIGHT DISTRICT)');
  msg = sysmsg();
  put msg '(msg)';
run;
----- LOG -----
ERROR: The variable ANAME in the DROP, KEEP, or RENAME list has never been referenced.
ERROR: The variable SCHOOL in the DROP, KEEP, or RENAME list has never been referenced.
ERROR: The variable AHEIGHT in the DROP, KEEP, or RENAME list has never been referenced.
ERROR: The variable ANAME in the DROP, KEEP, or RENAME list has never been referenced.
ERROR: The variable SCHOOL in the DROP, KEEP, or RENAME list has never been referenced.
ERROR: The variable AHEIGHT in the DROP, KEEP, or RENAME list has never been referenced.
ERROR: The variable DISTRICT in the DROP, KEEP, or RENAME list has never been referenced. (msg)

Does anyone have any ideas on why this double logging occurs and how it might be reduced to single logging ?

 

 

 

 

 

 

5 REPLIES 5
ballardw
Super User

One might ask why you are worried about a double error log in the first place.

If you are relying on the LOG to tell you that variables aren't there perhaps you could consult with the Dictionary.columns (or sashelp.vcolumn) for the names you are using to verify that they are in the data set before attempting to open the set.

 

If you run this code:

data _null_;
  dsid = open ('SASHELP.CLASS(keep=ANAME SCHOOL)');
  put "before msg";
  msg = sysmsg();
  put msg '(msg)';
run;

You will see that the first too lines of errors in the log occur before the SYSMSG function executes. So one suspects the KEEP= errors are getting passed to the log. Then you get a (partial) duplicate from your SYSMSG/PUT combination.

Quentin
Super User

Hmm, in 9.4M7 I get two errors just from trying to keep one non-existant variable:

 

1    data _null_;
2      dsid = open ('SASHELP.CLASS(keep=ANAME)');
3    run;

ERROR: The variable ANAME in the DROP, KEEP, or RENAME list has never been referenced.
ERROR: The variable ANAME in the DROP, KEEP, or RENAME list has never been referenced.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      user cpu time       0.00 seconds

That's 9.4M7 on windows.

BASUG is hosting free webinars Next up: Mark Keintz presenting History Carried Forward, Future Carried Back: Mixing Time Series of Differing Frequencies on May 8. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
RichardDeVen
Barite | Level 11
Hi Quentin:

Pretty interesting how the logging changed between M6 and M7.
Hope it is not an indicator of a whack-a-mole situation.

Richard
Patrick
Opal | Level 21

If using below code the compiler reports the error once.

data _null_;
  stop;
  set SASHELP.CLASS(keep=ANAME SCHOOL NAME AHEIGHT DISTRICT);
run;

So guess the open function then makes the compiler repeat the error message. 

 

Feels like something you would need to contact SAS TS.

Ksharp
Super User

How about to suppress these ERROR ?

 

options dkricond=nowarn dkrocond=nowarn ;
data _null_;
  dsid = open ('SASHELP.CLASS(keep=ANAME)');
  msg = sysmsg();
  put msg '(msg)';
run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 5 replies
  • 414 views
  • 0 likes
  • 5 in conversation