BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
zhangda
Fluorite | Level 6

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;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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;

View solution in original post

2 REPLIES 2
Reeza
Super User

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. 

ballardw
Super User

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;

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 Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 6159 views
  • 0 likes
  • 3 in conversation