BookmarkSubscribeRSS Feed
jakeroth424
Calcite | Level 5

I'm trying to create a column (postal_cd) and then join another table from that column, but I received this error:

ERROR: Column postal_cd could not be found in the table/view identified with the correlation name A.

 

proc sql;
create table TEST as
(select b.state_nm as state_c
,a.*
,a.full_zip as ZIP9
,substr(full_zip,1,5) as postal_cd
from sid.plus4_zip_summary_us a
inner join temp b
on b.zip_char_cd=a.postal_cd
);
quit;

2 REPLIES 2
mklangley
Lapis Lazuli | Level 10

The table with the alias is sid.plus4_zip_summary_us. That table does not have postal_cd, so a reference to a.postal_cd will give that error. However, that table does have full_zip, from which you are getting postal_cd. So you can just reference the substring of full_zip in your join:

proc sql;
create table TEST as
(select b.state_nm as state_c
,a.*
,a.full_zip as ZIP9
,substr(full_zip,1,5) as postal_cd
from sid.plus4_zip_summary_us a
inner join temp b
on b.zip_char_cd=substr(a.full_zip,1,5)
);
quit;
ballardw
Super User

That' pretty clear.

The data set sid.plus4_zip_summary_us  does not contain a variable name postal_cd

If you intend to create the code then you need to watch where you are placing ( ).

 

Maybe:

proc sql;
   create table TEST as
   select b.state_nm as state_c
   ,a.*
   ,a.full_zip as ZIP9
   ,
   from (select *, substr(full_zip,1,5) as postal_cd
         from sid.plus4_zip_summary_us) a
   inner join temp b
   on b.zip_char_cd=a.postal_cd
   ;
quit;

You were attempting to create the variable Postal_ct after the inner join. The  above creates it in a subquery so is in the alias A data.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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
  • 2 replies
  • 2714 views
  • 0 likes
  • 3 in conversation