DATA Step, Macro, Functions and more

Converting Char to Num

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

Converting Char to Num

I have the following code

t1.Count =input(t1.Count, 4.)

 

trying to convert char to number but I am getting following error  any idea

 

ERROR: Expression using equals (=) has components that are of different data types.

 


Accepted Solutions
Solution
‎03-22-2017 01:21 PM
Super User
Posts: 5,082

Re: Converting Char to Num

I think the syntax for this would be:

 

input(t1.Count1, 4.) as Count,

 

 

View solution in original post


All Replies
Super User
Posts: 10,500

Re: Converting Char to Num

It looks like you are doing this with SQL so are you attempting to use the numeric value in a comparison or  create a new variable?

 

Comparison

 

where input(t1.count,4.) = 245

or

where input(t1.count,4.) = b.numericvariable

 

new variable

 

Select input(t1.count,4.) as Count

 

As written you are comparing the current character value to the converted numeric and that is what generates an error.

More information about what you attempting to do may be needed.

Occasional Contributor
Posts: 9

Re: Converting Char to Num

This is what I am trying to do T1.Count1 is a char value and I am trying to convert to Num.

I thought if I assign the new name count can work as show below:

 

CREATE TABLE AUTO.QUERY_FOR_BUS_DAY AS

SELECT t1.'Active_Messages'n,

t1.'Total_Active_Messages'n,

t1.Aging,

Count =input(t1.Count1, 4.),

t1.'Age_Date'n,

t1.'Report_Date'n,

 

Solution
‎03-22-2017 01:21 PM
Super User
Posts: 5,082

Re: Converting Char to Num

I think the syntax for this would be:

 

input(t1.Count1, 4.) as Count,

 

 

Occasional Contributor
Posts: 9

Re: Converting Char to Num

Thank you
Super User
Posts: 10,500

Re: Converting Char to Num


Davar wrote:

This is what I am trying to do T1.Count1 is a char value and I am trying to convert to Num.

I thought if I assign the new name count can work as show below:

 

CREATE TABLE AUTO.QUERY_FOR_BUS_DAY AS

SELECT t1.'Active_Messages'n,

t1.'Total_Active_Messages'n,

t1.Aging,

Count =input(t1.Count1, 4.),

t1.'Age_Date'n,

t1.'Report_Date'n,

 


Using a = like that in a select creates a boolean (true/false 1/0 valued) un-named variable that SAS will assign a name for.

Please see this example:

data have;
  input x;
datalines;
1
2
;
run;

proc sql;
  create table result as
  select x, x=1
  from have;
quit;

When I ran that on my install I get a variable name _TEMA001, YMMV.

 

☑ This topic is SOLVED.

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

Discussion stats
  • 5 replies
  • 127 views
  • 0 likes
  • 3 in conversation