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

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.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

I think the syntax for this would be:

 

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

 

 

View solution in original post

5 REPLIES 5
ballardw
Super User

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.

Davar
Calcite | Level 5

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,

 

Astounding
PROC Star

I think the syntax for this would be:

 

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

 

 

Davar
Calcite | Level 5
Thank you
ballardw
Super User

@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.

 

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
  • 5 replies
  • 1048 views
  • 0 likes
  • 3 in conversation