Several coding issues can cause this error, but it all boils down to you having named a variable to drop, keep or rename that is not available in the SAS process. For example, let’s work with this sample input data:
WORK.INPUTDATA
#
Variable
Type
Len
1
ID
Num
8
3
char1
Char
1
2
var1
Num
In this code, I’ve mistyped the name of variable char1
DATA outputData2;
SET inputData;
DROP chr1;
RUN;
And SAS complains in the log:
ERROR: The variable chr1 in the DROP, KEEP, or RENAME list has never been referenced.
NOTE: The SAS System stopped processing this step because of errors.
A typo can be oh-so-subtle. Here, I inadvertently used a lower-case L instead of the number 1 in the variable name:
DATA outputData2;
SET inputData;
DROP varl;
RUN;
And, sure enough, SAS doesn’t like that, either:
ERROR: The variable varl in the DROP, KEEP, or RENAME list has never been referenced.
Sometimes I outsmart myself in the code. Here, I limited the variables read in with a KEEP= dataset option, and later try to drop char1, but it was never read in:
DATA outputData2;
SET inputData (keep=ID var1);
DROP char1;
RUN;
And… you guessed it, SAS calls me out on it:
ERROR: The variable char1 in the DROP, KEEP, or RENAME list has never been referenced.
And sometimes, I outsmart myself so well, that it can take hours for me to figure out what I did wrong!. Can you see what got me here?
DATA outputData2 (rename=(ID=ID2 var1=Numeric char1=Character));
SET inputData ;
DROP char1;
RUN;
ERROR: The variable char1 in the DROP, KEEP, or RENAME list has never been referenced.
Remember how the DROP statement flags variables in the PDV? Well, my RENAME= dataset option on the OUTPUT dataset means that the variables in the PDV have been renamed, so technically we can't drop char1 from outputData2. Instead, it would be named Character. It's kind of silly to try to drop it and rename a variable - why bother, right? This code runs fine:
DATA outputData2 (rename=(ID=ID2 var1=Numeric ));
SET inputData ;
DROP char1;
RUN;
Now, you can control how the SAS system responds to this problem with system options DKRICOND and DKROCOND. DKRICOND specifies the level of error detection to report when a variable is missing when you try to drop it from an input data set, and DKROCOND does the same for output data sets. The levels you can set are ERROR (default for PC SAS), WARNING (the default for most Enterprise Guide and SAS Studio installations), and NOWARNING which lets SAS ignore the condition entirely. For example:
options DKROCOND=NOWARNING;
DATA outputData2 (rename=(ID=ID2 var1=Numeric char1=Character));
SET inputData ;
DROP char1;
RUN;
Runs just fine:
NOTE: There were 5 observations read from the data set WORK.INPUTDATA.
NOTE: The data set WORK.OUTPUTDATA2 has 5 observations and 2 variables.
work.outputData2
#
Variable
Type
Len
1
ID2
Num
8
2
Numeric
Num
8
I hope you find this information helpful.
May the SAS be with you! Mark
... View more