BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Riteshdell
Quartz | Level 8

hello all,

 

I am getting a warning in some code:

WARNING: The variable in the DROP, KEEP, or RENAME list has never been referenced

 

Can any one tell me, what can be the scenario of this warning?

1 ACCEPTED SOLUTION

Accepted Solutions
SASJedi
SAS Super FREQ

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

 

 

 

 

 

 

 

 

 

Check out my Jedi SAS Tricks for SAS Users

View solution in original post

7 REPLIES 7
GreggB
Pyrite | Level 9

Can you post your code related to this data step?

RahulG
Barite | Level 11

 

 

In your output dataset, you have mentioned variable name that is not present in your input dataset.

One example mentioned below, weight,  age2 and height variable not present in input dataset.

 

data temp ( keep = weight drop=age2 rename = (height=ht));

set sashelp.class(keep = age );

run;

Doc_Duke
Rhodochrosite | Level 12

Most often, I have seen that hapen when I have a typo in a varaible name.

 

The second most often time I see it is when I am accessing a replacement data set (e.g. monthly processing) and the underlying input dataset has changed.  Excel is a frequent culprit.

Ksharp
Super User

You can suppress these warning message by :

 

options dkricond=nowarning dkrocond=nowarning ;
szb0167
Calcite | Level 5

Hello all,

 

I am facing a similar issue where I am getting warning messages in the DROP statement. As far as I know, I am referencing the correct variable names. My code is copied below. Any feedback would be greatly appreciated. Thank you!

 

CODE:-

DATA IrisURL2 (RENAME=(x1=SepalLength x2=SepalWidth x3=PetalLength
x4=PetalWidth));
LENGTH x1-x4 3 Species $15;

/*length of variables=w where w=total width, including decimal places*/
INFORMAT x1-x4 3. Species $15.;

/*informat/format of variables=w.d where w=total width, including decimal places*/
FORMAT x1-x4 3. Species $15.;
SET IrisURL;
WHERE (COMPRESS(Species)) NE 'Versicolor';
SSUM=x1+x2;
SDIFF=x1-x2;
PSUM=x3+x4;
PDIFF=x3-x4;
DROP x1 x2 x3 x4;
RUN;

PROC PRINT DATA=IrisURL2;
TITLE 'Iris Data Trim, Project 2, STAT 5110/6110';
RUN;

 

Kind Regards,

 

Suhas

Tom
Super User Tom
Super User

You dropped these variables.

DROP x1 x2 x3 x4;

And then later you attempted to RENAME them using the RENAME= dataset option on the output dataset.

IrisURL2 (RENAME=(x1=SepalLength x2=SepalWidth x3=PetalLength x4=PetalWidth))

You can't do both.  Which do you want to do?

If you want to drop them then remove the RENAME= option.

If you want to rename them then remove the DROP statement.

SASJedi
SAS Super FREQ

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

 

 

 

 

 

 

 

 

 

Check out my Jedi SAS Tricks for SAS Users

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 7 replies
  • 44415 views
  • 11 likes
  • 8 in conversation