DATA Step, Macro, Functions and more

NOTE: Variable X is uninitialize. WARNING: Variable X already exists on file WORK.mydataset.

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 19
Accepted Solution

NOTE: Variable X is uninitialize. WARNING: Variable X already exists on file WORK.mydataset.

[ Edited ]

Hi,

 

I am encountering a very weird case. I am in an emergency so please help.

 

I first imported data from excel:

 

    proc import out=mydataset
    datafile = 'C:\mypath\myfile.xlsx'
    dbms=xlsx replace;
    sheet = 'sheet1';
    datarow=3;getnames=no;
    run;

 

The imported dataset assigns A,B,C,... as variable names. Their format are all characters.

I need to convert the date variable into date format, and other variables into numericals. For example, I used

 

    data mydataset2;
    set mydataset;
    rename A=date B=price C=volume;
    price2=input(price,12.);
    run;

 

When I run this, I got 

 

NOTE: Numeric values have been converted to character values at the places given by:
(Line)Smiley SadColumn).
7675:14
NOTE: Variable price is uninitialized.
WARNING: Variable price already exists on file WORK.SPX2.
NOTE: There were 30000 observations read from the data set WORK.SPX.
NOTE: The data set WORK.SPX2 has 30000 observations and 12 variables.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.01 seconds

 

 

I could not do anything on variable formats. Moreover, I could not understand why a variable is both "uninitialized" and "already exists". This is driving me crazy. What should I do ? Thanks!


Accepted Solutions
Solution
‎09-03-2017 11:11 PM
Super Contributor
Posts: 271

Re: NOTE: Variable X is uninitialize. WARNING: Variable X already exists on file WORK.mydataset.

Rename statement and Rename option works little differently.

Rename statement would apply new name in the output dataset and not while processing.

 

I suggest either use any of the below two option

Option 1: Use data step option

  data mydataset2;
    set mydataset (    rename=( A=date B=price C=volume));
    price2=input(price,12.);
    run;

 

Option 2: 

    data mydataset2;
    set mydataset;
    rename A=date B=price C=volume;
    price2=input(B,12.);
    run;

View solution in original post


All Replies
Esteemed Advisor
Posts: 5,625

Re: NOTE: Variable X is uninitialize. WARNING: Variable X already exists on file WORK.mydataset.

You should do all your character to numeric conversions with input() :

 

data mydataset2;
set mydataset;
price = input(B, best.) ;
volume = input(C, best.) ;
date = input(A, anydtdte.) ;
format date yymmdd10. ;
drop A B C;
run;
PG
Solution
‎09-03-2017 11:11 PM
Super Contributor
Posts: 271

Re: NOTE: Variable X is uninitialize. WARNING: Variable X already exists on file WORK.mydataset.

Rename statement and Rename option works little differently.

Rename statement would apply new name in the output dataset and not while processing.

 

I suggest either use any of the below two option

Option 1: Use data step option

  data mydataset2;
    set mydataset (    rename=( A=date B=price C=volume));
    price2=input(price,12.);
    run;

 

Option 2: 

    data mydataset2;
    set mydataset;
    rename A=date B=price C=volume;
    price2=input(B,12.);
    run;

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 364 views
  • 2 likes
  • 3 in conversation