I have 5 table to merge all sorted by the common field SUBJECT and part of the view column looks like below
|
| Type | Length | format | Informat |
T_1 | SUBJECT | Text | 8 | $8 | $8 |
T_2 | SUBJECT | Text | 8 | $8 | $8 |
T_3 | SUBJECT | Text | 8 | $8 | $8 |
T_4 | SUBJECT | Number | 8 | BEST. |
|
T_5 | SUBJECT | Text | 8 | $8 | $8 |
Then I have
proc sort data = T_1; by SUBJECT; run;
proc sort data = T_2; by SUBJECT; run;
proc sort data = T_3; by SUBJECT; run;
proc sort data = T_4; by SUBJECT; run;
proc sort data = T_5; by SUBJECT; run;
data all; merge T_1 (in=a) T_2 T_3 T_4 T_5; by SUBJECT; if a; run;
the merge was failed due to one of the SUBJECT is number, any suggestion on how to fix this? I tried to convert the numeric SUBJECT to character and renaming, in the end the merge is not working
Thank you!
zimcom
Is this what you did?
proc sort data = T_1; by SUBJECT; run;
proc sort data = T_2; by SUBJECT; run;
proc sort data = T_3; by SUBJECT; run;
/*covert to char*/
data T_4(rename=(k=subject));
set T_4;
k=put(SUBJECT,8. -l);/*assuming the values are numbers */
drop subject;
run;
proc sort data = T_4; by SUBJECT; run;
proc sort data = T_5; by SUBJECT; run;
data all; merge T_1 (in=a) T_2 T_3 T_4 T_5; by SUBJECT; if a; run;
Is this what you did?
proc sort data = T_1; by SUBJECT; run;
proc sort data = T_2; by SUBJECT; run;
proc sort data = T_3; by SUBJECT; run;
/*covert to char*/
data T_4(rename=(k=subject));
set T_4;
k=put(SUBJECT,8. -l);/*assuming the values are numbers */
drop subject;
run;
proc sort data = T_4; by SUBJECT; run;
proc sort data = T_5; by SUBJECT; run;
data all; merge T_1 (in=a) T_2 T_3 T_4 T_5; by SUBJECT; if a; run;
novinosrin,
the codes works
you saved my life today!
don't know how I should thank you for all the helps you gave to me!
zimcom
No biggie. I am glad. I am about to catch the train and go home and enjoy world cup football finals tomorrow croatia vs france. Keep your questions coming. It's fun to ask, find and share. Cheers
Thank you, you deserve a good relax Sunday and enjoy the game tomorrom
@zimcom wrote:
tried to convert the numeric SUBJECT to character and renaming, in the end the merge is not working
Thank you!
zimcom
This is the correct approach so you likely did something incorrect in that step. If you post that code, we can help point out where the issues is.
@zimcom You could close the thread my marking some relevant answer as accepted solution rather than leaving completely open for too long
Hi Andygrey,
Thank you for letting me know.
As I am still kind of new to this forum (yesterday actually is my very first day here), I will make sure to close my thread as soon as I have an answer. This forum is really helpfull.
Have a good day!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.