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

Reply
Occasional Contributor
Posts: 8

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

Hello there,

 

I am trying to run this part of the code for the longest and I have not been able to complete this part of it, I keep getting the same error.

FYI, this code is huge, but this part has me stock in it. I would appreciate it!!!

 

data tempsas.itemoutputraw;

set tempsas.pi2_&b_ioYear - tempsas.pi2_&e_ioYear

tempsas.output_&b_ioYear - tempsas.output_&e_ioYear;

run;

proc sort data=tempsas.itemOutputRaw out=tempsas.itemOutput;

by item_id ioYear basingYear;

run;

 

data tempsas.itemoutput1;

set tempsas.itemoutput;

proval=basicval+comtax;

drop basicval comtax;

proc sort data=tempsas.itemoutput1;

by item_id ioyear basingyear;

data itemoutput2;

set itemoutput1;

where itemACPSA not in ('item91','item92','item99','noArt','total');

run;

 

 

 

ERROR: Variable ioYear has been defined as both character and numeric.

ERROR: Variable basingYear has been defined as both character and numeric.

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set TEMPSAS.ITEMOUTPUTRAW may be incomplete. When this step was stopped there were 0 observations and 9

variables.

WARNING: Data set TEMPSAS.ITEMOUTPUTRAW was not replaced because this step was stopped.

NOTE: DATA statement used (Total process time):

real time 0.00 seconds

cpu time 0.00 seconds

 

 

ERROR: Variable ITEM_ID not found.

ERROR: Variable IOYEAR not found.

ERROR: Variable BASINGYEAR not found.

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set TEMPSAS.ITEMOUTPUT may be incomplete. When this step was stopped there were 0 observations and 0

variables.

WARNING: Data set TEMPSAS.ITEMOUTPUT was not replaced because this step was stopped.

NOTE: PROCEDURE SORT used (Total process time):

real time 0.01 seconds

cpu time 0.01 seconds

 

 

 

NOTE: Variable comtax is uninitialized.

NOTE: Variable basicval is uninitialized.

NOTE: There were 0 observations read from the data set TEMPSAS.ITEMOUTPUT.

NOTE: The data set TEMPSAS.ITEMOUTPUT1 has 0 observations and 1 variables.

NOTE: DATA statement used (Total process time):

real time 0.00 seconds

cpu time 0.00 seconds

 

ERROR: Variable ITEM_ID not found.

ERROR: Variable IOYEAR not found.

ERROR: Variable BASINGYEAR not found.

NOTE: The SAS System stopped processing this step because of errors.

NOTE: PROCEDURE SORT used (Total process time):

real time 0.00 seconds

cpu time 0.00 seconds

 

 

ERROR: File WORK.ITEMOUTPUT1.DATA does not exist.

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set WORK.ITEMOUTPUT2 may be incomplete. When this step was stopped there were 0 observations and 0 variables.

NOTE: DATA statement used (Total process time):

real time 0.01 seconds

cpu time 0.00 seconds

Respected Advisor
Posts: 4,973

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

Let's start with two questions.

 

First, when  you see those first two error messages, is it clear what step in the program they refer to?  (It may not be, if macro language is generating your program.)

 

Second, assuming the first question is answered "yes", what do you think the words in the error message mean?

Occasional Contributor
Posts: 8

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

Excuse me for my ignorance but I am new to SAS and I need the output to do my job, could be more specific so I can answer your question...

Super User
Posts: 1,230

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

No one was born with knowledge. We all learn in order to hvae it.

I have a motto: "Everyting that we don't know is hard. Let's learn and it will be easy";

 

SAS variable type can be either character or numeric. 

Your 1s program step is:

 

data tempsas.itemoutputraw;

  set tempsas.pi2_&b_ioYear - tempsas.pi2_&e_ioYear

        tempsas.output_&b_ioYear - tempsas.output_&e_ioYear;

run;

 

1) How did you assigned the macro variables: b_ioYear , e_ioYear ?
     and what values ? How many years are between b_ioYear and e_ioYear ?

 

Now run next code on each of the inputs and check results :

1) are variables   ioyear   basingyear  exists on each of the inputs ?

2) are variables   ioyear   basingyear types the same of the inputs ? and value is it: NUM or CHAR ?

 

proc contents data=tempsas.pi2_&b_ioYear ; run;

proc contents data=tempsas.pi2_&e_ioYear ; run;

proc contents data=tempsas.output_&b_ioYear ; run;

proc contents data=tempsas.output_&e_ioYear ; run;

 

Probably there is at least one input file where those variables are defined differently from others or do not exist

 

Respected Advisor
Posts: 4,973

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

We all started out where you are now, so don't worry about that part.

 

You showed a program with 3 DATA steps and one PROC SORT.  And you got error messages.  The very first error messages about a variable being defined as both character and numeric ... does the log indicate which step those messages apply to?  (It is possible that the answer is "no" due to the presence of macro language, but you will have to examine the log to find out.)

 

Just for the record, I know the answers as I write these questions.  I'm just trying to lead you through the steps you will need, so you can learn to diagnose and fix such problems on your own.

Super User
Posts: 1,230

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

Your 1st ERROR messages are:

 

ERROR: Variable ioYear has been defined as both character and numeric.

ERROR: Variable basingYear has been defined as both character and numeric.

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set TEMPSAS.ITEMOUTPUTRAW may be incomplete.

 

To create TEMPSAS.ITEMOUTPUTRAW you concatenate several input datasets;

Check ioYear and basingYear on each input for its type and you'll find that in some of them

they are defined numeric and on others as character;

 

In oredr to change type of a avriable you can do:

 

/* 1-change from character to numeric */

data out;

 set inp (rename=( var_name = var_temp);

            varname = input(var_temp, best8.);   /* adapt informat to length of cahr variable */ 

            ...  

           drop var_temp;

run;

 

in similar way you can change from numeric to character, by:  varname = put(var_temp, 8.)  adapting the format.

Grand Advisor
Posts: 10,210

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

Any takers on bets that one or more of the data sets involved derive from Proc Import calls?

 

If your original datasets were created by Proc Import (or import wizards or tasks) then SAS had to guess whether values were character or numeric. Depending on how well structured those source files were the guesses may not have been optimal. So now you have data where the same variables are of two different types in different datasets.

 

 

Valued Guide
Posts: 2,174

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

For managing info from multiple files we need something more robust than proc import
Ask a Question
Discussion stats
  • 7 replies
  • 451 views
  • 0 likes
  • 5 in conversation