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

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):(Column).
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!

1 ACCEPTED SOLUTION

Accepted Solutions
RahulG
Barite | Level 11

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

2 REPLIES 2
PGStats
Opal | Level 21

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
RahulG
Barite | Level 11

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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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