Help using Base SAS procedures

input function doesn't work

Reply
N/A
Posts: 0

input function doesn't work

I have trying to convert id from text $37 to number 11. ,
I'm not sure why input function doesn't work in my case , any idea ?
Here's the code

----------------------------------
data table1;
set table0;
id= input(id,11.);
run;
---------------------------------------------------------------------------------------------------------------

Numeric values have been converted to character values at the places given by: (Line)Smiley SadColumn).
----------------------------------------------------------------------------------------------------------------
however I know that the " id" was character not numeric in table0

----------------------------------------------------------------------------------------------------------------
I also tried this code below , but it also doesn' t work.

data table1
set table0 ;
id= id*1;
run;
New Contributor
Posts: 3

Re: input function doesn't work

Posted in reply to deleted_user
Hi There,

The reason why it doesn't work is because the variable id (from the table0 dataset) is character and at compile time the PDV is set up with id being character. The first instance the compiler comes across the id variable is with the set statement.

So when you attempt to do the assignment statement the right hand side is a numeric value but the left hand side, the id variable, is defined as character - that is why you get the "NOTE: Numeric values have been converted to character values at the places given by: (Line)Smiley SadColumn)."

What you need to do is create a new variable that is numeric and drop your character id variable from your data set. Below is some code that I hope helps.

data table1(drop=charId);
set table0(rename=(id=charId));
id=input(charId,11.);
run;

Cheers,
Michelle
N/A
Posts: 0

Re: input function doesn't work

Hi there,

Thank you for your fast reply , but I still get this error below
-------------------------------------------------------------------------------------------------------------
data table1(drop=charId);
set table0(rename=(id=charId));
ERROR: Variable id is not on file WORK.table1.
ERROR: Invalid DROP, KEEP, or RENAME option on file WORK.table1.
id=input(charId,11.);
run;



NOTE: Numeric values have been converted to character values at the places given by: (Line)Smiley SadColumn).

WARNING: The data set WORK.table1 may be incomplete. When this step was stopped there were 0 observations and 1 variables.
WARNING: Data set WORK.table1 was not replaced because this step was stopped.

Message was edited by: iamjeannie Message was edited by: iamjeannie
Super Contributor
Super Contributor
Posts: 3,174

Re: input function doesn't work

Posted in reply to deleted_user
Something about your SAS log does not make sense - suggest you reply to your post and paste the "entire SAS log".

Scott Barry
SBBWorks, Inc.
SAS Super FREQ
Posts: 8,864

Re: input function doesn't work

Posted in reply to deleted_user
Hi:
I agree with Scott. Something strange is happening. As you can see from my log, below, when I create TABLE0 with a character ID variable and then create TABLE1 using the rename/INPUT technique, I do not get the same error messages, so somehow, something is "off".
[pre]
92 data table0;
93 id = '12345678901';
94 numvar = 1234;
95 run;

NOTE: The data set WORK.TABLE0 has 1 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds


96
97
98
99 data table1(drop=charId);
100 set table0(rename=(id=charId));
101 id=input(charId,11.);
102 put _all_;
103 run;

charId=12345678901 numvar=1234 id=12345678901 _ERROR_=0 _N_=1
NOTE: There were 1 observations read from the data set WORK.TABLE0.
NOTE: The data set WORK.TABLE1 has 1 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.04 seconds
cpu time 0.01 seconds
[/pre]

In additions to Scott's suggestion, I'd recommend going back a bit farther to where TABLE0 is created and do a PROC CONTENTS on TABLE0 to make sure that all the variables in the dataset are in the form that you expect them to be.

cynthia
Ask a Question
Discussion stats
  • 4 replies
  • 864 views
  • 0 likes
  • 4 in conversation