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 ?
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.
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.
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.
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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.