SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
vraj1
Quartz | Level 8

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?

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

like this?

 

data test;
	duration = 100;
	unit = 'years';
	adurn = cats(duration,unit);
run;
vraj1
Quartz | Level 8

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):(Column).
959:9
NOTE: Invalid numeric data, '18Days' , at line 959 column 9.

PeterClemmensen
Tourmaline | Level 20

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

RW9
Diamond | Level 26 RW9
Diamond | Level 26

I agree with @PeterClemmensen.  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);

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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