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

Different variable length during combining table

Reply
Regular Contributor
Posts: 215

Different variable length during combining table

Hi there,

I tried to merge two table where variable lengths are different in two different table for the same variable. Can anyone help me writing the code to add these two table with set statement plco.

Table1:

Student_ID        Name

101                   John

103                   Allison

105                   Michael

Table2:

Student_ID        Name

107                   Johan

109                   Chowdhury

Thanks,

Super User
Posts: 10,543

Re: Different variable length during combining table

easiest is to override the length before the set.

data want;

     length student_id $ 5 name $ 25; /* what ever lengths you might need*/

     merge table1 table2;

     by student_id;

run;

OR instead of merge:

     set table1 table2;

depending on what you are attempting to do.

Regular Contributor
Posts: 215

Re: Different variable length during combining table

Thanks ballardw,

I need the set statement and it worked when I write 'set Table2 Table1', but some observation doesn't come to it's total length when I write 'set Table1 Table2',. It's because variable 'Chowdhury' is bigger then any other variables. Do you know a solution to make it work for 'set Table1 Table2'. let's say for the following table. Thanks, 

Table1:

Student_ID        Name          Course

101                   John           Math

103                   Allison        English

105                   Michael      Geography

Table2:

Student_ID        Name         Course

107                   Johan          Math

109                   Chowdhury  English

Super User
Posts: 10,543

Re: Different variable length during combining table

Did you try adding the length statement before the SET statement? Did you make the length at least as long as the longest value of the variables concerned?

Super User
Posts: 9,691

Re: Different variable length during combining table

SQL could take care of it .

proc sql;

create table want as

select * from A

union all corr

select * from B ;

quit;

Xia Keshan

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