DATA Step, Macro, Functions and more

can we concatenate a numeric and character and make it to character in cats or catx?

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 115
Accepted Solution

can we concatenate a numeric and character and make it to character in cats or catx?

i have a variable duration(numeric) and unit(character).

 

i need to concatenate both and make them into character.

 

ADURN=cats(adurn,aduru);

 

but this fails as NOTE: Invalid numeric data.

 

is there any way to do in cat functions?


Accepted Solutions
Solution
‎05-19-2017 05:04 AM
PROC Star
Posts: 551

Re: can we concatenate a numeric and character and make it to character in cats or catx?

This happens because you are trying to change the variable ADURN's type from numeric to character.

 

You can not (and shouldn't try to) change the type of a variable once it has been defined.

 

Therefore, call ADURN something else at the left side of the equal sign

View solution in original post


All Replies
PROC Star
Posts: 551

Re: can we concatenate a numeric and character and make it to character in cats or catx?

like this?

 

data test;
	duration = 100;
	unit = 'years';
	adurn = cats(duration,unit);
run;
Frequent Contributor
Posts: 115

Re: can we concatenate a numeric and character and make it to character in cats or catx?

i used a same step but somehow i get the error

data inc;
set adae;
ADURN=cats(adurn,aduru);
run;

 

ADURN is numeric and lenght as 8 and format as best12.

ADURU is char and length 40 

 

NOTE: Character values have been converted to numeric values at the places given by: (Line)Smiley SadColumn).
959:9
NOTE: Invalid numeric data, '18Days' , at line 959 column 9.

Solution
‎05-19-2017 05:04 AM
PROC Star
Posts: 551

Re: can we concatenate a numeric and character and make it to character in cats or catx?

This happens because you are trying to change the variable ADURN's type from numeric to character.

 

You can not (and shouldn't try to) change the type of a variable once it has been defined.

 

Therefore, call ADURN something else at the left side of the equal sign

Super User
Super User
Posts: 7,401

Re: can we concatenate a numeric and character and make it to character in cats or catx?

I agree with @draycut.  One thing I would add is that it is generally advisable to put() numerics to text and cat the result, as then it is both in your hands what to do with the number, and clear to other users what is happening:

cats(put(number_var,3.),text_var);
☑ This topic is SOLVED.

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

Discussion stats
  • 4 replies
  • 181 views
  • 1 like
  • 3 in conversation