Building models with SAS Enterprise Miner, SAS Factory Miner, SAS Visual Data Mining and Machine Learning or just with programming

Variable in both Numeric and Character

Reply
Regular Contributor
Posts: 215

Variable in both Numeric and Character

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



Super Contributor
Posts: 336

Re: Variable in both Numeric and Character

probably not.

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

good luck!

Super User
Posts: 6,932

Re: Variable in both Numeric and Character

No. A variable defined as numeric can only hold numerical values.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Super User
Posts: 7,400

Re: Variable in both Numeric and Character

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;

Ask a Question
Discussion stats
  • 3 replies
  • 294 views
  • 0 likes
  • 4 in conversation