BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
HitmonTran
Pyrite | Level 9

I want to do a left join on 2 variables.

 

this is my code but there's an error because of the "on" statement "on a.subject, a.date = b.subject, b.date;"

proc sql;
  create table data3 as  select * 
  from data1 as a left join data2 as b 
  on a.subject, a.date = b.subject, b.date;
quit;
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
proc sql;
  create table data3 as  
select * from data1 as a
left join data2 as b on a.subject = b.subject and a.date=b.date; quit;

Separate your conditions with an AND 

View solution in original post

3 REPLIES 3
Reeza
Super User
proc sql;
  create table data3 as  
select * from data1 as a
left join data2 as b on a.subject = b.subject and a.date=b.date; quit;

Separate your conditions with an AND 

PaigeMiller
Diamond | Level 26
proc sql;
  create table data3 as  select * 
  from data1 as a left join data2 as b 
  on a.subject = b.subject and a.date = b.date;
quit;
--
Paige Miller
ballardw
Super User

Hint: when you get errors then include the code with the errors, the entire procedure, data step or macro, with all the messages.

In your case the error would have looked like this:

765  proc sql;
766    create table data3 as  select *
767    from sashelp.class as a left join sashelp.class as b
768    on a.sex, a.age = b.sex, b.age;
                       -
                       22
                       76
ERROR 22-322: Syntax error, expecting one of the following: a name, ;, (, ',', ANSIMISS, AS,
              CROSS, EXCEPT, FULL, GROUP, HAVING, INNER, INTERSECT, JOIN, LEFT, NATURAL, NOMISS,
              ORDER, OUTER, RIGHT, UNION, WHERE.

ERROR 76-322: Syntax error, statement will be ignored.

The presence of all the join options tells us that the error is that where the = in your code appears than SAS is expecting something related to another join. The comma was interpreted as a Cartesian join instruction similar to

proc sql;
   select a.*,b.*
   from someset as a, otherset as b
  ;
quit;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1862 views
  • 0 likes
  • 4 in conversation