BookmarkSubscribeRSS Feed
csetzkorn
Lapis Lazuli | Level 10

I am getting this error:

 

Column SomeColumn could not be found in the table/view identified with the correlation name TRANS.

 

Using this code

 

proc sql;
CREATE TABLE WORK.Test AS
select
Trans.SomeColumn 
from WORK.Joiner AS J
left outer join work.parameterestimatestrans AS Trans
ON J._NAME_ = Trans._NAME_;
run;

I know that SomeColumn is not in the table aliased Trans. However, a left out join should simply return a null (i.e. . in SAS). So I am a bit confused about the non sql sas behaviour. Any ideas?

11 REPLIES 11
Kurt_Bremser
Super User

The error is exactly what should happen. You explicitly named a column in the select that does not exist, so your select statement is useless.

SQL does not automatically create variables with missing values, as the data step does.

csetzkorn
Lapis Lazuli | Level 10
Would you mind creating the datastep equivalent please?
ballardw
Super User

@csetzkorn wrote:
Would you mind creating the datastep equivalent please?

It might help if you describe what the output should be. From the code posted it only appears that you want a data set with single variable and all values missing.

 

Reeza
Super User

Here, I fixed it for you, with a numeric and character missing. 

 

proc sql;
CREATE TABLE WORK.Test AS
select
" " as SomeColumn,
. as NumSomeColumn
from WORK.Joiner AS J
left outer join work.parameterestimatestrans AS Trans
ON J._NAME_ = Trans._NAME_;
run;
csetzkorn
Lapis Lazuli | Level 10
Thanks getting closer. The challenge I have that work.parameterestimatestrans may contain NumSomeColumn. I only want to set NumSomeColumn to 'null'/. if work.parameterestimatestrans does not exist.
csetzkorn
Lapis Lazuli | Level 10

I found a solution to my problem. Using:

 

data work.parameterestimatestrans;
    set work.parameterestimatestrans;
	NumSomeColumn = coalesce(NumSomeColumn,.);
run;

Will impute the variable should it be missing and the left join picks this up.

Kurt_Bremser
Super User

What do you mean by


@csetzkorn wrote:
 if work.parameterestimatestrans does not exist.

- the dataset does not exist

- or the dataset exists, but there is no matching record in it

- or the column does not exist in the dataset

?

csetzkorn
Lapis Lazuli | Level 10
I meant if NumSomeColumn does not exist in work.parameterestimatestrans
Reeza
Super User

If it doesn't exist the COALESCE doesn't do anything. 

It assigns a missing value. 

 

Kurt_Bremser
Super User

Since the OP has finally stated his/her true intentions, I can say that the data step with coalesce() is the correct solution.

The OP wants to reach a state where the variable will be present, no matter what is in the original dataset.

If the variable is not there, it will be created as missing, if it is there, the values will be preserved.

LinusH
Tourmaline | Level 20
There is no exact equivalent between SQL and the data step. Isn't it easier to fix the existing query?
If you want to create a column with missing values specify it as a constant in the select clause.
Data never sleeps

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 11 replies
  • 11927 views
  • 3 likes
  • 5 in conversation