I am trying to get a data from the previous table using from statement but getting error. Please suggest experts.
proc sql;
create table Test AS
Select
Account_code
From work.'foreign address'n;
quit;
proc sql;
create table Add_repcode as
select a.*,
b.rep_code,
From Test
inner join p2scflow.debt as b on a.Account_code= b.Account_code;
quit;
Getting this error
30 proc sql;
31 create table Add_repcode as
32 select a.*,
33 b.rep_code,
34 From Test
_________________
79
ERROR 79-322: Expecting a FROM.
35 inner join p2scflow.debt as b on a.account_code = b.account_code ;
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
36 quit;
You have an extra comma.
Make sure that you define the aliases if you are going to use them to reference variables from specific input dataset.
Do not hide continuation characters at the END of the line. Place them at the BEGINNING of the line. It is much easier for humans to scan for them there.
proc sql;
create table Add_repcode as
select a.*
, b.rep_code
from Test as a
inner join p2scflow.debt as b
on a.Account_code= b.Account_code
;
quit;
What @Tom points out is the comma at the end of line 4 (see my comment) is the cause of your error. Delete that comma and problem solved
proc sql;
create table Add_repcode as
select a.*,
b.rep_code, /* This comma at the end of this line is the issue */
From Test
inner join p2scflow.debt as b on a.Account_code= b.Account_code;
quit;
I did tried doing that but it gave me unresolved reference and few more errors.
9 proc sql;
30 create table Add_repcode as
31 select a.*,
32 b.rep_code
33 From Test
34 inner join p2scflow.debt as b on a.account_code = b.account_code ;
ERROR: Unresolved reference to table/correlation name a.
ERROR: Could not expand a.*, correlation name not found.
ERROR: The following columns were not found in the contributing tables: a.
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
35 quit;
NOTE: The SAS System stopped processing this step because of errors.
Because you have additional errors that become prominent once the comma is removed.
ERROR: Unresolved reference to table/correlation name a.
You don't have a table referred to with the alias A. So you can't use
select a.*,
I believe the fix is obvious, so I leave it as a homework assignment for you.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Lock in the best rate now before the price increases on April 1.
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.