Help using Base SAS procedures

ERROR: Variable has been defined as both character and numeric

Reply
N/A
Posts: 0

ERROR: Variable has been defined as both character and numeric

Hello, I know that this has to be an easy fix for you savvy SAS users;
I formatted the date from generic SAS datetime to this:

DATA V_DATE; SET CERTS; BDATE=DATEPART(BDATE); RUN;
PROC SORT DATA=V_DATE; BY BDATE; FORMAT BDATE mmddyy10.; RUN; OPTIONS COMPRESS=YES; RUN;

And now when I try to search for specific dates within V_DATE it tells me that BDATE has been defined as both character and numeric, although when I do a proc contents it tells me it is numeric.

DATA MISSING; IF BDATE IN(
'01/22/2006'
'02/14/2006'
'02/21/2006'
'03/05/2006'
'03/17/2006'
'03/18/2006'
'03/19/2006'
'03/24/2006'
'04/24/2006'
'05/08/2006'
'05/30/2006'
'06/12/2006'
'06/13/2006'
'06/17/2006'
'07/26/2006'
'09/28/2006'
'10/06/2006'
'10/23/2006'
'12/11/2006'
'12/18/2006'
'12/31/2006'
'01/04/2007'
'01/17/2007'
'01/26/2007'
'02/14/2007'
'05/16/2007'
'05/30/2007'
'07/18/2007'
'07/19/2007'
'08/15/2007'
'10/04/2007'
'10/05/2007'
'10/24/2007'
'11/08/2007'
'12/26/2007'); SET V_DATE;OPTIONS COMPRESS=YES; RUN;

It tells me this: Variable BDATE has been defined as both character and numeric.

grrrrrrr!!!! HELP Smiley Happy ?
Super Contributor
Super Contributor
Posts: 3,174

Re: ERROR: Variable has been defined as both character and numeric

A few items to correct and some suggestions:

1) Your IF statement must follow the SET statement.
2) The correct method to code a date-literal requires you specify a trailing "D" character after the quoted string -- such as '01jan2009'd.
3) Suggestion: move your FORMAT statement to be in the DATA step where you are transforming the "purpose" of BDATE - from a DATETIME variable to a DATE (numeric) variable, mostly for relevance.
4) Suggestion: remove the redundant OPTIONS COMPRESS=YES; statement -- that CONFIG option had already been set with the first statement.
5) Suggestion (depending on your data-volume) either change the IF statement to a WHERE statement or also consider using a PROC FORMAT to accomplish your look-up / data-filtering processing for optimized performance.
6) Suggestion: explore the use of SAS views (or an index) for further performance optimization, where applicable.

Scott Barry
SBBWorks, Inc.
Ask a Question
Discussion stats
  • 1 reply
  • 603 views
  • 0 likes
  • 2 in conversation