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

I have two tables and I want to join them together.

 

The columns of table one are 

  • name,
  • age,
  • birthday.

 

The columns of table two are

  • name,
  • salary.

 

How do i merge the data from table 2 into table 1 where the names are the same?

 

proc sql;
CREATE TABLE all_data AS
  SELECT a.*, b.* FROM
  table1 a full join table2 b
  on a.name == b.name
;
quit;

However, I get this error.

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant,
a missing value, BTRIM, INPUT, PUT, SUBSTRING, USER.
How do I do this?
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
Show the full log - where SAS indicates the error is informative.
No double == sign is one difference. I make the reverse mistake constantly in R 🙂

View solution in original post

3 REPLIES 3
Reeza
Super User
Show the full log - where SAS indicates the error is informative.
No double == sign is one difference. I make the reverse mistake constantly in R 🙂
Reeza
Super User
Note that SAS also supports the Natural Join which is useful.
Tom
Super User Tom
Super User

SAS will SHOW YOU where the mistake is.

70    proc sql;
71    CREATE TABLE all_data AS
72      SELECT a.*, b.* FROM
73      table1 a full join table2 b
74      on a.name == b.name
                   -
                   22
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant,
              a missing value, BTRIM, INPUT, PUT, SUBSTRING, USER.

75    ;
76    quit;

You have typed the equality operator symbol twice. Remove one of the equal signs,  a.name=b.name, or just use the  mnemonic equivalent, a.name eq b.name.

https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lrcon/p00iah2thp63bmn1lt20esag14lh.htm

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 851 views
  • 2 likes
  • 3 in conversation