BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
lioradam
Obsidian | Level 7

Hello all,

 I am trying to create a new variable which is a combination of a text variable and a numeric variable.

for example:

The observation of the text variable is "abrt"

The observation of the first numeric variable is "03"

The observation of the second numeric variable is "2014"

 

I want that the observation of the new variable will be "abrt032014".

 

What is the simplest code for that?

Thank you,

Lior

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

@lioradam wrote:

Hello all,

 I am trying to create a new variable which is a combination of a text variable and a numeric variable.

for example:

The observation of the text variable is "abrt"

The observation of the first numeric variable is "03"

The observation of the second numeric variable is "2014"


Do you mean "the value of ..." ???

 

If so, here is data step code to use:

 

length newvariable $ 20;
newvariable = cats(textvariable,firstnumericvariable,secondnumericvariable);

 

probably also best to give the new variable a length, I gave it 20 characters, but you may need more or fewer, depending on your data.

--
Paige Miller

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

@lioradam wrote:

Hello all,

 I am trying to create a new variable which is a combination of a text variable and a numeric variable.

for example:

The observation of the text variable is "abrt"

The observation of the first numeric variable is "03"

The observation of the second numeric variable is "2014"


Do you mean "the value of ..." ???

 

If so, here is data step code to use:

 

length newvariable $ 20;
newvariable = cats(textvariable,firstnumericvariable,secondnumericvariable);

 

probably also best to give the new variable a length, I gave it 20 characters, but you may need more or fewer, depending on your data.

--
Paige Miller
lioradam
Obsidian | Level 7

Thank you very much.

This is the code I needed.

 

Regards,

Lior

PaigeMiller
Diamond | Level 26

@lioradam you should not mark your own "Thank you" message as the correct answer. You should mark the correct answer as the correct answer.

--
Paige Miller
lioradam
Obsidian | Level 7

Sorry, I didn't notice that I marked the wrong message. 

Now it is corrected.

Thanks again,

Lior

FreelanceReinh
Jade | Level 19

Hello @lioradam,

Glad to see that Paige Miller's solution worked for you. Then it would be fair and help later readers if you marked his helpful reply as the accepted solution, not your own "thank you" post. Could you please change that? It's very easy: Select his post as the solution after clicking "Not the Solution" in the option menu (see icon below) of the current solution.
show_option_menu.png

lioradam
Obsidian | Level 7

Thank you for the explanation of how to correct it.

 

Regards,

Lior

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 837 views
  • 1 like
  • 3 in conversation