Hello,
I am joining two tables, testA, testB.code is as below, but how can I maintain the order of column name value, as H C D, instead of C D H after joining? Thank you so much!
data testA;
input name $ number;
datalines;
H 4
C 7
D 9
;
run;
data testB;
input name $ class;
datalines;
H 88
C 99
D 0
;
run;
proc sql;
create table final as
select a.*,b.* from testA a left join testB b on a.name=b.name;
quit;
One way to implement @Reeza's suggestion:
data testA;
input name $ number;
order = _n_;
datalines;
H 4
C 7
D 9
;
run;
data testB;
input name $ class;
datalines;
H 88
C 99
D 0
;
run;
proc sql;
create table final as
select a.*,b.* from testA a left join testB b on a.name=b.name
order by order;
quit;
You can't by default. If you have a variable you can sort by add that your order by statement.
If you don't have a sort var you'll have to create one.
One way to implement @Reeza's suggestion:
data testA;
input name $ number;
order = _n_;
datalines;
H 4
C 7
D 9
;
run;
data testB;
input name $ class;
datalines;
H 88
C 99
D 0
;
run;
proc sql;
create table final as
select a.*,b.* from testA a left join testB b on a.name=b.name
order by order;
quit;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.