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;

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
  • 2 replies
  • 2680 views
  • 2 likes
  • 3 in conversation