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

Hi,

 

I remember that there is a quick way to do SQL to accomplish the merge 2 datasets as I did below.

I just cant figure out what is the syntax, basically, I dont need to use the variable x=1;

Thank you,

 

HC

 

 

data a;
input   number;
datalines;
1
3
102
;run;

data b;
input  name1 :$5. ;
datalines;
new1
new2
;run;

data a; set a; x=1; run;
data b; set b; x=1; run;

proc sql;
create table want (drop=x)as select * from a join b
on a.x=b.x;quit;
1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
PROC Star

Change the "ON" expression to any tautology:

 

data a;
input   number;
datalines;
1
3
102
;run;

data b;
input  name1 :$5. ;
datalines;
new1
new2
;run;

proc sql;
  create table want as select * from a join b on 1=1;
quit;

 

In fact  you could say   "ON 0=0"    or   "ON 1>0".

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

View solution in original post

4 REPLIES 4
mkeintz
PROC Star

Change the "ON" expression to any tautology:

 

data a;
input   number;
datalines;
1
3
102
;run;

data b;
input  name1 :$5. ;
datalines;
new1
new2
;run;

proc sql;
  create table want as select * from a join b on 1=1;
quit;

 

In fact  you could say   "ON 0=0"    or   "ON 1>0".

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
hhchenfx
Barite | Level 11

Thank you,

nice trick.

HC

Astounding
PROC Star

Are you just looking for this?  Just create data sets A and B, and don't create X:

 

proc sql;

create table want as select * from a, b;

quit;

hhchenfx
Barite | Level 11

YES, it is what I am looking for.

 

from a, b;

 

Thanks,

HC

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 849 views
  • 1 like
  • 3 in conversation