BookmarkSubscribeRSS Feed
mlogan
Lapis Lazuli | Level 10

Hi All,

Can I put both and Character and Numeric under the same variable and assign the variable type as Numeric? I wanted to merge these two table with set command and it says Table 1 code is Numeric and Table 2 Code is Character. 

Table 1:

Code
1
2
3
4
5

Table 2:

CodeName
1John
5Clara
BMike
4Dave
ALaura

Can I merge them like this with a set command so that all codes come?


CodeName
1
2
3
4
5
1John
5Clara
BMike
4Dave
ALaura



3 REPLIES 3
M_Maldonado
Barite | Level 11

probably not.

create a dummy variable in table 1 to make it character before merging it to table 2.

good luck!

RW9
Diamond | Level 26 RW9
Diamond | Level 26

As has been mentioned above structurally you can only have a column which is of character or numeric.  You can however do this in one step:

data tab1;

  input code;

datalines;

1

2

3

4

5

;

run;

data tab2;

  input code $ name $;

datalines;

1 John

5 Clara

B Mike

4 Dave

A Laura

;

run;

proc sql;

  create table WANT as

  select  put(CODE,1.) as CODE,

          "" as NAME

  from    TAB1

  union all

  select  *

  from    TAB2;

quit;

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 choose a machine learning algorithm

Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 957 views
  • 0 likes
  • 4 in conversation